History

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.

Peter Zijlstra committed 10 years ago

Commit 920c7201 parent 39a11421 file · +7 −1Browse files

Showing the changes to kernel/locking (1 of 1 file). Show all

Unified · Split

kernel/locking/mcs_spinlock.h+7−1
@@ -67,7 +67,13 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) · 66 unmodified lines
6767 node->locked = 0;
6868 node->next = NULL;
6969
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);
7177 if (likely(prev == NULL)) {
7278 /*
7379 * Lock acquired, don't need to set node->locked to 1. Threads