]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: arm64: Introduce helper to calculate fault IPA offset
authorFuad Tabba <tabba@google.com>
Thu, 11 Dec 2025 10:47:04 +0000 (10:47 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 15 Jan 2026 15:43:15 +0000 (15:43 +0000)
This 12-bit FAR fault IPA offset mask is hard-coded as 'GENMASK(11, 0)'
in several places to reconstruct the full fault IPA.

Introduce FAR_TO_FIPA_OFFSET() to calculate this value in a shared
header and replace all open-coded instances to improve readability.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20251211104710.151771-5-tabba@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_arm.h
arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
arch/arm64/kvm/inject_fault.c
arch/arm64/kvm/mmu.c

index e500600e4b9b8cf555a5b555db21b935dc6f83c1..58495593570cb4f5164fd9f87589c9870260f5da 100644 (file)
 #define PAR_TO_HPFAR(par)              \
        (((par) & GENMASK_ULL(52 - 1, 12)) >> 8)
 
+#define FAR_TO_FIPA_OFFSET(far) ((far) & GENMASK_ULL(11, 0))
+
 #define ECN(x) { ESR_ELx_EC_##x, #x }
 
 #define kvm_arm_exception_class \
index 5fd99763b54de536229f35c5305e8d17f9bfc065..f0605836821e2c927aead6ef6074e94dfe91e5b4 100644 (file)
@@ -44,7 +44,7 @@ int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
 
        /* Build the full address */
        fault_ipa  = kvm_vcpu_get_fault_ipa(vcpu);
-       fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
+       fault_ipa |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
 
        /* If not for GICV, move on */
        if (fault_ipa <  vgic->vgic_cpu_base ||
index dfcd66c6551799774c130eafddb9424ca00f72f0..c9bbce017dee98388dbdb9019f6c721be0cb6df3 100644 (file)
@@ -258,7 +258,7 @@ void kvm_inject_size_fault(struct kvm_vcpu *vcpu)
        unsigned long addr, esr;
 
        addr  = kvm_vcpu_get_fault_ipa(vcpu);
-       addr |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
+       addr |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
 
        __kvm_inject_sea(vcpu, kvm_vcpu_trap_is_iabt(vcpu), addr);
 
index 48d7c372a4cd02da5ea7a7cc0f685e8617a682dd..ba44a29b75aa3ea0b1193d53be0264d86df38d23 100644 (file)
@@ -2070,7 +2070,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
 
                /* Falls between the IPA range and the PARange? */
                if (fault_ipa >= BIT_ULL(VTCR_EL2_IPA(vcpu->arch.hw_mmu->vtcr))) {
-                       fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
+                       fault_ipa |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
 
                        return kvm_inject_sea(vcpu, is_iabt, fault_ipa);
                }
@@ -2175,7 +2175,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
                 * faulting VA. This is always 12 bits, irrespective
                 * of the page size.
                 */
-               ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
+               ipa |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
                ret = io_mem_abort(vcpu, ipa);
                goto out_unlock;
        }