Skip to content

Commit 8c2d146

Browse files
James MorseMarc Zyngier
authored andcommitted
KVM: arm64: Define our own swab32() to avoid a uapi static inline
KVM uses swab32() when mediating GIC MMIO accesses if the GICV is badly aligned, and the host and guest differ in endianness. arm64 doesn't provide a __arch_swab32(), so __fswab32() is always backed by the macro implementation that the compiler reduces to a single instruction. But the static-inline causes problems for KVM if the compiler chooses not to inline this function, it may not be located in the __hyp_text where __vgic_v2_perform_cpuif_access() needs it. Create our own __kvm_swab32() macro that calls ___constant_swab32() directly. This way we know it will always be inlined. Signed-off-by: James Morse <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5c37f1a commit 8c2d146

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

arch/arm64/include/asm/kvm_hyp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
#define read_sysreg_el2(r) read_sysreg_elx(r, _EL2, _EL1)
4848
#define write_sysreg_el2(v,r) write_sysreg_elx(v, r, _EL2, _EL1)
4949

50+
/*
51+
* Without an __arch_swab32(), we fall back to ___constant_swab32(), but the
52+
* static inline can allow the compiler to out-of-line this. KVM always wants
53+
* the macro version as its always inlined.
54+
*/
55+
#define __kvm_swab32(x) ___constant_swab32(x)
56+
5057
int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu);
5158

5259
void __vgic_v3_save_state(struct kvm_vcpu *vcpu);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ int __hyp_text __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
6969
u32 data = vcpu_get_reg(vcpu, rd);
7070
if (__is_be(vcpu)) {
7171
/* guest pre-swabbed data, undo this for writel() */
72-
data = swab32(data);
72+
data = __kvm_swab32(data);
7373
}
7474
writel_relaxed(data, addr);
7575
} else {
7676
u32 data = readl_relaxed(addr);
7777
if (__is_be(vcpu)) {
7878
/* guest expects swabbed data */
79-
data = swab32(data);
79+
data = __kvm_swab32(data);
8080
}
8181
vcpu_set_reg(vcpu, rd, data);
8282
}

0 commit comments

Comments
 (0)