]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: arm64: Optimize early exit checks in kvm_s2_fault_pin_pfn()
authorFuad Tabba <tabba@google.com>
Fri, 6 Mar 2026 14:02:30 +0000 (14:02 +0000)
committerMarc Zyngier <maz@kernel.org>
Sat, 28 Mar 2026 11:29:40 +0000 (11:29 +0000)
Optimize the early exit checks in kvm_s2_fault_pin_pfn by grouping all
error responses under the generic is_error_noslot_pfn check first,
avoiding unnecessary branches in the hot path.

Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/mmu.c

index fe942be061cb008cdef21ba05594b6a0f66bec16..74c512839e81c5c7c9bd2c9ed91bfc4ffc116961 100644 (file)
@@ -1791,12 +1791,13 @@ static int kvm_s2_fault_pin_pfn(struct kvm_s2_fault *fault)
        fault->pfn = __kvm_faultin_pfn(fault->memslot, fault->gfn,
                                       fault->write_fault ? FOLL_WRITE : 0,
                                       &fault->writable, &fault->page);
-       if (fault->pfn == KVM_PFN_ERR_HWPOISON) {
-               kvm_send_hwpoison_signal(fault->hva, __ffs(fault->vma_pagesize));
-               return 0;
-       }
-       if (is_error_noslot_pfn(fault->pfn))
+       if (unlikely(is_error_noslot_pfn(fault->pfn))) {
+               if (fault->pfn == KVM_PFN_ERR_HWPOISON) {
+                       kvm_send_hwpoison_signal(fault->hva, __ffs(fault->vma_pagesize));
+                       return 0;
+               }
                return -EFAULT;
+       }
 
        return 1;
 }