rcu: No ordering for rcu_assign_pointer() of NULL
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Mon, 2 May 2016 01:46:54 +0000 (18:46 -0700)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Wed, 15 Jun 2016 22:31:28 +0000 (15:31 -0700)
This commit does a compile-time check for rcu_assign_pointer() of NULL,
and uses WRITE_ONCE() rather than smp_store_release() in that case.

Reported-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
include/linux/rcupdate.h

index c61b6b9506e7ee9666eb9e48c5e669293e869e0f..a8af79738a0e7910966b19b37e3becd69f960156 100644 (file)
@@ -650,7 +650,16 @@ static inline void rcu_preempt_sleep_check(void)
  * please be careful when making changes to rcu_assign_pointer() and the
  * other macros that it invokes.
  */
-#define rcu_assign_pointer(p, v) smp_store_release(&p, RCU_INITIALIZER(v))
+#define rcu_assign_pointer(p, v)                                             \
+({                                                                           \
+       uintptr_t _r_a_p__v = (uintptr_t)(v);                                 \
+                                                                             \
+       if (__builtin_constant_p(v) && (_r_a_p__v) == (uintptr_t)NULL)        \
+               WRITE_ONCE((p), (typeof(p))(_r_a_p__v));                      \
+       else                                                                  \
+               smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
+       _r_a_p__v;                                                            \
+})
 
 /**
  * rcu_access_pointer() - fetch RCU pointer with no dereferencing
This page took 0.036896 seconds and 5 git commands to generate.