aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Ellerman <mpe@ellerman.id.au>2015-01-07 23:30:08 -0500
committerMichael Ellerman <mpe@ellerman.id.au>2015-01-12 00:40:02 -0500
commita87e810f61b49f19bd29ea564b7cd1e92e43d989 (patch)
treef6ff82304f0c2b8d2c1e91ba39096f72559d4dfe
parent0712dc7e73e59d79bcead5d5520acf4e9e917e87 (diff)
powerpc: Work around gcc bug in current_thread_info()
In commit a3e5b356b3ab "powerpc: Don't use local named register variable in current_thread_info" Anton changed the way we did current_thread_info() to accommodate LLVM, and it was not meant to have any effect elsewhere. Unfortunately it has exposed a gcc bug, where r1 gets copied into another register and then gcc uses that register to restore the toc after a function call, even when that register is volatile and has been clobbered by the function call. We could revert Anton's patch, but it's not clear the original code is safe either, we may just have been lucky. The cleanest solution is to just use the existing CURRENT_THREAD_INFO() asm macro, and call it using inline asm. Segher points out we don't need volatile on the asm, if the result of the shift is unused it's fine for the compiler to elide it. Fixes: a3e5b356b3ab ("powerpc: Don't use local named register variable in current_thread_info") Reported-by: Alexander Graf <agraf@suse.de> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--arch/powerpc/include/asm/thread_info.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index ebc4f165690a..0be6c681cab1 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -23,9 +23,9 @@
23#define THREAD_SIZE (1 << THREAD_SHIFT) 23#define THREAD_SIZE (1 << THREAD_SHIFT)
24 24
25#ifdef CONFIG_PPC64 25#ifdef CONFIG_PPC64
26#define CURRENT_THREAD_INFO(dest, sp) clrrdi dest, sp, THREAD_SHIFT 26#define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(clrrdi dest, sp, THREAD_SHIFT)
27#else 27#else
28#define CURRENT_THREAD_INFO(dest, sp) rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT 28#define CURRENT_THREAD_INFO(dest, sp) stringify_in_c(rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT)
29#endif 29#endif
30 30
31#ifndef __ASSEMBLY__ 31#ifndef __ASSEMBLY__
@@ -71,12 +71,13 @@ struct thread_info {
71#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT) 71#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
72 72
73/* how to get the thread information struct from C */ 73/* how to get the thread information struct from C */
74register unsigned long __current_r1 asm("r1");
75static inline struct thread_info *current_thread_info(void) 74static inline struct thread_info *current_thread_info(void)
76{ 75{
77 /* gcc4, at least, is smart enough to turn this into a single 76 unsigned long val;
78 * rlwinm for ppc32 and clrrdi for ppc64 */ 77
79 return (struct thread_info *)(__current_r1 & ~(THREAD_SIZE-1)); 78 asm (CURRENT_THREAD_INFO(%0,1) : "=r" (val));
79
80 return (struct thread_info *)val;
80} 81}
81 82
82#endif /* __ASSEMBLY__ */ 83#endif /* __ASSEMBLY__ */