[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ac53a62e-4f89-49c9-a755-fdfa7a582337@ghiti.fr>
Date: Thu, 30 Jan 2025 16:23:00 +0100
From: Alexandre Ghiti <alex@...ti.fr>
To: Andreas Schwab <schwab@...e.de>
Cc: linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] riscv/atomic: Do proper sign extension also for unsigned
in arch_cmpxchg
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?
Powered by blists - more mailing lists