]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: TDX: Move lockdep assert in __tdp_mmu_set_spte_atomic() to TDX code
authorRick Edgecombe <rick.p.edgecombe@intel.com>
Sat, 9 May 2026 07:55:57 +0000 (15:55 +0800)
committerSean Christopherson <seanjc@google.com>
Wed, 27 May 2026 22:35:12 +0000 (15:35 -0700)
Move the MMU lockdep assert in __tdp_mmu_set_spte_atomic() into the TDX
specific op because the assert is TDX specific in intention.

The TDP MMU has many lockdep asserts for various scenarios, and in fact
the callchains that are used for TDX already have a lockdep assert which
covers the case in __tdp_mmu_set_spte_atomic(). However, these asserts are
for management of the TDP root owned by KVM. In the
__tdp_mmu_set_spte_atomic() assert case, it is helping with a scheme to
avoid contention in the TDX module during zap operations. That is very
TDX specific.

One option would be to just remove the assert in
__tdp_mmu_set_spte_atomic() and rely on the other ones in the TDP MMU. But
that assert is for a different intention, and too far away from the
SEAMCALL that needs it. So just move it to TDX code.

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
Link: https://patch.msgid.link/20260509075557.4226-1-yan.y.zhao@intel.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/mmu/tdp_mmu.c
arch/x86/kvm/vmx/tdx.c

index ed806a4768c2c8f37e1fc77a3d88e4f0c9641635..dc455e6e7dc77c4a9d4d2db161cb4c6c9fa1b8c9 100644 (file)
@@ -612,8 +612,6 @@ static inline int __must_check __tdp_mmu_set_spte_atomic(struct kvm *kvm,
        if (is_mirror_sptep(iter->sptep) && !is_frozen_spte(new_spte)) {
                int ret;
 
-               lockdep_assert_held(&kvm->mmu_lock);
-
                /*
                 * We need to lock out other updates to the SPTE until the external
                 * page table has been modified. Use FROZEN_SPTE similar to
index ea3ad913e750a33d23aa6988db0141433e8dc7f7..2e41bddfb80e143972934ed6b35c1606c5bfdb72 100644 (file)
@@ -1721,6 +1721,8 @@ static int tdx_sept_map_leaf_spte(struct kvm *kvm, gfn_t gfn, enum pg_level leve
 static int tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn, u64 old_spte,
                                     u64 new_spte, enum pg_level level)
 {
+       lockdep_assert_held(&kvm->mmu_lock);
+
        if (KVM_BUG_ON(is_shadow_present_pte(old_spte), kvm))
                return -EIO;