All of lore.kernel.org
 help / color / mirror / Atom feed
* linux-user/armeb: Fix __kernel_cmpxchg() for armeb
@ 2023-07-27 21:19 Helge Deller
  2023-07-28  0:12 ` Richard Henderson
  2023-07-31  9:26 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 4+ messages in thread
From: Helge Deller @ 2023-07-27 21:19 UTC (permalink / raw)
  To: Richard Henderson, Laurent Vivier, qemu-devel, Peter Maydell
  Cc: John Reiser, Markus F.X.J. Oberhumer

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.

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-stable@nongnu.org
Reported-by: "Markus F.X.J. Oberhumer" <markus@oberhumer.com>
Reported-by: John Reiser <jreiser@BitWagon.com>
Closes: https://github.com/upx/upx/issues/687

diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index a992423257..ff0bff7c63 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -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();


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: linux-user/armeb: Fix __kernel_cmpxchg() for armeb
  2023-07-27 21:19 linux-user/armeb: Fix __kernel_cmpxchg() for armeb Helge Deller
@ 2023-07-28  0:12 ` Richard Henderson
  2023-07-31  9:26 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2023-07-28  0:12 UTC (permalink / raw)
  To: Helge Deller, Laurent Vivier, qemu-devel, Peter Maydell
  Cc: John Reiser, Markus F.X.J. Oberhumer

On 7/27/23 14:19, Helge Deller wrote:
> 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.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: qemu-stable@nongnu.org
> Reported-by: "Markus F.X.J. Oberhumer" <markus@oberhumer.com>
> Reported-by: John Reiser <jreiser@BitWagon.com>
> Closes: https://github.com/upx/upx/issues/687
> 
> diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
> index a992423257..ff0bff7c63 100644
> --- a/linux-user/arm/cpu_loop.c
> +++ b/linux-user/arm/cpu_loop.c
> @@ -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

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

as far as this goes.


r~



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: linux-user/armeb: Fix __kernel_cmpxchg() for armeb
  2023-07-27 21:19 linux-user/armeb: Fix __kernel_cmpxchg() for armeb Helge Deller
  2023-07-28  0:12 ` Richard Henderson
@ 2023-07-31  9:26 ` Philippe Mathieu-Daudé
  2023-07-31  9:29   ` Michael Tokarev
  1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-07-31  9:26 UTC (permalink / raw)
  To: Helge Deller, Richard Henderson, Laurent Vivier, qemu-devel,
	Peter Maydell
  Cc: John Reiser, Markus F.X.J. Oberhumer

On 27/7/23 23:19, Helge Deller wrote:
> 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.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: qemu-stable@nongnu.org
> Reported-by: "Markus F.X.J. Oberhumer" <markus@oberhumer.com>
> Reported-by: John Reiser <jreiser@BitWagon.com>
> Closes: https://github.com/upx/upx/issues/687

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: linux-user/armeb: Fix __kernel_cmpxchg() for armeb
  2023-07-31  9:26 ` Philippe Mathieu-Daudé
@ 2023-07-31  9:29   ` Michael Tokarev
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Tokarev @ 2023-07-31  9:29 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé,
	Helge Deller, Richard Henderson, Laurent Vivier, qemu-devel,
	Peter Maydell
  Cc: John Reiser, Markus F.X.J. Oberhumer

31.07.2023 12:26, Philippe Mathieu-Daudé wrote:
> On 27/7/23 23:19, Helge Deller wrote:
>> Words are stored in big endian in the guest memory for armeb.
..
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

There was a v3 of this patch already, fwiw.

/mjt


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-31  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 21:19 linux-user/armeb: Fix __kernel_cmpxchg() for armeb Helge Deller
2023-07-28  0:12 ` Richard Henderson
2023-07-31  9:26 ` Philippe Mathieu-Daudé
2023-07-31  9:29   ` Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.