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 HV

Replace Book3s HV's homebrewed 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-61-seanjc@google.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
0865ba14 334511d4

+4 -21
+4 -21
arch/powerpc/kvm/book3s_64_mmu_hv.c
··· 603 603 write_ok = writing; 604 604 hva = gfn_to_hva_memslot(memslot, gfn); 605 605 606 - /* 607 - * Do a fast check first, since __gfn_to_pfn_memslot doesn't 608 - * do it with !atomic && !async, which is how we call it. 609 - * We always ask for write permission since the common case 610 - * is that the page is writable. 611 - */ 612 - if (get_user_page_fast_only(hva, FOLL_WRITE, &page)) { 613 - write_ok = true; 614 - } else { 615 - /* Call KVM generic code to do the slow-path check */ 616 - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL, 617 - writing, &write_ok); 618 - if (is_error_noslot_pfn(pfn)) 619 - return -EFAULT; 620 - page = NULL; 621 - if (pfn_valid(pfn)) { 622 - page = pfn_to_page(pfn); 623 - if (PageReserved(page)) 624 - page = NULL; 625 - } 626 - } 606 + pfn = __kvm_faultin_pfn(memslot, gfn, writing ? FOLL_WRITE : 0, 607 + &write_ok, &page); 608 + if (is_error_noslot_pfn(pfn)) 609 + return -EFAULT; 627 610 628 611 /* 629 612 * Read the PTE from the process' radix tree and use that