Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Srinivas KANDAGATLA and committed by
Paul Mundt
5bdbd4fa 363e9f05

+12 -9
+12 -9
arch/sh/include/asm/cmpxchg-grb.h
··· 15 15 " mov.l %2, @%1 \n\t" /* store new value */ 16 16 "1: mov r1, r15 \n\t" /* LOGOUT */ 17 17 : "=&r" (retval), 18 - "+r" (m) 19 - : "r" (val) 18 + "+r" (m), 19 + "+r" (val) /* inhibit r15 overloading */ 20 + : 20 21 : "memory", "r0", "r1"); 21 22 22 23 return retval; ··· 37 36 " mov.b %2, @%1 \n\t" /* store new value */ 38 37 "1: mov r1, r15 \n\t" /* LOGOUT */ 39 38 : "=&r" (retval), 40 - "+r" (m) 41 - : "r" (val) 39 + "+r" (m), 40 + "+r" (val) /* inhibit r15 overloading */ 41 + : 42 42 : "memory" , "r0", "r1"); 43 43 44 44 return retval; ··· 56 54 " nop \n\t" 57 55 " mov r15, r1 \n\t" /* r1 = saved sp */ 58 56 " mov #-8, r15 \n\t" /* LOGIN */ 59 - " mov.l @%1, %0 \n\t" /* load old value */ 60 - " cmp/eq %0, %2 \n\t" 57 + " mov.l @%3, %0 \n\t" /* load old value */ 58 + " cmp/eq %0, %1 \n\t" 61 59 " bf 1f \n\t" /* if not equal */ 62 - " mov.l %3, @%1 \n\t" /* store new value */ 60 + " mov.l %2, @%3 \n\t" /* store new value */ 63 61 "1: mov r1, r15 \n\t" /* LOGOUT */ 64 - : "=&r" (retval) 65 - : "r" (m), "r" (old), "r" (new) 62 + : "=&r" (retval), 63 + "+r" (old), "+r" (new) /* old or new can be r15 */ 64 + : "r" (m) 66 65 : "memory" , "r0", "r1", "t"); 67 66 68 67 return retval;