[PATCH] riscv/futex: sign extend compare value in atomic cmpxchg

Andreas Schwab schwab at suse.de
Mon Feb 3 07:44:52 PST 2025


On Feb 03 2025, Björn Töpel wrote:

> Andreas Schwab <schwab at suse.de> writes:
>
>> Make sure the compare value in the lr/sc loop is sign extended to match
>> what lr.w does.  Fortunately, due to the compiler keeping the register
>> contents sign extended anyway the lack of the explicit extension didn't
>> result in wrong code so far, but this cannot be relied upon.
>>
>> Fixes: b90edb33010b ("RISC-V: Add futex support.")
>> Signed-off-by: Andreas Schwab <schwab at suse.de>
>
> Hmm, in this scenario we *can* rely on it, no (inline vs macro)?

No, the issue is that the asm operand (oldval) is u32, but the asm is
using the 64-bit value from the register.  You cannot expect that the
compiler keeps the upper half defined in any way at this point.  That is
different for the operand that is passed in from newval, because sc.w is
only using the low 32-bits from the operand.

-- 
Andreas Schwab, SUSE Labs, schwab at suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



More information about the linux-riscv mailing list