Skip to content

Commit 8c403cf

Browse files
48casean-jc
authored andcommitted
KVM: x86/mmu: Only check gfn age in shadow MMU if indirect_shadow_pages > 0
When aging SPTEs and the TDP MMU is enabled, process the shadow MMU if and only if the VM has at least one shadow page, as opposed to checking if the VM has rmaps. Checking for rmaps will effectively yield a false positive if the VM ran nested TDP VMs in the past, but is not currently doing so. Signed-off-by: James Houghton <jthoughton@google.com> Acked-by: Yu Zhao <yuzhao@google.com> Link: https://lore.kernel.org/r/20250204004038.1680123-8-jthoughton@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e25c233 commit 8c403cf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,14 +1588,19 @@ static bool kvm_rmap_age_gfn_range(struct kvm *kvm,
15881588
return young;
15891589
}
15901590

1591+
static bool kvm_may_have_shadow_mmu_sptes(struct kvm *kvm)
1592+
{
1593+
return !tdp_mmu_enabled || READ_ONCE(kvm->arch.indirect_shadow_pages);
1594+
}
1595+
15911596
bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
15921597
{
15931598
bool young = false;
15941599

15951600
if (tdp_mmu_enabled)
15961601
young = kvm_tdp_mmu_age_gfn_range(kvm, range);
15971602

1598-
if (kvm_memslots_have_rmaps(kvm)) {
1603+
if (kvm_may_have_shadow_mmu_sptes(kvm)) {
15991604
write_lock(&kvm->mmu_lock);
16001605
young |= kvm_rmap_age_gfn_range(kvm, range, false);
16011606
write_unlock(&kvm->mmu_lock);
@@ -1611,7 +1616,7 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
16111616
if (tdp_mmu_enabled)
16121617
young = kvm_tdp_mmu_test_age_gfn(kvm, range);
16131618

1614-
if (!young && kvm_memslots_have_rmaps(kvm)) {
1619+
if (!young && kvm_may_have_shadow_mmu_sptes(kvm)) {
16151620
write_lock(&kvm->mmu_lock);
16161621
young |= kvm_rmap_age_gfn_range(kvm, range, true);
16171622
write_unlock(&kvm->mmu_lock);

0 commit comments

Comments
 (0)