Skip to content

Commit c273fee

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Introduce helper to calculate fault IPA offset
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>
1 parent ebbcaec commit c273fee

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

arch/arm64/include/asm/kvm_arm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@
344344
#define PAR_TO_HPFAR(par) \
345345
(((par) & GENMASK_ULL(52 - 1, 12)) >> 8)
346346

347+
#define FAR_TO_FIPA_OFFSET(far) ((far) & GENMASK_ULL(11, 0))
348+
347349
#define ECN(x) { ESR_ELx_EC_##x, #x }
348350

349351
#define kvm_arm_exception_class \

arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
4444

4545
/* Build the full address */
4646
fault_ipa = kvm_vcpu_get_fault_ipa(vcpu);
47-
fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
47+
fault_ipa |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
4848

4949
/* If not for GICV, move on */
5050
if (fault_ipa < vgic->vgic_cpu_base ||

arch/arm64/kvm/inject_fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void kvm_inject_size_fault(struct kvm_vcpu *vcpu)
258258
unsigned long addr, esr;
259259

260260
addr = kvm_vcpu_get_fault_ipa(vcpu);
261-
addr |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
261+
addr |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
262262

263263
__kvm_inject_sea(vcpu, kvm_vcpu_trap_is_iabt(vcpu), addr);
264264

arch/arm64/kvm/mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
20702070

20712071
/* Falls between the IPA range and the PARange? */
20722072
if (fault_ipa >= BIT_ULL(VTCR_EL2_IPA(vcpu->arch.hw_mmu->vtcr))) {
2073-
fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
2073+
fault_ipa |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
20742074

20752075
return kvm_inject_sea(vcpu, is_iabt, fault_ipa);
20762076
}
@@ -2175,7 +2175,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
21752175
* faulting VA. This is always 12 bits, irrespective
21762176
* of the page size.
21772177
*/
2178-
ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
2178+
ipa |= FAR_TO_FIPA_OFFSET(kvm_vcpu_get_hfar(vcpu));
21792179
ret = io_mem_abort(vcpu, ipa);
21802180
goto out_unlock;
21812181
}

0 commit comments

Comments
 (0)