[PATCH 13/17] KVM: TDX: Hoist tdx_sept_remove_private_spte() above set_private_spte()

Rick Edgecombe
2026-03-27T20:14:35Z

From: Sean Christopherson <seanjc@google.com>

Move tdx_sept_remove_private_spte() (and its tdx_track() helper) above
tdx_sept_set_private_spte() in anticipation of routing all non-atomic
S-EPT writes (with the exception of reclaiming non-leaf pages) through
the "set" API.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
---
arch/x86/kvm/vmx/tdx.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 569a0576e7c9..5a1a6610a98f 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -1719,20 +1719,6 @@ static int tdx_sept_map_leaf_spte(struct kvm *kvm, gfn_t gfn, enum pg_level leve
return tdx_mem_page_aug(kvm, gfn, level, pfn);
}

-static int tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn, u64 old_spte,
- u64 new_spte, enum pg_level level)
-{
- if (KVM_BUG_ON(!is_shadow_present_pte(new_spte), kvm))
- return -EIO;
-
- lockdep_assert_held(&kvm->mmu_lock);
-
- if (!is_last_spte(new_spte, level))
- return tdx_sept_link_private_spt(kvm, gfn, level, new_spte);
-
- return tdx_sept_map_leaf_spte(kvm, gfn, level, new_spte);
-}
-
/*
* Ensure shared and private EPTs to be flushed on all vCPUs.
* tdh_mem_track() is the only caller that increases TD epoch. An increase in
@@ -1852,6 +1838,20 @@ static void tdx_sept_remove_private_spte(struct kvm *kvm, gfn_t gfn,
tdx_quirk_reset_page(page);
}

+static int tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn, u64 old_spte,
+ u64 new_spte, enum pg_level level)
+{
+ if (KVM_BUG_ON(!is_shadow_present_pte(new_spte), kvm))
+ return -EIO;
+
+ lockdep_assert_held(&kvm->mmu_lock);
+
+ if (!is_last_spte(new_spte, level))
+ return tdx_sept_link_private_spt(kvm, gfn, level, new_spte);
+
+ return tdx_sept_map_leaf_spte(kvm, gfn, level, new_spte);
+}
+
void tdx_deliver_interrupt(struct kvm_lapic *apic, int delivery_mode,
int trig_mode, int vector)
{
--
2.53.0