linux-user/armeb: Fix __kernel_cmpxchg() for armeb
Words are stored in big endian in the guest memory for armeb.
Commit 7f4f0d9ea870 ("linux-user/arm: Implement __kernel_cmpxchg with host atomics") switched to use qatomic_cmpxchg() to swap a word with the memory content, but missed to endianess-swap the oldval and newval values when emulating an armeb CPU.
The bug can be verified with qemu >= v7.2 on any little-endian host, when starting the armeb binary of the upx program, which just hangs without this patch.
linux-user/arm/cpu_loop.c +2 -2
@@ -117,8 +117,8 @@ static void arm_kernel_cmpxchg32_helper(CPUARMState *env) {uint32_t oldval, newval, val, addr, cpsr, *host_addr; - oldval = env->regs[0 ]; - newval = env->regs[1 ]; + oldval =tswap32 (env->regs[0 ]); + newval =tswap32 (env->regs[1 ]); addr = env->regs[2 ];mmap_lock ();
Richard Henderson
Reviewed-byQuoted 24 lines · Helge Deller
Words are stored in big endian in the guest memory for armeb.
Commit
7f4f0d9ea870("linux-user/arm: Implement__kernel_cmpxchgwith host atomics") switched to useqatomic_cmpxchg()to swap a word with the memory content, but missed to endianess-swap the oldval and newval values when emulating an armeb CPU.The bug can be verified with qemu >= v7.2 on any little-endian host, when starting the armeb binary of the upx program, which just hangs without this patch.
Signed-off-by Helge Deller <[email protected]>Cc Richard Henderson <[email protected]>Cc Peter Maydell <[email protected]>Reported-by "Markus F.X.J. Oberhumer" <[email protected]>Reported-by John Reiser <[email protected]>linux-user/arm/cpu_loop.c +0
-0
linux-user/arm/cpu_loop.c static void arm_kernel_cmpxchg32_helper(CPUARMState *env) · line 122
Quoted 8 lines
linux-user/arm/cpu_loop.c +2
-2@@ -117,8 +117,8 @@ static void arm_kernel_cmpxchg32_helper(CPUARMState *env) {uint32_t oldval, newval, val, addr, cpsr, *host_addr; - oldval = env->regs[0 ]; - newval = env->regs[1 ]; + oldval =tswap32 (env->regs[0 ]); + newval =tswap32 (env->regs[1 ]); addr = env->regs[2 ];
There's a similar bug with arm_kernel_cmpxchg64_helper just below, but
as far as this goes.
r~
Philippe Mathieu-Daudé
Reviewed-byQuoted 11 lines · Helge Deller
Words are stored in big endian in the guest memory for armeb.
Commit
7f4f0d9ea870("linux-user/arm: Implement__kernel_cmpxchgwith host atomics") switched to useqatomic_cmpxchg()to swap a word with the memory content, but missed to endianess-swap the oldval and newval values when emulating an armeb CPU.The bug can be verified with qemu >= v7.2 on any little-endian host, when starting the armeb binary of the upx program, which just hangs without this patch.
Quoted 7 lines
Signed-off-by Helge Deller <[email protected]>Cc Richard Henderson <[email protected]>Cc Peter Maydell <[email protected]>Reported-by "Markus F.X.J. Oberhumer" <[email protected]>Reported-by John Reiser <[email protected]>
Quoted 2 lines · Philippe Mathieu-Daudé
Quoted 1 line · Helge Deller
Words are stored in big endian in the guest memory for armeb.
..
Quoted 1 line
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
There was a v3 of this patch already, fwiw.
/mjt