]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86/mmu: Use gfn_to_page_many_atomic() when prefetching indirect PTEs
authorSean Christopherson <seanjc@google.com>
Thu, 10 Oct 2024 18:23:12 +0000 (11:23 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 25 Oct 2024 16:54:42 +0000 (12:54 -0400)
Use gfn_to_page_many_atomic() instead of gfn_to_pfn_memslot_atomic() when
prefetching indirect PTEs (direct_pte_prefetch_many() already uses the
"to page" APIS).  Functionally, the two are subtly equivalent, as the "to
pfn" API short-circuits hva_to_pfn() if hva_to_pfn_fast() fails, i.e. is
just a wrapper for get_user_page_fast_only()/get_user_pages_fast_only().

Switching to the "to page" API will allow dropping the @atomic parameter
from the entire hva_to_pfn() callchain.

Tested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20241010182427.1434605-11-seanjc@google.com>

arch/x86/kvm/mmu/paging_tmpl.h

index fbaae040218bd60723e7b97710c1c50f2a016a09..36b2607280f0fdcc6fe1f0ba951e3a4c254a397d 100644 (file)
@@ -535,8 +535,8 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
 {
        struct kvm_memory_slot *slot;
        unsigned pte_access;
+       struct page *page;
        gfn_t gfn;
-       kvm_pfn_t pfn;
 
        if (FNAME(prefetch_invalid_gpte)(vcpu, sp, spte, gpte))
                return false;
@@ -549,12 +549,11 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
        if (!slot)
                return false;
 
-       pfn = gfn_to_pfn_memslot_atomic(slot, gfn);
-       if (is_error_pfn(pfn))
+       if (gfn_to_page_many_atomic(slot, gfn, &page, 1) != 1)
                return false;
 
-       mmu_set_spte(vcpu, slot, spte, pte_access, gfn, pfn, NULL);
-       kvm_release_pfn_clean(pfn);
+       mmu_set_spte(vcpu, slot, spte, pte_access, gfn, page_to_pfn(page), NULL);
+       kvm_release_page_clean(page);
        return true;
 }