aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/rcupdate.h
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2013-12-16 16:24:32 -0500
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2014-02-17 18:02:00 -0500
commit88c1863066ccfa456797e12c5d8b4631aa1ad0d0 (patch)
tree4f456425e3af718957113bd9c4b019b10c496061 /include/linux/rcupdate.h
parent0adab9b9aa18d7e90337d43567f1eec3d5401b81 (diff)
rcu: Define rcu_assign_pointer() in terms of smp_store_release()
The new smp_store_release() function provides better guarantees than did rcu_assign_pointer(), and potentially less overhead on some architectures. The guarantee that smp_store_release() provides that rcu_assign_pointer() does that is obscure, but its lack could cause considerable confusion. This guarantee is illustrated by the following code fragment: struct foo { int a; int b; int c; struct foo *next; }; struct foo foo1; struct foo foo2; struct foo __rcu *foop; ... foo2.a = 1; foo2.b = 2; BUG_ON(foo2.c); rcu_assign_pointer(foop, &foo); ... fp = rcu_dereference(foop); fp.c = 3; The current rcu_assign_pointer() semantics permit the BUG_ON() to trigger because rcu_assign_pointer()'s smp_wmb() is not guaranteed to order prior reads against later writes. This commit therefore upgrades rcu_assign_pointer() from smp_wmb() to smp_store_release() to avoid this counter-intuitive outcome. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Diffstat (limited to 'include/linux/rcupdate.h')
-rw-r--r--include/linux/rcupdate.h8
1 files changed, 2 insertions, 6 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 278a9da69ec4..32decf1a9c6c 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -44,6 +44,7 @@
44#include <linux/debugobjects.h> 44#include <linux/debugobjects.h>
45#include <linux/bug.h> 45#include <linux/bug.h>
46#include <linux/compiler.h> 46#include <linux/compiler.h>
47#include <asm/barrier.h>
47 48
48#ifdef CONFIG_RCU_TORTURE_TEST 49#ifdef CONFIG_RCU_TORTURE_TEST
49extern int rcutorture_runnable; /* for sysctl */ 50extern int rcutorture_runnable; /* for sysctl */
@@ -580,12 +581,7 @@ static inline void rcu_preempt_sleep_check(void)
580 * please be careful when making changes to rcu_assign_pointer() and the 581 * please be careful when making changes to rcu_assign_pointer() and the
581 * other macros that it invokes. 582 * other macros that it invokes.
582 */ 583 */
583#define rcu_assign_pointer(p, v) \ 584#define rcu_assign_pointer(p, v) smp_store_release(&p, RCU_INITIALIZER(v))
584 do { \
585 smp_wmb(); \
586 ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
587 } while (0)
588
589 585
590/** 586/**
591 * rcu_access_pointer() - fetch RCU pointer with no dereferencing 587 * rcu_access_pointer() - fetch RCU pointer with no dereferencing