mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] KVM: x86/mmu: Fix NX page unaccounting for TDP MMU pages
@ 2026-09-16 10:04 Carlos López
  2026-09-16 13:44 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos López @ 2026-09-16 10:04 UTC (permalink / raw)
  To: kvm, seanjc, pbonzini
  Cc: Carlos López, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, Vipin Sharma, James Houghton,
	open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)

unaccount_nx_huge_page() unconditionally passes KVM_SHADOW_MMU to
untrack_possible_nx_huge_page(), which is incorrect, particularly on
the path from kvm_recover_nx_huge_pages(), which handles pages from
both MMUs.

Fix this by adding a helper to retrieve the MMU type of a page and use
it to pass the correct variant down.

Fixes: 6777885605e1 ("KVM: x86/mmu: Track possible NX huge pages separately for TDP vs. Shadow MMU")
Signed-off-by: Carlos López <clopez@suse.de>
---
v2:
  * Use a helper to retrieve the MMU type to avoid referencing KVM_TDP_MMU for
    32 bit builds (Sashiko).
 arch/x86/kvm/mmu/mmu.c     |  2 +-
 arch/x86/kvm/mmu/tdp_mmu.h | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 9788ff180374..fa3e9ff7bec1 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -868,7 +868,7 @@ static void unaccount_nx_huge_page(struct kvm *kvm, struct kvm_mmu_page *sp)
 {
 	sp->nx_huge_page_disallowed = false;
 
-	untrack_possible_nx_huge_page(kvm, sp, KVM_SHADOW_MMU);
+	untrack_possible_nx_huge_page(kvm, sp, page_mmu_type(sp));
 }
 
 static struct kvm_memory_slot *gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu,
diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
index bd62977c9199..17e506ea3298 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.h
+++ b/arch/x86/kvm/mmu/tdp_mmu.h
@@ -115,8 +115,19 @@ u64 *kvm_tdp_mmu_fast_pf_get_last_sptep(struct kvm_vcpu *vcpu, gfn_t gfn,
 
 #ifdef CONFIG_X86_64
 static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return sp->tdp_mmu_page; }
+
+static inline enum kvm_mmu_type page_mmu_type(struct kvm_mmu_page *sp) {
+	return is_tdp_mmu_page(sp) ? KVM_TDP_MMU : KVM_SHADOW_MMU;
+}
+
 #else
+
 static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return false; }
+
+static inline enum kvm_mmu_type page_mmu_type(struct kvm_mmu_page *sp) {
+	return KVM_SHADOW_MMU;
+}
+
 #endif
 
 #endif /* __KVM_X86_MMU_TDP_MMU_H */

base-commit: 70c944caf570fda2d79baa71435589a8db39f048
-- 
2.51.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-16 13:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 10:04 [PATCH v2] KVM: x86/mmu: Fix NX page unaccounting for TDP MMU pages Carlos López
2026-09-16 13:44 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®