[PATCH v2] arm64: vgic-v2: Fix proxying of cpuif access

Marc Zyngier marc.zyngier at arm.com
Fri May 4 08:43:27 PDT 2018


On 04/05/18 16:19, James Morse wrote:
> 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.

<song>
The Thing That Should Not Be
</song>

> Based on a patch from Marc Zyngier.
> 
> Reported-by: Suzuki K Poulose <suzuki.poulose at arm.com>
> Fixes: bf8feb39642b ("arm64: KVM: vgic-v2: Add GICV access from HYP")
> CC: Marc Zyngier <marc.zyngier at arm.com>
> Signed-off-by: James Morse <james.morse at arm.com>

Awesome, thanks a lot for picking this up and fixing it the right way!

I'll queue it right away.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...



More information about the linux-arm-kernel mailing list