From: tip-bot for Peter Zijlstra <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
davidlohr.bueso@hp.com, torvalds@linux-foundation.org,
peterz@infradead.org, paulmck@linux.vnet.ibm.com,
riel@redhat.com, dhowells@redhat.com, Waiman.Long@hp.com,
tglx@linutronix.de
Subject: [tip:core/locking] mutex: Fix/ document access-once assumption in mutex_can_spin_on_owner()
Date: Tue, 23 Jul 2013 00:46:20 -0700 [thread overview]
Message-ID: <tip-1e40c2edef2537f87f94d0baf80aeaeb7d51cc23@git.kernel.org> (raw)
In-Reply-To: <20130719183101.GA20909@twins.programming.kicks-ass.net>
Commit-ID: 1e40c2edef2537f87f94d0baf80aeaeb7d51cc23
Gitweb: http://git.kernel.org/tip/1e40c2edef2537f87f94d0baf80aeaeb7d51cc23
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Fri, 19 Jul 2013 20:31:01 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 22 Jul 2013 10:33:39 +0200
mutex: Fix/document access-once assumption in mutex_can_spin_on_owner()
mutex_can_spin_on_owner() is technically broken in that it would
in theory allow the compiler to load lock->owner twice, seeing a
pointer first time and a NULL pointer the second time.
Linus pointed out that a compiler has to be seriously broken to
not compile this correctly - but nevertheless this change
is correct as it will better document the implementation.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Acked-by: Waiman Long <Waiman.Long@hp.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Rik van Riel <riel@redhat.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: David Howells <dhowells@redhat.com>
Link: http://lkml.kernel.org/r/20130719183101.GA20909@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/mutex.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/mutex.c b/kernel/mutex.c
index ff05f4b..7ff48c5 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -209,11 +209,13 @@ int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
*/
static inline int mutex_can_spin_on_owner(struct mutex *lock)
{
+ struct task_struct *owner;
int retval = 1;
rcu_read_lock();
- if (lock->owner)
- retval = lock->owner->on_cpu;
+ owner = ACCESS_ONCE(lock->owner);
+ if (owner)
+ retval = owner->on_cpu;
rcu_read_unlock();
/*
* if lock->owner is not set, the mutex owner may have just acquired
prev parent reply other threads:[~2013-07-23 7:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-19 18:31 [PATCH] mutex: Fix mutex_can_spin_on_owner Peter Zijlstra
2013-07-19 18:36 ` Davidlohr Bueso
2013-07-19 19:08 ` Waiman Long
2013-07-19 19:41 ` Thomas Gleixner
2013-07-19 19:48 ` Linus Torvalds
2013-07-19 20:58 ` Waiman Long
2013-07-25 12:18 ` Jan-Simon Möller
2013-07-20 11:16 ` Peter Zijlstra
2013-07-19 19:36 ` Rik van Riel
2013-07-23 7:46 ` tip-bot for Peter Zijlstra [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-1e40c2edef2537f87f94d0baf80aeaeb7d51cc23@git.kernel.org \
--to=tipbot@zytor.com \
--cc=Waiman.Long@hp.com \
--cc=davidlohr.bueso@hp.com \
--cc=dhowells@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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).