Skip to content

Commit 509eb76

Browse files
wildea01Russell King
authored andcommitted
ARM: 7747/1: pcpu: ensure __my_cpu_offset cannot be re-ordered across barrier()
__my_cpu_offset is non-volatile, since we want its value to be cached when we access several per-cpu variables in a row with preemption disabled. This means that we rely on preempt_{en,dis}able to hazard with the operation via the barrier() macro, so that we can't end up migrating CPUs without reloading the per-cpu offset. Unfortunately, GCC doesn't treat a "memory" clobber on a non-volatile asm block as a side-effect, and will happily re-order it before other memory clobbers (including those in prempt_disable()) and cache the value. This has been observed to break the cmpxchg logic in the slub allocator, leading to livelock in kmem_cache_alloc in mainline kernels. This patch adds a dummy memory input operand to __my_cpu_offset, forcing it to be ordered with respect to the barrier() macro. Cc: <[email protected]> Cc: Rob Herring <[email protected]> Reviewed-by: Nicolas Pitre <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent ced2a3b commit 509eb76

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arch/arm/include/asm/percpu.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ static inline void set_my_cpu_offset(unsigned long off)
3030
static inline unsigned long __my_cpu_offset(void)
3131
{
3232
unsigned long off;
33-
/* Read TPIDRPRW */
34-
asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off) : : "memory");
33+
register unsigned long *sp asm ("sp");
34+
35+
/*
36+
* Read TPIDRPRW.
37+
* We want to allow caching the value, so avoid using volatile and
38+
* instead use a fake stack read to hazard against barrier().
39+
*/
40+
asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off) : "Q" (*sp));
41+
3542
return off;
3643
}
3744
#define __my_cpu_offset __my_cpu_offset()

0 commit comments

Comments
 (0)