Skip to content

TDX MMU refactors

Yan Zhao kvm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest15 patches 2 repliesIn review
  2. v215 patches 7 repliesApplied

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15KVM: TDX: Drop kvm_x86_ops.link_external_spt()arch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/tdp_mmu.c +1 more+44 -520 replies
2/15KVM: TDX: Wrap mapping of leaf and non-leaf S-EPT entries into helpersarch/x86/kvm/vmx/tdx.c+15 -90 replies
3/15KVM: x86/mmu: Fold set_external_spte_present() into its sole callerarch/x86/kvm/mmu/tdp_mmu.c+31 -410 replies
4/15KVM: x86/mmu: Plumb param "old_spte" into kvm_x86_ops.set_external_spte()arch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/tdp_mmu.c arch/x86/kvm/vmx/tdx.c+15 -150 replies
5/15KVM: TDX: Move KVM_BUG_ON()s in __tdp_mmu_set_spte_atomic() to TDX codearch/x86/kvm/mmu/tdp_mmu.c arch/x86/kvm/vmx/tdx.c+3 -100 replies
6/15KVM: TDX: Move lockdep assert in __tdp_mmu_set_spte_atomic() to TDX codearch/x86/kvm/mmu/tdp_mmu.c arch/x86/kvm/vmx/tdx.c+2 -20 replies
7/15KVM: x86/tdp_mmu: Morph !is_frozen_spte() check into a KVM_MMU_WARN_ON()arch/x86/kvm/mmu/tdp_mmu.c+4 -10 replies
8/15KVM: x86/mmu: Plumb "sp" _pointer_ into the TDP MMU's handle_changed_spte()arch/x86/kvm/mmu/tdp_mmu.c+18 -170 replies
9/15KVM: x86/tdp_mmu: Centrally propagate to-present/atomic zap updates to external PTEsarch/x86/kvm/mmu/tdp_mmu.c+81 -450 replies
10/15KVM: x86/mmu: Drop KVM_BUG_ON() on shared lock to zap child external PTEsarch/x86/kvm/mmu/tdp_mmu.c+1 -30 replies
11/15KVM: TDX: Hoist tdx_sept_remove_private_spte() above set_private_spte()arch/x86/kvm/vmx/tdx.c+40 -400 replies
12/15KVM: TDX: Drop kvm_x86_ops.remove_external_spte()arch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/tdp_mmu.c +1 more+31 -490 replies
13/15KVM: TDX: Rename tdx_sept_remove_private_spte() to show it's for leaf SPTEsarch/x86/kvm/vmx/tdx.c+4 -40 replies
14/15KVM: x86: Move error handling inside free_external_spt()arch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/tdp_mmu.c +1 more+18 -280 replies
15/15KVM: TDX: Move external page table freeing to TDX codearch/x86/kvm/mmu/tdp_mmu.c arch/x86/kvm/vmx/tdx.c+21 -60 replies

Reviews trailers per patch

None of the 15 patches has a Reviewed-by or Acked-by.

PatchSean Christopherson
1/15
2/15
3/15
4/15
5/15
6/15
7/15
8/15
9/15Not-yet-Signed-off-by
10/15
11/15
12/15
13/15
14/15
15/15Not-yet-Signed-off-by

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/15] TDX MMU refactors

This is v3 of the TDX MMU refactor series, a simple rebase of v2 [2] to kvm-x86-next-2026.05.26 plus addressing a trace issue reported by Sashiko [7].

The code is also available at [3]. (Note: due to the instability of v7.1.0-rc2, I also applied series [4] and [5] in [3] to pass CI.)

As in v2, patches 9 and 15 still have the "Not-yet-Signed-off-by" tag.

Patches layout
--------------
Part 1: Patches 1-9 (for to-present and atomic-zap-leaf-SPTE changes).

Patches 1-4 are preparation for patch 5. So when patch 5 drops KVM_BUG_ON()s on zappings in __tdp_mmu_set_spte_atomic(), both to-present changes and atomic-zap-leaf-SPTE changes are propagated via the set_external_spte() op and TDX code can trigger KVM_BUG_ON()s on the atomic zap scenario.

Patches 5-6 move asserts and KVM_BUG_ON()s from TDP MMU to TDX code.

