Re: [PATCH] riscv/atomic: Do proper sign extension also for unsigned in arch_cmpxchg
From: Alexandre Ghiti
Date: Thu Jan 30 2025 - 10:23:11 EST
On 30/01/2025 15:52, Andreas Schwab wrote:
On Jan 30 2025, Alexandre Ghiti wrote:
That's a nice catch indeed. IIUC, we have the same issue here
https://elixir.bootlin.com/linux/v6.13/source/arch/riscv/include/asm/futex.h#L89
right?
Indeed, though it doesn't result in wrong code currently. This is
because the compare value is passed unmodified as u32 to the asm and the
compiler keeps the value sign extended in registers. That would break
if you would add a cast to long like in commit 6c58f25e6938 as that
would erroneously zero extend it.
This is the disassembly I get:
ffffffff800fc540 <futex_atomic_cmpxchg_inatomic>:
...
ffffffff800fc566: 1605a8af lr.w.aqrl a7,(a1)
ffffffff800fc56a: 00c89563 bne
a7,a2,ffffffff800fc574 <futex_atomic_cmpxchg_inatomic+0x3
4>
ffffffff800fc56e: 1ed5a52f sc.w.aqrl a0,a3,(a1)
a2 is used as it is passed by the calling function, so we can't be sure
a2 is sign extended to me, what am I missing?