From: Sean Christopherson <seanjc@google.com>
To: sashiko-reviews@lists.linux.dev
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 4/4] KVM: x86/mmu: Add sanity check to detect stale page faults in "map private PFN"
Date: Thu, 6 Aug 2026 15:12:40 -0700 [thread overview]
Message-ID: <anUG2D2jrXatibSy@google.com> (raw)
In-Reply-To: <20260806215413.537841F000E9@smtp.kernel.org>
On Thu, Aug 06, 2026, sashiko-bot@kernel.org wrote:
> > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> > index 379f570ef04f8..76e3cd717324b 100644
> > --- a/arch/x86/kvm/mmu/mmu.c
> > +++ b/arch/x86/kvm/mmu/mmu.c
> > @@ -5210,6 +5210,16 @@ int kvm_tdp_mmu_map_private_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn)
> > */
> > WARN_ON_ONCE(kvm_test_request(KVM_REQ_MMU_FREE_OBSOLETE_ROOTS, vcpu));
> >
> > + /*
> > + * Snapshot the invalidation sequence counter after acquiring
> > + * mmu_lock, as guest_memfd guarantees the validity of the pfn,
> > + * i.e. any concurrent invalidations are guaranteed to be
> > + * irrelevant.
> > + */
> > + fault.mmu_seq = vcpu->kvm->mmu_invalidate_seq;
>
> [Severity: High]
> Does capturing the invalidation sequence after acquiring mmu_lock violate
> the KVM MMU invalidation retry protocol order?
Yes, see the comment and changelog.
> The sequence is explicitly captured inside the mmu_lock critical section
> after the PFN has already been resolved by the caller. This bypasses the
> mandatory generation safety sequence (capture sequence, resolve PFN, acquire
> lock).
>
> Additionally, could this still cause false positives since
> mmu_invalidate_retry_gfn() checks mmu_invalidate_in_progress?
Yes, it's possible, but it would require zappings GFNs on either side of the GFN
being mapped, such that the target GFN is contained by mmu_invalidate_range_{start,end}.
The odds of that happening in practice are low enough that I'm comfortable eating
false positives even though strictly speaking they _should_ be irrelevant.
> > + if (is_page_fault_stale(vcpu, &fault))
> > + continue;
>
> [Severity: High]
> Does this continue statement inadvertently exit the loop without retrying?
>
> In C, a continue statement within a do-while loop jumps to the while
> condition evaluation, not the beginning of the loop block. If r is not
> RET_PF_RETRY when this continue is hit, the condition r == RET_PF_RETRY
> will evaluate to false.
>
> Will this cause the function to exit the loop prematurely and return -EIO?
Doh. And this is why I'm more than happy to deal with Sashiko's paranoia :-)
prev parent reply other threads:[~2026-08-06 22:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 21:40 [PATCH 0/4] KVM: x86/mmu: Fix pre-fault and map private loops Sean Christopherson
2026-08-06 21:40 ` [PATCH 1/4] KVM: x86/mmu: Reload MMU on *every* page pre-fault attempt/iteration Sean Christopherson
2026-08-07 8:58 ` Huang, Kai
2026-08-07 19:04 ` Edgecombe, Rick P
2026-08-07 19:11 ` Sean Christopherson
2026-08-06 21:40 ` [PATCH 2/4] KVM: x86/mmu: Harden "map private PFN" against unexpected root invalidation Sean Christopherson
2026-08-06 22:14 ` sashiko-bot
2026-08-06 22:21 ` Sean Christopherson
2026-08-07 20:26 ` Edgecombe, Rick P
2026-08-07 22:18 ` Sean Christopherson
2026-08-06 21:40 ` [PATCH 3/4] KVM: x86/mmu: Top-up memory caches when retrying "map private PFN" Sean Christopherson
2026-08-06 21:56 ` sashiko-bot
2026-08-06 22:07 ` Sean Christopherson
2026-08-07 20:38 ` Edgecombe, Rick P
2026-08-07 22:13 ` Sean Christopherson
2026-08-06 21:40 ` [PATCH 4/4] KVM: x86/mmu: Add sanity check to detect stale page faults in " Sean Christopherson
2026-08-06 21:54 ` sashiko-bot
2026-08-06 22:12 ` Sean Christopherson [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=anUG2D2jrXatibSy@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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