KVM: x86/mmu: Fix NX page unaccounting for TDP MMU pages
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.
--- arch/x86/kvm/mmu/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +3 -1
@@ -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
[email protected]
AI reviewThank 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
[ ... ]
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