Skip to content

Commit e25c233

Browse files
48casean-jc
authored andcommitted
KVM: x86/mmu: Skip shadow MMU test_young if TDP MMU reports page as young
Reorder the processing of the TDP MMU versus the shadow MMU when aging SPTEs, and skip the shadow MMU entirely in the test-only case if the TDP MMU reports that the page is young, i.e. completely avoid taking mmu_lock if the TDP MMU SPTE is young. Swap the order for the test-and-age helper as well for consistency. Signed-off-by: James Houghton <jthoughton@google.com> Acked-by: Yu Zhao <yuzhao@google.com> Link: https://lore.kernel.org/r/20250204004038.1680123-7-jthoughton@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b146a9b commit e25c233

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,31 +1592,31 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
15921592
{
15931593
bool young = false;
15941594

1595+
if (tdp_mmu_enabled)
1596+
young = kvm_tdp_mmu_age_gfn_range(kvm, range);
1597+
15951598
if (kvm_memslots_have_rmaps(kvm)) {
15961599
write_lock(&kvm->mmu_lock);
1597-
young = kvm_rmap_age_gfn_range(kvm, range, false);
1600+
young |= kvm_rmap_age_gfn_range(kvm, range, false);
15981601
write_unlock(&kvm->mmu_lock);
15991602
}
16001603

1601-
if (tdp_mmu_enabled)
1602-
young |= kvm_tdp_mmu_age_gfn_range(kvm, range);
1603-
16041604
return young;
16051605
}
16061606

16071607
bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
16081608
{
16091609
bool young = false;
16101610

1611-
if (kvm_memslots_have_rmaps(kvm)) {
1611+
if (tdp_mmu_enabled)
1612+
young = kvm_tdp_mmu_test_age_gfn(kvm, range);
1613+
1614+
if (!young && kvm_memslots_have_rmaps(kvm)) {
16121615
write_lock(&kvm->mmu_lock);
1613-
young = kvm_rmap_age_gfn_range(kvm, range, true);
1616+
young |= kvm_rmap_age_gfn_range(kvm, range, true);
16141617
write_unlock(&kvm->mmu_lock);
16151618
}
16161619

1617-
if (tdp_mmu_enabled)
1618-
young |= kvm_tdp_mmu_test_age_gfn(kvm, range);
1619-
16201620
return young;
16211621
}
16221622

0 commit comments

Comments
 (0)