All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mutex: Fix mutex_can_spin_on_owner
@ 2013-07-19 18:31 Peter Zijlstra
  2013-07-19 18:36 ` Davidlohr Bueso
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Peter Zijlstra @ 2013-07-19 18:31 UTC (permalink / raw)
  To: Waiman Long
  Cc: Davidlohr Bueso, Rik van Riel, Linus Torvalds, Andrew Morton,
	Thomas Gleixner, Paul E. McKenney, David Howells, Ingo Molnar,
	linux-kernel


mutex_can_spin_on_owner() is broken in that it would allow the compiler
to load lock->owner twice, seeing a pointer first time and a MULL
pointer the second time.

Signed-off-by: Peter Zijlstra <peterz@infradead.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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-07-25 12:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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:core/locking] mutex: Fix/ document access-once assumption in mutex_can_spin_on_owner() tip-bot for Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.