Re: [PATCH 2/4] KVM: x86/mmu: Harden "map private PFN" against unexpected root invalidation
From: Sean Christopherson
Date: Fri Aug 07 2026 - 18:23:04 EST
On Fri, Aug 07, 2026, Rick P Edgecombe wrote:
> On Thu, 2026-08-06 at 14:40 -0700, Sean Christopherson wrote:
> > @@ -5199,10 +5195,21 @@ int kvm_tdp_mmu_map_private_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn)
> > if (kvm_test_request(KVM_REQ_VM_DEAD, vcpu))
> > return -EIO;
> >
> > + r = kvm_mmu_reload(vcpu);
> > + if (r)
> > + return r;
> > +
> > cond_resched();
> >
> > guard(read_lock)(&kvm->mmu_lock);
> >
> > + /*
> > + * Because slots_lock is held, it should be impossible for roots
> > + * to be invalidated after the initial MMU reload. WARN, but
> > + * continue and re-reload the MMU to try and keep the VM alive.
> > + */
>
> It might be a little confusing when no MMU reload follows the comment. Maybe
> mention that the MMU reload is above? Either way ok to me.
Yeah, I don't love the comment either. The subtlety that it doesn't capture is
that KVM_REQ_MMU_FREE_OBSOLETE_ROOTS doesn't actually mean the current root is
invalid, just that it might be invalid and the vCPU needs to check.
How about this?
/*
* Because slots_lock is held, it should be impossible for *any*
* roots to be invalidated after the initial MMU reload. WARN,
* but continue on; the above MMU reload will do the right thing
* if the current root is actually invalid.
*/
> > + WARN_ON_ONCE(kvm_test_request(KVM_REQ_MMU_FREE_OBSOLETE_ROOTS, vcpu));
> > +
> > r = kvm_tdp_mmu_map(vcpu, &fault);
>