Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM64: KVM: MMIO support BE host running LE code

In case of guest CPU running in LE mode and host runs in
BE mode we need byteswap data, so read/write is emulated correctly.

Signed-off-by: Victor Kamensky <victor.kamensky@linaro.org>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>

authored by

Victor Kamensky and committed by
Christoffer Dall
b3007086 f5aa4621

+22
+22
arch/arm64/include/asm/kvm_emulate.h
··· 213 213 default: 214 214 return be64_to_cpu(data); 215 215 } 216 + } else { 217 + switch (len) { 218 + case 1: 219 + return data & 0xff; 220 + case 2: 221 + return le16_to_cpu(data & 0xffff); 222 + case 4: 223 + return le32_to_cpu(data & 0xffffffff); 224 + default: 225 + return le64_to_cpu(data); 226 + } 216 227 } 217 228 218 229 return data; /* Leave LE untouched */ ··· 243 232 return cpu_to_be32(data & 0xffffffff); 244 233 default: 245 234 return cpu_to_be64(data); 235 + } 236 + } else { 237 + switch (len) { 238 + case 1: 239 + return data & 0xff; 240 + case 2: 241 + return cpu_to_le16(data & 0xffff); 242 + case 4: 243 + return cpu_to_le32(data & 0xffffffff); 244 + default: 245 + return cpu_to_le64(data); 246 246 } 247 247 } 248 248