Skip to content

Commit 5bdbd4f

Browse files
Srinivas-Kandagatlapmundt
authored andcommitted
sh: Fix up xchg/cmpxchg corruption with gUSA RB.
gUSA special cases r15 for part of its login/out sequence, meaning that any parameters need to be explicitly prohibited from accidentally being assigned that particular register, and the compiler ultimately needs to use a temporary instead. Certain configurations have begun generating code paths that do indeed get allocated r15, resulting in immediate corruption of the exchanged value. This was observed in (amongst others) exit_mm() code generation where the xchg_u32 call was immediately corrupting a structure address. As this is a general gUSA restriction, the rest of the users likewise need to be updated to ensure sensible constraints. References: https://bugzilla.stlinux.com/show_bug.cgi?id=11229 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Reviewed-by: Stuart Menefy <stuart.menefy@st.com> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 363e9f0 commit 5bdbd4f

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎arch/sh/include/asm/cmpxchg-grb.h‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
1515
" mov.l %2, @%1 \n\t" /* store new value */
1616
"1: mov r1, r15 \n\t" /* LOGOUT */
1717
: "=&r" (retval),
18-
"+r" (m)
19-
: "r" (val)
18+
"+r" (m),
19+
"+r" (val) /* inhibit r15 overloading */
20+
:
2021
: "memory", "r0", "r1");
2122

2223
return retval;
@@ -36,8 +37,9 @@ static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
3637
" mov.b %2, @%1 \n\t" /* store new value */
3738
"1: mov r1, r15 \n\t" /* LOGOUT */
3839
: "=&r" (retval),
39-
"+r" (m)
40-
: "r" (val)
40+
"+r" (m),
41+
"+r" (val) /* inhibit r15 overloading */
42+
:
4143
: "memory" , "r0", "r1");
4244

4345
return retval;
@@ -54,13 +56,14 @@ static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
5456
" nop \n\t"
5557
" mov r15, r1 \n\t" /* r1 = saved sp */
5658
" mov #-8, r15 \n\t" /* LOGIN */
57-
" mov.l @%1, %0 \n\t" /* load old value */
58-
" cmp/eq %0, %2 \n\t"
59+
" mov.l @%3, %0 \n\t" /* load old value */
60+
" cmp/eq %0, %1 \n\t"
5961
" bf 1f \n\t" /* if not equal */
60-
" mov.l %3, @%1 \n\t" /* store new value */
62+
" mov.l %2, @%3 \n\t" /* store new value */
6163
"1: mov r1, r15 \n\t" /* LOGOUT */
62-
: "=&r" (retval)
63-
: "r" (m), "r" (old), "r" (new)
64+
: "=&r" (retval),
65+
"+r" (old), "+r" (new) /* old or new can be r15 */
66+
: "r" (m)
6467
: "memory" , "r0", "r1", "t");
6568

6669
return retval;

0 commit comments

Comments
 (0)