public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Immunize rcu_dereference() against crazy compiler writers
@ 2007-07-12  1:00 Paul E. McKenney
  2007-07-12  1:03 ` [PATCH] Remove workaround for unimmunized rcu_dereference from mce_log() Paul E. McKenney
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Paul E. McKenney @ 2007-07-12  1:00 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, dipankar, josht, akpm

Turns out that compiler writers are a bit more aggressive about optimizing
than one might expect.  This patch prevents a number of such optimizations
from messing up rcu_deference().  This is not merely a theoretical
problem, as evidenced by the rmb() in mce_log().

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 rcupdate.h |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff -urpNa -X dontdiff linux-2.6.22/include/linux/rcupdate.h linux-2.6.22-volrcud/include/linux/rcupdate.h
--- linux-2.6.22/include/linux/rcupdate.h	2007-07-08 16:32:17.000000000 -0700
+++ linux-2.6.22-volrcud/include/linux/rcupdate.h	2007-07-11 17:21:09.000000000 -0700
@@ -217,6 +217,18 @@ extern int rcu_needs_cpu(int cpu);
 		local_bh_enable(); \
 	} while(0)
 
+/*
+ * Prevent the compiler from merging or refetching accesses.  The compiler
+ * is also forbidden from reordering successive instances of ACCESS_ONCE(),
+ * but only when the compiler is aware of some particular ordering.  One way
+ * to make the compiler aware of ordering is to put the two invocations of 
+ * ACCESS_ONCE() in different C statements.
+ *
+ * This macro does absolutely -nothing- to prevent the CPU from reordering,
+ * merging, or refetching absolutely anything at any time.
+ */
+#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
+
 /**
  * rcu_dereference - fetch an RCU-protected pointer in an
  * RCU read-side critical section.  This pointer may later
@@ -228,7 +240,7 @@ extern int rcu_needs_cpu(int cpu);
  */
 
 #define rcu_dereference(p)     ({ \
-				typeof(p) _________p1 = p; \
+				typeof(p) _________p1 = ACCESS_ONCE(p); \
 				smp_read_barrier_depends(); \
 				(_________p1); \
 				})

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

end of thread, other threads:[~2007-07-17 13:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-12  1:00 [PATCH] Immunize rcu_dereference() against crazy compiler writers Paul E. McKenney
2007-07-12  1:03 ` [PATCH] Remove workaround for unimmunized rcu_dereference from mce_log() Paul E. McKenney
2007-07-12 14:03 ` [PATCH] Immunize rcu_dereference() against crazy compiler writers Andi Kleen
2007-07-12 14:49   ` Paul E. McKenney
2007-07-12 16:08 ` Josh Triplett
2007-07-17  9:46 ` Andrew Morton
2007-07-17 13:53   ` Paul E. McKenney

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