]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv/atomic: Do proper sign extension also for unsigned in arch_cmpxchg
authorAndreas Schwab <schwab@suse.de>
Thu, 30 Jan 2025 09:25:38 +0000 (10:25 +0100)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 14 Feb 2025 21:06:23 +0000 (13:06 -0800)
Sign extend also an unsigned compare value to match what lr.w is doing.
Otherwise try_cmpxchg may spuriously return true when used on a u32 value
that has the sign bit set, as it happens often in inode_set_ctime_current.

Do this in three conversion steps.  The first conversion to long is needed
to avoid a -Wpointer-to-int-cast warning when arch_cmpxchg is used with a
pointer type.  Then convert to int and back to long to always sign extend
the 32-bit value to 64-bit.

Fixes: 6c58f25e6938 ("riscv/atomic: Fix sign extension for RV64I")
Signed-off-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Tested-by: Xi Ruoyao <xry111@xry111.site>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/mvmed0k4prh.fsf@suse.de
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/cmpxchg.h

index 4cadc56220feac3ef7207f678c8bac2585c36739..427c41dde64319c01e520d746cdc42005264f655 100644 (file)
                __arch_cmpxchg(".w", ".w" sc_sfx, ".w" cas_sfx,         \
                               sc_prepend, sc_append,                   \
                               cas_prepend, cas_append,                 \
-                              __ret, __ptr, (long), __old, __new);     \
+                              __ret, __ptr, (long)(int)(long), __old, __new);  \
                break;                                                  \
        case 8:                                                         \
                __arch_cmpxchg(".d", ".d" sc_sfx, ".d" cas_sfx,         \