From: Peter Zijlstra <peterz@infradead.org>
To: Will Deacon <will.deacon@arm.com>,
Paul McKenney <paulmck@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
Ingo Molnar <mingo@kernel.org>,
parri.andrea@gmail.com
Subject: [RFC][PATCH] locking/mcs: Fix ordering for mcs_spin_lock()
Date: Mon, 1 Feb 2016 15:37:24 +0100 [thread overview]
Message-ID: <20160201143724.GW6357@twins.programming.kicks-ass.net> (raw)
Given the below patch; we've now got an unconditional full global
barrier in, does this make the MCS spinlock RCsc ?
The 'problem' is that this barrier can happen before we actually acquire
the lock. That is, if we hit arch_mcs_spin_lock_contended() _that_ will
be the acquire barrier and we end up with a SYNC in between unlock and
lock -- ie. not an smp_mb__after_unlock_lock() equivalent.
---
Subject: locking/mcs: Fix ordering for mcs_spin_lock()
From: Peter Zijlstra <peterz@infradead.org>
Date: Mon Feb 1 15:11:28 CET 2016
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.
Cc: Will Deacon <will.deacon@arm.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Reported-by: Andrea Parri <parri.andrea@gmail.com>
Fixes: 3552a07a9c4a ("locking/mcs: Use acquire/release semantics")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/locking/mcs_spinlock.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--- a/kernel/locking/mcs_spinlock.h
+++ b/kernel/locking/mcs_spinlock.h
@@ -67,7 +67,13 @@ void mcs_spin_lock(struct mcs_spinlock *
node->locked = 0;
node->next = NULL;
- prev = xchg_acquire(lock, node);
+ /*
+ * We rely on the full barrier with global transitivity implied by the
+ * below xchg() to order the initialization stores above against any
+ * observation of @node. And to provide the ACQUIRE ordering associated
+ * with a LOCK primitive.
+ */
+ prev = xchg(lock, node);
if (likely(prev == NULL)) {
/*
* Lock acquired, don't need to set node->locked to 1. Threads
next reply other threads:[~2016-02-01 14:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-01 14:37 Peter Zijlstra [this message]
2016-02-01 16:58 ` [RFC][PATCH] locking/mcs: Fix ordering for mcs_spin_lock() Will Deacon
2016-02-01 17:24 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160201143724.GW6357@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dave@stgolabs.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=parri.andrea@gmail.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox