Skip to contentSkip to conversation

KVM: x86/mmu: Preserve nested TDP shadow page tables if they are used as roots

PATCH Applied Sean Christopherson 2 participants 2 messages Oct 21 – Oct 22

Subsystems (2)
lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

PATCH 1/1 KVM: x86/mmu: Preserve nested TDP shadow page tables if they are used as roots

From: Hyunwoo Kim <[email protected]>

[ Upstream commit 7a2c70e777a00c32ebafd376a6fe31ebb91c5b20 ]

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")
[sean: resolve minor conflict due to lack of lockless aging in 6.1]
---
 arch/x86/kvm/mmu/mmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +3 -1
index d7f1fbf8a83d..33e89555bb09 100644
@@ -2395,7 +2395,9 @@ static int mmu_page_zap_pte(struct kvm *kvm, struct kvm_mmu_page *sp,
 			 * avoids retaining a large number of stale nested SPs.
 			 */
 			if (tdp_enabled && invalid_list &&
-			    child->role.guest_mode && !child->parent_ptes.val)
+			    child->role.guest_mode &&
+			    !child->root_count &&
+			    !child->parent_ptes.val)
 				return kvm_mmu_prepare_zap_page(kvm, child,
 								invalid_list);
 		}

base-commit: 79807e970724c1f90cee1316361d61b80db4eef6

Signature · 1 line
2.56.0.218.g1ec904b173-goog
maintainer Applied
#1 lore raw
Quoted 2 lines

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

Queued for 6.1, thanks.

Signature · 2 lines
Thanks,
Sasha