Commit 6c58f25e authored by Nathan Huckleberry's avatar Nathan Huckleberry Committed by Palmer Dabbelt

riscv/atomic: Fix sign extension for RV64I

The argument passed to cmpxchg is not guaranteed to be sign
extended, but lr.w sign extends on RV64I. This makes cmpxchg
fail on clang built kernels when __old is negative.

To fix this, we just cast __old to long which sign extends on
RV64I. With this fix, clang built RISC-V kernels now boot.

Link: https://github.com/ClangBuiltLinux/linux/issues/867Signed-off-by: default avatarNathan Huckleberry <nhuck@google.com>
Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
parent cd16ed33
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
" bnez %1, 0b\n" \ " bnez %1, 0b\n" \
"1:\n" \ "1:\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
: "rJ" (__old), "rJ" (__new) \ : "rJ" ((long)__old), "rJ" (__new) \
: "memory"); \ : "memory"); \
break; \ break; \
case 8: \ case 8: \
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
RISCV_ACQUIRE_BARRIER \ RISCV_ACQUIRE_BARRIER \
"1:\n" \ "1:\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
: "rJ" (__old), "rJ" (__new) \ : "rJ" ((long)__old), "rJ" (__new) \
: "memory"); \ : "memory"); \
break; \ break; \
case 8: \ case 8: \
...@@ -270,7 +270,7 @@ ...@@ -270,7 +270,7 @@
" bnez %1, 0b\n" \ " bnez %1, 0b\n" \
"1:\n" \ "1:\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
: "rJ" (__old), "rJ" (__new) \ : "rJ" ((long)__old), "rJ" (__new) \
: "memory"); \ : "memory"); \
break; \ break; \
case 8: \ case 8: \
...@@ -316,7 +316,7 @@ ...@@ -316,7 +316,7 @@
" fence rw, rw\n" \ " fence rw, rw\n" \
"1:\n" \ "1:\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
: "rJ" (__old), "rJ" (__new) \ : "rJ" ((long)__old), "rJ" (__new) \
: "memory"); \ : "memory"); \
break; \ break; \
case 8: \ case 8: \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment