Re: [RFC PATCH v5 05/45] KVM: TDX: Drop kvm_x86_ops.link_external_spt(), use .set_external_spte() for all

From: Sean Christopherson

Date: Thu Feb 05 2026 - 18:14:44 EST


On Wed, Feb 04, 2026, Yan Zhao wrote:
> On Tue, Feb 03, 2026 at 08:05:05PM +0000, Sean Christopherson wrote:
> > On Tue, Feb 03, 2026, Yan Zhao wrote:
> > > On Wed, Jan 28, 2026 at 05:14:37PM -0800, Sean Christopherson wrote:
> > > > static int __must_check set_external_spte_present(struct kvm *kvm, tdp_ptep_t sptep,
> > > > gfn_t gfn, u64 *old_spte,
> > > > u64 new_spte, int level)
> > > > {
> > > > - bool was_present = is_shadow_present_pte(*old_spte);
> > > > - bool is_present = is_shadow_present_pte(new_spte);
> > > > - bool is_leaf = is_present && is_last_spte(new_spte, level);
> > > > - int ret = 0;
> > > > -
> > > > - KVM_BUG_ON(was_present, kvm);
> > > > + int ret;
> > > >
> > > > lockdep_assert_held(&kvm->mmu_lock);
> > > > +
> > > > + if (KVM_BUG_ON(is_shadow_present_pte(*old_spte), kvm))
> > > > + return -EIO;
> > > Why not move this check of is_shadow_present_pte() to tdx_sept_set_private_spte()
> > > as well?
> >
> > The series gets there eventually, but as of this commit, @old_spte isn't plumbed
> > into tdx_sept_set_private_spte().
> >
> > > Or also check !is_shadow_present_pte(new_spte) in TDP MMU?
> >
> > Not sure I understand this suggestion.
> Sorry. The accurate expression should be
> "what about moving !is_shadow_present_pte(new_spte) to TDP MMU as well?".

It's already there, in __tdp_mmu_set_spte_atomic():

/*
* KVM doesn't currently support zapping or splitting mirror
* SPTEs while holding mmu_lock for read.
*/
if (KVM_BUG_ON(is_shadow_present_pte(iter->old_spte), kvm) ||
KVM_BUG_ON(!is_shadow_present_pte(new_spte), kvm))
return -EBUSY;


> > > And as Rick also mentioned, better to remove external in external_spt, e.g.
> > > something like pt_page.
> >
> > Yeah, maybe sept_spt?
> Hmm, here sept_spt is of type struct page, while sp->spt and sp->external_spt
> represents VA. Not sure if it will cause confusion.

How about sept_pt?