linux/arch/arm64/kvm/hyp
James Morse b220244d41 arm64: vgic-v2: Fix proxying of cpuif access
Proxying the cpuif accesses at EL2 makes use of vcpu_data_guest_to_host
and co, which check the endianness, which call into vcpu_read_sys_reg...
which isn't mapped at EL2 (it was inlined before, and got moved OoL
with the VHE optimizations).

The result is of course a nice panic. Let's add some specialized
cruft to keep the broken platforms that require this hack alive.

But, this code used vcpu_data_guest_to_host(), which expected us to
write the value to host memory, instead we have trapped the guest's
read or write to an mmio-device, and are about to replay it using the
host's readl()/writel() which also perform swabbing based on the host
endianness. This goes wrong when both host and guest are big-endian,
as readl()/writel() will undo the guest's swabbing, causing the
big-endian value to be written to device-memory.

What needs doing?
A big-endian guest will have pre-swabbed data before storing, undo this.
If its necessary for the host, writel() will re-swab it.

For a read a big-endian guest expects to swab the data after the load.
The hosts's readl() will correct for host endianness, giving us the
device-memory's value in the register. For a big-endian guest, swab it
as if we'd only done the load.

For a little-endian guest, nothing needs doing as readl()/writel() leave
the correct device-memory value in registers.

Tested on Juno with that rarest of things: a big-endian 64K host.
Based on a patch from Marc Zyngier.

Reported-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Fixes: bf8feb3964 ("arm64: KVM: vgic-v2: Add GICV access from HYP")
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
2018-05-04 16:45:55 +01:00
..
Makefile KVM: arm/arm64: Move arm64-only vgic-v2-sr.c file to arm64 2018-03-19 10:53:20 +00:00
debug-sr.c KVM: arm64: Improve debug register save/restore flow 2018-03-19 10:53:12 +00:00
entry.S arm64: KVM: Use SMCCC_ARCH_WORKAROUND_1 for Falkor BP hardening 2018-04-11 18:49:30 +01:00
fpsimd.S arm64: KVM: Implement fpsimd save/restore 2015-12-14 11:30:41 +00:00
hyp-entry.S arm64: Move the content of bpi.S to hyp-entry.S 2018-04-11 18:49:30 +01:00
s2-setup.c KVM: arm64: Stop save/restoring host tpidr_el1 on VHE 2018-01-13 10:44:40 +00:00
switch.c arm64: KVM: Use SMCCC_ARCH_WORKAROUND_1 for Falkor BP hardening 2018-04-11 18:49:30 +01:00
sysreg-sr.c KVM: arm64: Configure c15, PMU, and debug register traps on cpu load/put for VHE 2018-03-19 10:53:19 +00:00
tlb.c KVM: arm/arm64: Detangle kvm_mmu.h from kvm_hyp.h 2018-01-08 15:20:43 +01:00
vgic-v2-cpuif-proxy.c arm64: vgic-v2: Fix proxying of cpuif access 2018-05-04 16:45:55 +01:00