Skip to content

Commit 2ff1411

Browse files
committed
KVM: TDX: Assert that mmu_lock is held for write when removing S-EPT entries
Unconditionally assert that mmu_lock is held for write when removing S-EPT entries, not just when removing S-EPT entries triggers certain conditions, e.g. needs to do TDH_MEM_TRACK or kick vCPUs out of the guest. Conditionally asserting implies that it's safe to hold mmu_lock for read when those paths aren't hit, which is simply not true, as KVM doesn't support removing S-EPT entries under read-lock. Only two paths lead to remove_external_spte(), and both paths asserts that mmu_lock is held for write (tdp_mmu_set_spte() via lockdep, and handle_removed_pt() via KVM_BUG_ON()). Deliberately leave lockdep assertions in the "no vCPUs" helpers to document that wait_for_sept_zap is guarded by holding mmu_lock for write, and keep the conditional assert in tdx_track() as well, but with a comment to help explain why holding mmu_lock for write matters (above and beyond why tdx_sept_remove_private_spte()'s requirements). Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20251030200951.3402865-21-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 55560b6 commit 2ff1411

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,11 @@ static void tdx_track(struct kvm *kvm)
17151715
if (unlikely(kvm_tdx->state != TD_STATE_RUNNABLE))
17161716
return;
17171717

1718+
/*
1719+
* The full sequence of TDH.MEM.TRACK and forcing vCPUs out of guest
1720+
* mode must be serialized, as TDH.MEM.TRACK will fail if the previous
1721+
* tracking epoch hasn't completed.
1722+
*/
17181723
lockdep_assert_held_write(&kvm->mmu_lock);
17191724

17201725
err = tdh_mem_track(&kvm_tdx->td);
@@ -1762,6 +1767,8 @@ static void tdx_sept_remove_private_spte(struct kvm *kvm, gfn_t gfn,
17621767
gpa_t gpa = gfn_to_gpa(gfn);
17631768
u64 err, entry, level_state;
17641769

1770+
lockdep_assert_held_write(&kvm->mmu_lock);
1771+
17651772
/*
17661773
* HKID is released after all private pages have been removed, and set
17671774
* before any might be populated. Warn if zapping is attempted when

0 commit comments

Comments
 (0)