Skip to contentSkip to conversation

KVM: x86/mmu: Fix NX page unaccounting for TDP MMU pages

PATCH Superseded Carlos López 2 participants 2 messages Sep 15

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86/mmu: Fix NX page unaccounting for TDP MMU pages

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 retrieving the MMU type via is_tdp_mmu_page() and passing it down.

Fixes 6777885605e1 ("KVM: x86/mmu: Track possible NX huge pages separately for TDP vs. Shadow MMU")
---
 arch/x86/kvm/mmu/mmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +3 -1
index 9788ff180374..61996669b6f6 100644
@@ -866,9 +866,11 @@ void untrack_possible_nx_huge_page(struct kvm *kvm, struct kvm_mmu_page *sp,
 
 static void unaccount_nx_huge_page(struct kvm *kvm, struct kvm_mmu_page *sp)
 {
+	enum kvm_mmu_type mmu_type = is_tdp_mmu_page(sp) ? KVM_TDP_MMU : KVM_SHADOW_MMU;
+
 	sp->nx_huge_page_disallowed = false;
 
-	untrack_possible_nx_huge_page(kvm, sp, KVM_SHADOW_MMU);
+	untrack_possible_nx_huge_page(kvm, sp, mmu_type);
 }
 
 static struct kvm_memory_slot *gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu,

base-commit: 70c944caf570fda2d79baa71435589a8db39f048

Signature · 1 line
2.51.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] mmu: build failure on 32-bit x86 due to undeclared KVM_TDP_MMU --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] mmu: build failure on 32-bit x86 due to undeclared KVM_TDP_MMU
--

commit c2443a58667359b4d898625aee21d7fa954accfd
Author: Carlos López <[email protected]>
KVM: x86/mmu: Fix NX page unaccounting for TDP MMU pages

This commit fixes unaccounting of NX huge pages for TDP MMU pages by passing the correct MMU type to untrack_possible_nx_huge_page() instead of always hardcoding KVM_SHADOW_MMU.

Quoted 4 lines
arch/x86/kvm/mmu/mmu.c +0 -0
index 9788ff1803740..61996669b6f6a 100644

[ ... ]

arch/x86/kvm/mmu/mmu.c void untrack_possible_nx_huge_page(struct kvm *kvm, struct kvm_mmu_page *sp, · line 869

Quoted 5 lines
arch/x86/kvm/mmu/mmu.c +1 -0
@@ -866,9 +866,11 @@ void untrack_possible_nx_huge_page(struct kvm *kvm, struct kvm_mmu_page *sp,
 
 static void unaccount_nx_huge_page(struct kvm *kvm, struct kvm_mmu_page *sp)
 {
+	enum kvm_mmu_type mmu_type = is_tdp_mmu_page(sp) ? KVM_TDP_MMU : KVM_SHADOW_MMU;

[Severity: Low]
Will this break the build on 32-bit x86 systems? KVM_TDP_MMU is only defined when CONFIG_X86_64 is enabled. Unconditionally referencing it here in unaccount_nx_huge_page() will result in an undeclared identifier error when compiling KVM with CONFIG_X86_32=y.

Quoted 6 lines
arch/x86/kvm/mmu/mmu.c +2 -1
+
 	sp->nx_huge_page_disallowed = false;
 
-	untrack_possible_nx_huge_page(kvm, sp, KVM_SHADOW_MMU);
+	untrack_possible_nx_huge_page(kvm, sp, mmu_type);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1