kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Carsten Stollmaier <stollmc@amazon.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,
	 Matthew Wilcox <willy@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [PATCH] KVM: x86: Use gfn_to_pfn_cache for steal_time
Date: Tue, 29 Jul 2025 11:28:18 +0100	[thread overview]
Message-ID: <1b955b6b9b49a7f03fae12d9b13b027822749527.camel@infradead.org> (raw)
In-Reply-To: <b69ed9d08eb86a346a1d092575abe99512fa875a.camel@infradead.org>

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

On Tue, 2024-08-20 at 11:11 +0100, David Woodhouse wrote:
> On Fri, 2024-08-16 at 17:22 -0700, Sean Christopherson wrote:
> > On Fri, Aug 02, 2024, David Woodhouse wrote:
> > > On Fri, 2024-08-02 at 11:44 +0000, Carsten Stollmaier wrote:
> > > > On vcpu_run, before entering the guest, the update of the steal time
> > > > information causes a page-fault if the page is not present. In our
> > > > scenario, this gets handled by do_user_addr_fault and successively
> > > > handle_userfault since we have the region registered to that.
> > > > 
> > > > 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.
> > > 
> > > The busy-loop causes so much contention on mmap_lock that post-copy
> > > live migration fails to make progress, and is leading to failures. Yes?
> > > 
> > > > This patch replaces the use of gfn_to_hva_cache with gfn_to_pfn_cache,
> > > > as gfn_to_pfn_cache ensures page presence for the memory access,
> > > > preventing the contention of the mmap_lock.
> > > > 
> > > > Signed-off-by: Carsten Stollmaier <stollmc@amazon.com>
> > > 
> > > Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
> > > 
> > > I think this makes sense on its own, as it addresses the specific case
> > > where KVM is *likely* to be touching a userfaulted (guest) page. And it
> > > allows us to ditch yet another explicit asm exception handler.
> > 
> > At the cost of using a gpc, which has its own complexities.
> > 
> > But I don't understand why steal_time is special.  If the issue is essentially
> > with handle_userfault(), can't this happen on any KVM uaccess?
> 
> Theoretically, yes. The steal time is only special in that it happens
> so *often*, every time the vCPU is scheduled in.
> 
> We should *also* address the general case, perhaps making by
> interruptible user access functions as discussed. But this solves the
> immediate issue which is being observed, *and* lets us ditch the last
> explicit asm exception handling in kvm/x86.c which is why I think it's
> worth doing anyway, even if there's an upcoming fix for the general
> case.

Gentle reader, there was *not* an upcoming fix for the general case,
and this is still an issue in real-world use cases... or would be, if
we hadn't been using Carsten's patch ever since he came up with it.

I still quite like the idea of interruptible user access, but nobody
seemed that excited by it, and as noted I think we should move steal
time to a GPC *anyway*.


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

      reply	other threads:[~2025-07-29 10:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-02 11:44 [PATCH] KVM: x86: Use gfn_to_pfn_cache for steal_time Carsten Stollmaier
2024-08-02 12:03 ` David Woodhouse
2024-08-02 12:38   ` Matthew Wilcox
2024-08-02 12:53     ` David Woodhouse
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 [this message]

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=1b955b6b9b49a7f03fae12d9b13b027822749527.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --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).