]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv/futex: sign extend compare value in atomic cmpxchg
authorAndreas Schwab <schwab@suse.de>
Mon, 3 Feb 2025 10:06:00 +0000 (11:06 +0100)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 14 Feb 2025 21:06:31 +0000 (13:06 -0800)
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@suse.de>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/mvmfrkv2vhz.fsf@suse.de
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/futex.h

index 72be100afa236bedb7148247b792626a31b6c35b..90c86b115e008a1fb08f3da64382fb4a64d9cc2f 100644 (file)
@@ -93,7 +93,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
                _ASM_EXTABLE_UACCESS_ERR(1b, 3b, %[r])  \
                _ASM_EXTABLE_UACCESS_ERR(2b, 3b, %[r])  \
        : [r] "+r" (ret), [v] "=&r" (val), [u] "+m" (*uaddr), [t] "=&r" (tmp)
-       : [ov] "Jr" (oldval), [nv] "Jr" (newval)
+       : [ov] "Jr" ((long)(int)oldval), [nv] "Jr" (newval)
        : "memory");
        __disable_user_access();