public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] percpu: make this_cpu_generic_read() atomic w.r.t. interrupts
@ 2017-09-25 13:24 Mark Rutland
  2017-09-25 15:18 ` Tejun Heo
  0 siblings, 1 reply; 10+ messages in thread
From: Mark Rutland @ 2017-09-25 13:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mark Rutland, Arnd Bergmann, Christoph Lameter, Peter Zijlstra,
	Pranith Kumar, Tejun Heo, linux-arch

As raw_cpu_generic_read() is a plain read from a raw_cpu_ptr() address,
it's possible (albeit unlikely) that the compiler will split the access
across multiple instructions.

In this_cpu_generic_read() we disable preemption but not interrupts
before calling raw_cpu_generic_read(). Thus, an interrupt could be taken
in the middle of the split load instructions. If a this_cpu_write() or
RMW this_cpu_*() op is made to the same variable in the interrupt
handling path, this_cpu_read() will return a torn value.

Avoid this by using READ_ONCE() to inhibit tearing.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Pranith Kumar <bobby.prani@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: linux-arch@vger.kernel.org
---
 include/asm-generic/percpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h
index 0504ef8..79a8a58 100644
--- a/include/asm-generic/percpu.h
+++ b/include/asm-generic/percpu.h
@@ -67,7 +67,7 @@
 
 #define raw_cpu_generic_read(pcp)					\
 ({									\
-	*raw_cpu_ptr(&(pcp));						\
+	READ_ONCE(*raw_cpu_ptr(&(pcp)));				\
 })
 
 #define raw_cpu_generic_to_op(pcp, val, op)				\
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-09-27 10:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-25 13:24 [PATCH] percpu: make this_cpu_generic_read() atomic w.r.t. interrupts Mark Rutland
2017-09-25 15:18 ` Tejun Heo
2017-09-25 15:33   ` Mark Rutland
2017-09-25 15:44     ` Tejun Heo
2017-09-26  6:47       ` Christopher Lameter
2017-09-26  7:47         ` Thomas Gleixner
2017-09-26 16:42           ` Christopher Lameter
2017-09-27  9:01             ` Thomas Gleixner
2017-09-27 10:10               ` Mark Rutland
2017-09-26 17:28         ` Mark Rutland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox