From da8a5909fed9bb801b7d9b175330f4e205b9dd61 Mon Sep 17 00:00:00 2001 From: Srinivas Kandagatla Date: Thu, 7 Apr 2011 13:34:43 +0100 Subject: [PATCH sh-2.6.32.y] sh: fixed issue in xchg_u32 function. This patch addresses a use case where input parameter (val) to xchg_u32 inline asm function is equal to r15. If val == r15 then xchg_u32 always sets m to -4(0xfffffffc). In particular code in kernel/exit.c exit_mm() will hit this bug. This patch makes adds val to input/output constraint so that compiler cannot pass r15 directly and must use a temporary register instead. Without this patch a SEGFAULT in multithreaded program will crash the kernel. Originally this bug was discovered as part of stlinux bugzilla##11229 triage. Signed-off-by: Srinivas Kandagatla Reviewed-by: Stuart Menefy --- arch/sh/include/asm/cmpxchg-grb.h | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/sh/include/asm/cmpxchg-grb.h b/arch/sh/include/asm/cmpxchg-grb.h index 4676bf5..fc3deb6 100644 --- a/arch/sh/include/asm/cmpxchg-grb.h +++ b/arch/sh/include/asm/cmpxchg-grb.h @@ -15,8 +15,10 @@ static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val) " mov.l %2, @%1 \n\t" /* store new value */ "1: mov r1, r15 \n\t" /* LOGOUT */ : "=&r" (retval), - "+r" (m) - : "r" (val) + "+r" (m), + "+r" (val) /* when val == r15 this function will not work as expected. + * So val is added to output constriants */ + : : "memory", "r0", "r1"); return retval; -- 1.6.3.3