aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zijlstra <[email protected]>2013-07-19 20:31:01 +0200
committerIngo Molnar <[email protected]>2013-07-22 10:33:39 +0200
commit1e40c2edef2537f87f94d0baf80aeaeb7d51cc23 (patch)
tree3692ad447e3242ab2042edfd09d24107d5166652
parentc4be9cb4f19cbd534a6c4c334cd48d8bb483e17a (diff)
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 <[email protected]> Acked-by: Davidlohr Bueso <[email protected]> Acked-by: Waiman Long <[email protected]> Acked-by: Linus Torvalds <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Acked-by: Rik van Riel <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: David Howells <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
-rw-r--r--kernel/mutex.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/kernel/mutex.c b/kernel/mutex.c
index ff05f4bd86eb..7ff48c55a98b 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