linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Carsten Stollmaier <stollmc@amazon.com>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	nh-open-source@amazon.com, Peter Xu <peterx@redhat.com>,
	 Sebastian Biemueller <sbiemue@amazon.de>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH] KVM: x86: Use gfn_to_pfn_cache for steal_time
Date: Fri, 02 Aug 2024 13:53:17 +0100	[thread overview]
Message-ID: <ae8606f26bd559263e232d5f0b9e3fe7ac7ccd33.camel@infradead.org> (raw)
In-Reply-To: <ZqzTOvyKRI0qzwCT@casper.infradead.org>

[-- Attachment #1: Type: text/plain, Size: 2311 bytes --]

On Fri, 2024-08-02 at 13:38 +0100, Matthew Wilcox wrote:
> On Fri, Aug 02, 2024 at 01:03:16PM +0100, David Woodhouse wrote:
> > On Fri, 2024-08-02 at 11:44 +0000, Carsten Stollmaier wrote:
> > > handle_userfault uses TASK_INTERRUPTIBLE, so it is interruptible by
> > > signals. do_user_addr_fault then busy-retries it if the pending signal
> > > is non-fatal. This leads to contention of the mmap_lock.
> 
> Why does handle_userfault use TASK_INTERRUPTIBLE?  We really don't
> want to stop handling a page fault just because somebody resized a
> window or a timer went off.  TASK_KILLABLE, sure.

Well, the literal answer there in this case is "because we ask it to".

The handle_userfault() function will literally do what it's told by the
fault flags: 

static inline unsigned int userfaultfd_get_blocking_state(unsigned int flags)
{
	if (flags & FAULT_FLAG_INTERRUPTIBLE)
		return TASK_INTERRUPTIBLE;

	if (flags & FAULT_FLAG_KILLABLE)
		return TASK_KILLABLE;

	return TASK_UNINTERRUPTIBLE;
}


Hence the other potential workaround I mentioned, for
do_user_addr_fault() *not* to ask it to, for faults from the kernel:

> > 
> > --- a/arch/x86/mm/fault.c
> > +++ b/arch/x86/mm/fault.c
> > @@ -1304,6 +1304,8 @@ void do_user_addr_fault(struct pt_regs *regs,
> >          */
> >         if (user_mode(regs))
> >                 flags |= FAULT_FLAG_USER;
> > +       else
> > +               flags &= ~FAULT_FLAG_INTERRUPTIBLE;
> >  
> >  #ifdef CONFIG_X86_64
> >         /*
> > 


But I don't know that I agree with your statement above, that we "don't
want to stop handling a page fault just because somebody resized a
window or a timer went off". 

In fact, I don't think we *do* even stop handling the page fault in
those cases; we just stop *waiting* for it to be handled. 

In fact, couldn't you contrive a test case where a thread is handling
its own uffd faults via SIGIO, where it's the opposite of what you say.
In that case the *only* way the fault actually gets handled is if we
let the signal happen instead of just waiting? 

That doesn't seem like *such* a contrived case either — that seems
perfectly reasonable for a vCPU thread, to then handle its own missing
pages?


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]

  reply	other threads:[~2024-08-02 12:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240802114402.96669-1-stollmc@amazon.com>
2024-08-02 12:03 ` [PATCH] KVM: x86: Use gfn_to_pfn_cache for steal_time David Woodhouse
2024-08-02 12:38   ` Matthew Wilcox
2024-08-02 12:53     ` David Woodhouse [this message]
2024-08-02 12:56       ` David Woodhouse
2024-08-02 16:06   ` David Woodhouse
2024-08-02 22:40   ` Peter Xu
2024-08-03  8:35     ` David Woodhouse
2024-08-04 13:31       ` Peter Xu
2024-08-17  0:22   ` Sean Christopherson
2024-08-20 10:11     ` David Woodhouse
2025-07-29 10:28       ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae8606f26bd559263e232d5f0b9e3fe7ac7ccd33.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=nh-open-source@amazon.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=sbiemue@amazon.de \
    --cc=seanjc@google.com \
    --cc=stollmc@amazon.com \
    --cc=tglx@linutronix.de \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).