lkml.org 
[lkml]   [2013]   [Jul]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] mutex: Fix mutex_can_spin_on_owner
From
Date
On Fri, 2013-07-19 at 20:31 +0200, Peter Zijlstra wrote:
> 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>

Yep, I remember this from the rwsem optimistic spinning thread.

Acked-by: Davidlohr Bueso <davidlohr.bueso@hp.com>

> ---
> 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




\
 
 \ /
  Last update: 2013-07-19 20:41    [W:0.125 / U:0.204 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site