From: tip-bot for Jianyu Zhan <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, nasa4836@gmail.com,
borntraeger@de.ibm.com, tglx@linutronix.de, hpa@zytor.com,
dvhart@linux.intel.com, mingo@kernel.org
Subject: [tip:locking/core] futex: Replace barrier() in unqueue_me() with READ_ONCE()
Date: Tue, 8 Mar 2016 08:09:39 -0800 [thread overview]
Message-ID: <tip-29b75eb2d56a714190a93d7be4525e617591077a@git.kernel.org> (raw)
In-Reply-To: <1457314344-5685-1-git-send-email-nasa4836@gmail.com>
Commit-ID: 29b75eb2d56a714190a93d7be4525e617591077a
Gitweb: http://git.kernel.org/tip/29b75eb2d56a714190a93d7be4525e617591077a
Author: Jianyu Zhan <nasa4836@gmail.com>
AuthorDate: Mon, 7 Mar 2016 09:32:24 +0800
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 8 Mar 2016 17:04:02 +0100
futex: Replace barrier() in unqueue_me() with READ_ONCE()
Commit e91467ecd1ef ("bug in futex unqueue_me") introduced a barrier() in
unqueue_me() to prevent the compiler from rereading the lock pointer which
might change after a check for NULL.
Replace the barrier() with a READ_ONCE() for the following reasons:
1) READ_ONCE() is a weaker form of barrier() that affects only the specific
load operation, while barrier() is a general compiler level memory barrier.
READ_ONCE() was not available at the time when the barrier was added.
2) Aside of that READ_ONCE() is descriptive and self explainatory while a
barrier without comment is not clear to the casual reader.
No functional change.
[ tglx: Massaged changelog ]
Signed-off-by: Jianyu Zhan <nasa4836@gmail.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Darren Hart <dvhart@linux.intel.com>
Cc: dave@stgolabs.net
Cc: peterz@infradead.org
Cc: linux@rasmusvillemoes.dk
Cc: akpm@linux-foundation.org
Cc: fengguang.wu@intel.com
Cc: bigeasy@linutronix.de
Link: http://lkml.kernel.org/r/1457314344-5685-1-git-send-email-nasa4836@gmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/futex.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index bae542e..a5d2e74 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2010,8 +2010,12 @@ static int unqueue_me(struct futex_q *q)
/* In the common case we don't take the spinlock, which is nice. */
retry:
- lock_ptr = q->lock_ptr;
- barrier();
+ /*
+ * q->lock_ptr can change between this read and the following spin_lock.
+ * Use READ_ONCE to forbid the compiler from reloading q->lock_ptr and
+ * optimizing lock_ptr out of the logic below.
+ */
+ lock_ptr = READ_ONCE(q->lock_ptr);
if (lock_ptr != NULL) {
spin_lock(lock_ptr);
/*
prev parent reply other threads:[~2016-03-08 16:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-03 15:38 [PATCH] futex: replace bare barrier() with more lightweight READ_ONCE() Jianyu Zhan
2016-03-03 17:05 ` Darren Hart
2016-03-04 1:12 ` Jianyu Zhan
2016-03-04 21:05 ` Darren Hart
2016-03-04 21:57 ` Paul E. McKenney
2016-03-04 22:38 ` Darren Hart
2016-03-04 22:45 ` Paul E. McKenney
2016-03-04 22:53 ` Darren Hart
2016-03-07 1:32 ` [PATCH v3] " Jianyu Zhan
2016-03-08 11:26 ` Darren Hart
2016-03-08 16:09 ` tip-bot for Jianyu Zhan [this message]
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=tip-29b75eb2d56a714190a93d7be4525e617591077a@git.kernel.org \
--to=tipbot@zytor.com \
--cc=borntraeger@de.ibm.com \
--cc=dvhart@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=nasa4836@gmail.com \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).