]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86/mmu: Preserve nested TDP shadow page tables if they are used as roots
authorHyunwoo Kim <imv4bel@gmail.com>
Sun, 12 Jul 2026 01:14:50 +0000 (10:14 +0900)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 21 Jul 2026 10:25:18 +0000 (12:25 +0200)
kvm_mmu_zap_oldest_mmu_pages() excludes a shadow page whose root_count
is non-zero from top-level reclaim, because such a page cannot be
freed. The path in mmu_page_zap_pte() that recursively zaps a parentless
nested TDP child has no such check. As a result, a shadow page can
be zapped even if the page itself can't be freed; as the comment in
kvm_mmu_zap_oldest_mmu_pages() notes, zapping it will just force vCPUs
to rebuild the page.

As in top-level reclaim, do not recursively prepare zapping of a
nested TDP child whose root_count is non-zero.

Fixes: 2de4085cccea ("KVM: x86/MMU: Recursively zap nested TDP SPs when zapping last/only parent")
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c

index 41f92ed1ca377fe3f2aa96ad2a85ee121dc5e05b..7e80abba73136c517b7da9df36e47faea894106d 100644 (file)
@@ -2642,6 +2642,7 @@ static int mmu_page_zap_pte(struct kvm *kvm, struct kvm_mmu_page *sp,
                         */
                        if (tdp_enabled && invalid_list &&
                            child->role.guest_mode &&
+                           !child->root_count &&
                            !atomic_long_read(&child->parent_ptes.val))
                                return kvm_mmu_prepare_zap_page(kvm, child,
                                                                invalid_list);