lkml.org 
[lkml]   [2016]   [Aug]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH -v2 4/4] locking/mutex: Add lock handoff to avoid starvation
On 08/25/2016 02:37 PM, Peter Zijlstra wrote:
> @@ -468,9 +496,12 @@ void __sched mutex_unlock(struct mutex *
> DEBUG_LOCKS_WARN_ON(__mutex_owner(lock) != current);
> #endif
>
> - owner = atomic_long_fetch_and(MUTEX_FLAGS,&lock->owner);
> + owner = atomic_long_read(&lock->owner);
> + if (!(owner& MUTEX_FLAG_HANDOFF))
> + owner = atomic_long_fetch_and(MUTEX_FLAGS,&lock->owner);
> +
> if (__owner_flags(owner))
> - __mutex_unlock_slowpath(lock);
> + __mutex_unlock_slowpath(lock, owner);
> }
> EXPORT_SYMBOL(mutex_unlock);

I don't think the race condition is fixed when we don't make sure that
lock handoff only happens from current=>new. The problem is due to the
fact that the MUTEX_FLAG_HANDOFF check in the unlock fastpath isn't
serialized by the wait_lock. As a result, it is possible that the owner
is NULL while the HANDOFF bit is set. Or an optimistic spinner may have
stolen the lock in the interim.

Cheers,
Longman

\
 
 \ /
  Last update: 2016-09-17 09:57    [W:0.485 / U:0.400 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site