KVM: x86/mmu: Preserve nested TDP shadow page tables if they are used as roots
Subsystems (2)
Sean Christopherson
reviewerPATCH 1/1 KVM: x86/mmu: Preserve nested TDP shadow page tables if they are used as roots
From: Hyunwoo Kim <[email protected]>
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.
--- arch/x86/kvm/mmu/mmu.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/mmu/mmu.c +1 -0
@@ -2630,6 +2630,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);
base-commit: 2ff600d29ee478d0a8d46ef8a58afb5e038fe692
Signature · 1 line
2.56.0.218.g1ec904b173-goog
Sean Christopherson
reviewerQuoted 1 line · Sean Christopherson
From: Hyunwoo Kim <[email protected]>
Gah, I'm rusty sending patches to stable@. This should have:
[ Upstream commit 7a2c70e777a00c32ebafd376a6fe31ebb91c5b20 ]
I'll spam a v2 right away so that I don't forget...
Quoted 35 lines
kvm_mmu_zap_oldest_mmu_pages()excludes a shadow page whoseroot_countis non-zero from top-level reclaim, because such a page cannot be freed. The path inmmu_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 inkvm_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_countis non-zero.Fixes 2de4085cccea ("KVM: x86/MMU: Recursively zap nested TDP SPs when zapping last/only parent")Signed-off-by Hyunwoo Kim <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/mmu/mmu.c | 1 + 1 file changed, 1 insertion(+)arch/x86/kvm/mmu/mmu.c +1
-0@@ -2630,6 +2630,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);base-commit:
2ff600d29ee478d0a8d46ef8a58afb5e038fe692Signature · 1 line
2.56.0.218.g1ec904b173-goog