]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86/mmu: Skip shadow MMU test_young if TDP MMU reports page as young
authorJames Houghton <jthoughton@google.com>
Tue, 4 Feb 2025 00:40:33 +0000 (00:40 +0000)
committerSean Christopherson <seanjc@google.com>
Fri, 14 Feb 2025 15:17:23 +0000 (07:17 -0800)
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>
arch/x86/kvm/mmu/mmu.c

index b73b3c12f76fdea1fe6ec2e99ded06bea95d48f3..3fc461ebaf05548332b571bf1b29cddfbea427fb 100644 (file)
@@ -1592,15 +1592,15 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
 {
        bool young = false;
 
+       if (tdp_mmu_enabled)
+               young = kvm_tdp_mmu_age_gfn_range(kvm, range);
+
        if (kvm_memslots_have_rmaps(kvm)) {
                write_lock(&kvm->mmu_lock);
-               young = kvm_rmap_age_gfn_range(kvm, range, false);
+               young |= kvm_rmap_age_gfn_range(kvm, range, false);
                write_unlock(&kvm->mmu_lock);
        }
 
-       if (tdp_mmu_enabled)
-               young |= kvm_tdp_mmu_age_gfn_range(kvm, range);
-
        return young;
 }
 
@@ -1608,15 +1608,15 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
 {
        bool young = false;
 
-       if (kvm_memslots_have_rmaps(kvm)) {
+       if (tdp_mmu_enabled)
+               young = kvm_tdp_mmu_test_age_gfn(kvm, range);
+
+       if (!young && kvm_memslots_have_rmaps(kvm)) {
                write_lock(&kvm->mmu_lock);
-               young = kvm_rmap_age_gfn_range(kvm, range, true);
+               young |= kvm_rmap_age_gfn_range(kvm, range, true);
                write_unlock(&kvm->mmu_lock);
        }
 
-       if (tdp_mmu_enabled)
-               young |= kvm_tdp_mmu_test_age_gfn(kvm, range);
-
        return young;
 }