Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: PPC: Use __kvm_faultin_pfn() to handle page faults on Book3s Radix

Replace Book3s Radix's homebrewed (read: copy+pasted) fault-in logic with
__kvm_faultin_pfn(), which functionally does pretty much the exact same
thing.

Note, when the code was written, KVM indeed didn't do fast GUP without
"!atomic && !async", but that has long since changed (KVM tries fast GUP
for all writable mappings).

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-62-seanjc@google.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
431d2f7d 0865ba14

+5 -24
+5 -24
arch/powerpc/kvm/book3s_64_mmu_radix.c
··· 829 829 unsigned long mmu_seq; 830 830 unsigned long hva, gfn = gpa >> PAGE_SHIFT; 831 831 bool upgrade_write = false; 832 - bool *upgrade_p = &upgrade_write; 833 832 pte_t pte, *ptep; 834 833 unsigned int shift, level; 835 834 int ret; 836 835 bool large_enable; 836 + kvm_pfn_t pfn; 837 837 838 838 /* used to check for invalidations in progress */ 839 839 mmu_seq = kvm->mmu_invalidate_seq; 840 840 smp_rmb(); 841 841 842 - /* 843 - * Do a fast check first, since __gfn_to_pfn_memslot doesn't 844 - * do it with !atomic && !async, which is how we call it. 845 - * We always ask for write permission since the common case 846 - * is that the page is writable. 847 - */ 848 842 hva = gfn_to_hva_memslot(memslot, gfn); 849 - if (!kvm_ro && get_user_page_fast_only(hva, FOLL_WRITE, &page)) { 850 - upgrade_write = true; 851 - } else { 852 - unsigned long pfn; 853 - 854 - /* Call KVM generic code to do the slow-path check */ 855 - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL, 856 - writing, upgrade_p); 857 - if (is_error_noslot_pfn(pfn)) 858 - return -EFAULT; 859 - page = NULL; 860 - if (pfn_valid(pfn)) { 861 - page = pfn_to_page(pfn); 862 - if (PageReserved(page)) 863 - page = NULL; 864 - } 865 - } 843 + pfn = __kvm_faultin_pfn(memslot, gfn, writing ? FOLL_WRITE : 0, 844 + &upgrade_write, &page); 845 + if (is_error_noslot_pfn(pfn)) 846 + return -EFAULT; 866 847 867 848 /* 868 849 * Read the PTE from the process' radix tree and use that