aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/locking
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2016-02-01 09:11:28 -0500
committerIngo Molnar <mingo@kernel.org>2016-02-29 04:02:41 -0500
commit920c720aa5aa3900a7f1689228fdfc2580a91e7e (patch)
treede04ffb2172a814c84fbbb1fd906bb9c2b139ae5 /kernel/locking
parent39a1142dbba04d2e08259bd10a369465c932126b (diff)
locking/mcs: Fix mcs_spin_lock() ordering
Similar to commit b4b29f94856a ("locking/osq: Fix ordering of node initialisation in osq_lock") the use of xchg_acquire() is fundamentally broken with MCS like constructs. Furthermore, it turns out we rely on the global transitivity of this operation because the unlock path observes the pointer with a READ_ONCE(), not an smp_load_acquire(). This is non-critical because the MCS code isn't actually used and mostly serves as documentation, a stepping stone to the more complex things we've build on top of the idea. Reported-by: Andrea Parri <parri.andrea@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Fixes: 3552a07a9c4a ("locking/mcs: Use acquire/release semantics") Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/locking')
-rw-r--r--kernel/locking/mcs_spinlock.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
index 5b9102a47ea5..c835270f0c2f 100644
--- a/kernel/locking/mcs_spinlock.h
+++ b/kernel/locking/mcs_spinlock.h
@@ -67,7 +67,13 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
67 node->locked = 0; 67 node->locked = 0;
68 node->next = NULL; 68 node->next = NULL;
69 69
70 prev = xchg_acquire(lock, node); 70 /*
71 * We rely on the full barrier with global transitivity implied by the
72 * below xchg() to order the initialization stores above against any
73 * observation of @node. And to provide the ACQUIRE ordering associated
74 * with a LOCK primitive.
75 */
76 prev = xchg(lock, node);
71 if (likely(prev == NULL)) { 77 if (likely(prev == NULL)) {
72 /* 78 /*
73 * Lock acquired, don't need to set node->locked to 1. Threads 79 * Lock acquired, don't need to set node->locked to 1. Threads