From: David Woodhouse <dwmw2@infradead.org>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, rcu@vger.kernel.org,
linux-rt-devel@lists.linux.dev,
Paolo Bonzini <pbonzini@redhat.com>, Paul Durrant <paul@xen.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Fred Griffoul <fgriffo@amazon.co.uk>,
"Paul E . McKenney" <paulmck@kernel.org>,
Kunwu Chan <kunwu.chan@linux.dev>,
Kunwu Chan <kunwu.chan@gmail.com>,
syzbot+208f7f3e5f59c11aeb90@syzkaller.appspotmail.com
Subject: Re: [PATCH v2 06/20] KVM: x86: Request the guest TLB flush from record_steal_time()
Date: Tue, 10 Nov 2026 13:14:26 -0800 [thread overview]
Message-ID: <ccaa2d3b80a798e1513956fa436742c1e0fb50fe.camel@infradead.org> (raw)
In-Reply-To: <avN8aJIHiX4xyTNO@seanjc-mac.roam.internal>
[-- Attachment #1: Type: text/plain, Size: 3714 bytes --]
On Tue, 2026-11-10 at 12:19 -0800, Sean Christopherson wrote:
> On Thu, Nov 05, 2026, David Woodhouse wrote:
> > From: David Woodhouse <dwmw@amazon.co.uk>
> >
> > record_steal_time() performs a TLB flush on the guest's behalf when
> > the
> > guest sets KVM_VCPU_FLUSH_TLB. With shadow paging,
> > kvm_vcpu_flush_tlb_guest() ends up in mmu_sync_children(), which
> > can
> > reschedule via cond_resched_rwlock_write(). That is why the flush
> > currently sits between a user_access_end() and a fresh
> > user_access_begin(): it cannot be done while the guest page is
> > mapped
> > for access.
> >
> > Raise KVM_REQ_TLB_FLUSH_GUEST instead of flushing inline, and move
> > the
> > processing of KVM_REQ_STEAL_UPDATE ahead of where the TLB flush
> > requests
> > are serviced in vcpu_enter_guest() so that the flush still happens
> > before
> > the vCPU enters the guest. There is no requirement for it to
> > complete any
> > earlier than that.
> >
> > kvm_make_request() on the vCPU which is running is nothing more
> > than a
> > barrier and a set_bit(), so unlike the flush itself it can be done
> > from
> > any context — which lets the surrounding access be simplified
> > later.
> >
> > Note that the xchg() must stay where it is: it atomically consumes
> > any
> > KVM_VCPU_FLUSH_TLB which the guest has set, as required by commit
> > b043138246a4 ("x86/KVM: Make sure KVM_VCPU_FLUSH_TLB flag is not
> > missed").
> >
> > Reported-by: Sashiko AI review <sashiko-bot@kernel.org>
> > Closes:
> > https://lore.kernel.org/all/20260530061932.7849D1F00893@smtp.kernel.org
> > Suggested-by: Sean Christopherson <seanjc@google.com>
> > Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> > ---
> > arch/x86/kvm/x86.c | 26 +++++++++++++++++++++++---
> > 1 file changed, 23 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 6a1f0404f029..3c26c0eb9865 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -2117,8 +2117,22 @@ static void record_steal_time(struct
> > kvm_vcpu *vcpu)
> >
> > trace_kvm_pv_tlb_flush(vcpu->vcpu_id,
> > st_preempted &
> > KVM_VCPU_FLUSH_TLB);
> > + /*
> > + * Request the flush instead of performing it
> > inline. With
> > + * shadow paging kvm_vcpu_flush_tlb_guest() can
> > reschedule
> > + * (via mmu_sync_children()), so it could not be
> > called while
> > + * the user access above was open. Requesting is
> > just a bit
> > + * set on the running vCPU, and the request is
> > serviced
> > + * before the vCPU enters the guest; nothing
> > requires the
> > + * flush to have completed any earlier than that.
>
> Argh, I completely forgot about this. It throws a big wrench in my plans to fix
> a mishandled TLB flush without using a deferred mechanism[1]. I really don't like
> having to re-introduce deferred flags, but the diff is a lot smaller[2]. On the
> other hand, I still don't like the idea of delaying the MMU sync until the nested
> VM-Exit.
>
> I think I'll see how gross it is to do something like add a
> KVM_REQ_PV_TLB_FLUSH.
>
> [1] https://lore.kernel.org/all/au0R41xbEJ_9W_9z@google.com
> [2] https://lore.kernel.org/all/auDkX94UTjrLNmqp@google.com
It's still OK just to do the TLB flush synchronously from the end of
record_steal_time() after clearing KVM_VCPU_FLUSH_TLB and dropping the
GPC lock.
You suggested using KVM_REQ_TLB_FLUSH_GUEST in
https://lore.kernel.org/all/aidiOemcna1Un9wG@google.com/ but if it now
makes you sad, I'm happy to go back to the original approach (noting
that it loses the coalescing of multiple flushes).
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
next prev parent reply other threads:[~2026-11-10 21:14 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 2:00 [PATCH v2 00/20] KVM: Use atomic SRCU for gfn-to-pfn cache, reinstate guest mode for x86 nesting David Woodhouse
2026-11-05 2:00 ` [PATCH v2 01/20] KVM: x86/xen: Fill the hypercall page with a single guest write David Woodhouse
2026-11-05 2:00 ` [PATCH v2 02/20] KVM: x86/xen: Add KVM_XEN_VCPU_ATTR_TYPE_WRITE_HYPERCALL_PAGE David Woodhouse
2026-11-05 2:00 ` [PATCH v2 03/20] KVM: x86/xen: Extract delivery of event to vCPU into a separate helper David Woodhouse
2026-11-05 2:00 ` [PATCH v2 04/20] KVM: x86/xen: Explicitly tag "shared info" page as never being dirty tracked David Woodhouse
2026-11-05 2:00 ` [PATCH v2 05/20] KVM: x86/xen: Don't dirty track "vCPU info" page David Woodhouse
2026-11-05 2:00 ` [PATCH v2 06/20] KVM: x86: Request the guest TLB flush from record_steal_time() David Woodhouse
2026-11-10 20:19 ` Sean Christopherson
2026-11-10 21:14 ` David Woodhouse [this message]
2026-11-05 2:00 ` [PATCH v2 07/20] KVM: selftests: Actually deactivate the HVA-based shared_info cache in xen_shinfo_test David Woodhouse
2026-11-05 2:00 ` [PATCH v2 08/20] KVM: pfncache: Use atomic SRCU for readers instead of a rwlock David Woodhouse
2026-11-05 2:00 ` [PATCH v2 09/20] KVM: x86: Use gfn_to_pfn_cache for steal time / preempted status David Woodhouse
2026-11-05 2:00 ` [PATCH v2 10/20] KVM: pfncache: Add guest-mode pinning (GUEST_USES_PFN successor) David Woodhouse
2026-11-05 2:29 ` sashiko-bot
2026-11-05 2:00 ` [PATCH v2 11/20] KVM: nVMX: Implement cache for L1 MSR bitmap David Woodhouse
2026-11-05 2:00 ` [PATCH v2 12/20] KVM: nVMX: Use pinned pfncache for L1 APIC virtualization pages David Woodhouse
2026-11-05 2:33 ` sashiko-bot
2026-11-05 2:00 ` [PATCH v2 13/20] KVM: x86: Post KVM_REQ_GET_NESTED_STATE_PAGES on memslot updates David Woodhouse
2026-11-05 2:00 ` [PATCH v2 14/20] KVM: selftests: Add nested VMX APIC cache invalidation test David Woodhouse
2026-11-05 2:25 ` sashiko-bot
2026-11-05 2:00 ` [PATCH v2 15/20] KVM: nSVM: Use a gfn_to_pfn_cache for the vmcb12 page David Woodhouse
2026-11-05 2:00 ` [PATCH v2 16/20] KVM: nSVM: Cache L1's MSR permissions map pages David Woodhouse
2026-11-05 2:00 ` [PATCH v2 17/20] KVM: nSVM: Cache L1's IO " David Woodhouse
2026-11-05 2:01 ` [PATCH v2 18/20] KVM: selftests: Add nested transition benchmark David Woodhouse
2026-11-05 2:01 ` [PATCH v2 19/20] KVM: selftests: Add Xen evtchn vs memslot-update race test David Woodhouse
2026-11-05 2:01 ` [PATCH v2 20/20] KVM: selftests: Add Xen evtchn vs mmu_notifier race test for HVA caches David Woodhouse
2026-11-05 2:28 ` sashiko-bot
2026-11-10 19:52 ` [PATCH v2 00/20] KVM: Use atomic SRCU for gfn-to-pfn cache, reinstate guest mode for x86 nesting David Woodhouse
2026-11-10 20:14 ` Sean Christopherson
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=ccaa2d3b80a798e1513956fa436742c1e0fb50fe.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=fgriffo@amazon.co.uk \
--cc=kunwu.chan@gmail.com \
--cc=kunwu.chan@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=paul@xen.org \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=rcu@vger.kernel.org \
--cc=seanjc@google.com \
--cc=syzbot+208f7f3e5f59c11aeb90@syzkaller.appspotmail.com \
--cc=vkuznets@redhat.com \
/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
all inboxes | Powered by JetHome®