Re: [RFC PATCH v5 06/45] KVM: x86/mmu: Fold set_external_spte_present() into its sole caller

From: Sean Christopherson

Date: Thu Feb 05 2026 - 18:07:16 EST


On Wed, Feb 04, 2026, Yan Zhao wrote:
> On Wed, Jan 28, 2026 at 05:14:38PM -0800, Sean Christopherson wrote:
> > @@ -626,6 +599,8 @@ static inline int __must_check __tdp_mmu_set_spte_atomic(struct kvm *kvm,
> > struct tdp_iter *iter,
> > u64 new_spte)
> > {
> > + u64 *raw_sptep = rcu_dereference(iter->sptep);
> > +
> > /*
> > * The caller is responsible for ensuring the old SPTE is not a FROZEN
> > * SPTE. KVM should never attempt to zap or manipulate a FROZEN SPTE,
> > @@ -638,31 +613,46 @@ static inline int __must_check __tdp_mmu_set_spte_atomic(struct kvm *kvm,
> > int ret;
> >
> > /*
> > - * Users of atomic zapping don't operate on mirror roots,
> > - * so don't handle it and bug the VM if it's seen.
> > + * KVM doesn't currently support zapping or splitting mirror
> > + * SPTEs while holding mmu_lock for read.
> > */
> > - if (KVM_BUG_ON(!is_shadow_present_pte(new_spte), kvm))
> > + if (KVM_BUG_ON(is_shadow_present_pte(iter->old_spte), kvm) ||
> > + KVM_BUG_ON(!is_shadow_present_pte(new_spte), kvm))
> > return -EBUSY;
> Should this be -EIO instead?

Yeah, probably.

> Though -EBUSY was introduced by commit 94faba8999b9 ('KVM: x86/tdp_mmu:
> Propagate tearing down mirror page tables')
>
> > - ret = set_external_spte_present(kvm, iter->sptep, iter->gfn,
> > - &iter->old_spte, new_spte, iter->level);
> Add "lockdep_assert_held(&kvm->mmu_lock)" for this case?

No, because I don't want to unnecessarily bleed TDX details into common MMU. Ah,
but there was a pre-existing lockdep in set_external_spte_present(). So I guess
that's arguably a functional change and should be called out in the changelog.

But I still want to drop the assertion (or maybe move it to TDX in a prep patch),
because ultimately the requirements around locking come from TDX, not from the
TDP MMU.