Subject: Re: [PATCH RFC] spinlock: split out debugging check from spin_lock_mutex

From: Bart Van Assche <[email-masked]>
Date: Fri, 12 Apr 2013 08:27:31 +0200

On 04/11/13 21:14, Neil Horman wrote:
>      This resulted from my commit ca99ca14c which introduced a mutex_trylock
>      operation in a path that could execute in interrupt context.  When mutex
>      debugging is enabled, the above warns the user when we are in fact exectuting in
>      interrupt context.
>
>      I think this is a false positive however.  The check is intended to catch users
>      who might be issuing sleeping calls in irq context, but the use of mutex_trylock
>      here is guaranteed not to sleep.
>
>      We could fix this by replacing the DEBUG_LOCK_WARN_ON check in spin_lock_mutex
>      with a __might_sleep call in the appropriate parent mutex operations, but for
>      the sake of effiency (which It seems is why the check was put in the spin lock
>      code only when debug is enabled), lets split the spin_lock_mutex call into two
>      components, where the outer component does the debug checking.  Then
>      mutex_trylock can just call the inner part as its callable from irq context
>      safely.

Sorry but I'm not yet convinced that it's safe to invoke mutex_trylock() 
from IRQ context. Please have a look at the implementation of 
mutex_set_owner(), which is invoked by mutex_trylock(). 
mutex_set_owner() stores the value of the "current" pointer into 
lock->owner. The value of "current" does not have a meaning in IRQ context.

Bart.