Patches 7-9: centralize external PTE propagation triggered by tdp_mmu_set_spte_atomic() (for to-present and atomic-zap-leaf-SPTE changes) to __handle_changed_spte().

Part 2: Patches 10-13 (for zapping of leaf SPTEs).
Drop remove_external_spte() op and have __handle_changed_spte() centralize propagation of leaf SPTE zapping in all scenarios.

Part 3: Patches 14-15 (for zapping of non-leaf SPTEs).
Cleanup of the free_external_spt() op.

Changelogs
----------
v2 [2] --> v3:
- Rebased to kvm-x86-next-2026.05.26.
- Fixed a missing trace issue reported by Sashiko [7].

v1 [1] --> v2:
- Dropped 4 cleanup patches that will be pulled separately into the base.
- Rebased onto v7.1.0-rc2 and the v2 struct page to PFN conversion series.
- Fixed typos, code comments, updated commit messages, and removed unused parameters.
- Patch reordering and added back patch 8.
- Renamed TDX functions to indicate map/remove leaf/non-leaf status.
- Addressed the sashiko comment [6] of how atomic zaps are handled before all changes (except for reclaiming non-leaf pages) are propagated via the set_external_spte() op in __handle_changed_spte().
- Added expected lock and valid scenarios in function comments of tdx_sept_set_private_spte() and tdx_sept_free_private_spt().
- Explained why kvm_tdp_mmu_age_spte() does not warn about installing FROZEN_SPTE as a long-term value and explained why it warns on mirror roots.

Sean's DPAMT/Huge page combined series [0] --> v1:
- Went back to free_external_spt() name. Since free_external_sp() was dropped from the changes, there was no similarly named function to confuse.
- Suggestions around dropping or moving KVM_BUG_ON/WARNs were turned into patches.

Thanks
Yan

[0] https://lore.kernel.org/kvm/[email protected]
[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/kvm/[email protected]
[3] https://github.com/intel-staging/tdx/tree/tdx_mmu_refactors_v3
[4] https://lore.kernel.org/all/[email protected]
[5] https://lore.kernel.org/all/[email protected]
[6] https://lore.kernel.org/lkml/[email protected]
[7] https://lore.kernel.org/kvm/[email protected]

Rick Edgecombe (4):
KVM: TDX: Move KVM_BUG_ON()s in __tdp_mmu_set_spte_atomic() to TDX
code
KVM: TDX: Move lockdep assert in __tdp_mmu_set_spte_atomic() to TDX
code
KVM: x86/tdp_mmu: Morph !is_frozen_spte() check into a

    KVM_MMU_WARN_ON()

KVM: x86/mmu: Drop KVM_BUG_ON() on shared lock to zap child external
PTEs

Sean Christopherson (10):
KVM: TDX: Drop kvm_x86_ops.link_external_spt()
KVM: TDX: Wrap mapping of leaf and non-leaf S-EPT entries into helpers
KVM: x86/mmu: Fold set_external_spte_present() into its sole caller
KVM: x86/mmu: Plumb param "old_spte" into

    kvm_x86_ops.set_external_spte()

KVM: x86/mmu: Plumb "sp" _pointer_ into the TDP MMU's
handle_changed_spte()
KVM: x86/tdp_mmu: Centrally propagate to-present/atomic zap updates to
external PTEs
KVM: TDX: Hoist tdx_sept_remove_private_spte() above
set_private_spte()
KVM: TDX: Drop kvm_x86_ops.remove_external_spte()
KVM: x86: Move error handling inside free_external_spt()
KVM: TDX: Move external page table freeing to TDX code

Yan Zhao (1):
KVM: TDX: Rename tdx_sept_remove_private_spte() to show it's for leaf
SPTEs

 arch/x86/include/asm/kvm-x86-ops.h |   4 +-
 arch/x86/include/asm/kvm_host.h    |  13 +-
 arch/x86/kvm/mmu/tdp_mmu.c         | 275 ++++++++++++-----------------
 arch/x86/kvm/vmx/tdx.c             | 172 ++++++++++++------
 4 files changed, 235 insertions(+), 229 deletions(-)
Signature · 1 line
2.43.2