public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* rt_mutex: restore wait_lock init in __rt_mutex_init
@ 2011-07-27  8:18 Darren Hart
  2011-07-27  9:37 ` Thomas Gleixner
  0 siblings, 1 reply; 4+ messages in thread
From: Darren Hart @ 2011-07-27  8:18 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: Darren Hart, Maarten Lankhorst, Thomas Gleixner, Steven Rostedt

Without the raw_spin_lock_init(), the wait_lock does not get properly
initialized with CONFIG_DEBUG_SPINLOCK. This can manifest in a BUG() in the
futex requeue_pi path when the pi_state->pi_mutex->wait_lock fails the magic
test in rt_mutex_start_proxy_lock()->raw_spin_lock(&lock->wait_lock).

Signed-off-by: Darren Hart <dvhart@linux.intel.com>
Reported-by: Maarten Lankhorst <m.b.lankhorst@gmail.com>
CC: Maarten Lankhorst <m.b.lankhorst@gmail.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Steven Rostedt <rostedt@goodmis.org>

---
 rtmutex.c |    1 +
 1 file changed, 1 insertion(+)

Index: linux-3.0-rt/kernel/rtmutex.c
===================================================================
--- linux-3.0-rt.orig/kernel/rtmutex.c
+++ linux-3.0-rt/kernel/rtmutex.c
@@ -1277,6 +1277,7 @@ EXPORT_SYMBOL_GPL(rt_mutex_destroy);
 void __rt_mutex_init(struct rt_mutex *lock, const char *name)
 {
 	lock->owner = NULL;
+	raw_spin_lock_init(&lock->wait_lock);
 	plist_head_init_raw(&lock->wait_list, &lock->wait_lock);
 
 	debug_rt_mutex_init(lock, name);

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

* Re: rt_mutex: restore wait_lock init in __rt_mutex_init
  2011-07-27  8:18 rt_mutex: restore wait_lock init in __rt_mutex_init Darren Hart
@ 2011-07-27  9:37 ` Thomas Gleixner
  2011-07-27 14:34   ` Maarten Lankhorst
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2011-07-27  9:37 UTC (permalink / raw)
  To: Darren Hart; +Cc: Linux Kernel Mailing List, Maarten Lankhorst, Steven Rostedt

On Wed, 27 Jul 2011, Darren Hart wrote:

> Without the raw_spin_lock_init(), the wait_lock does not get properly
> initialized with CONFIG_DEBUG_SPINLOCK. This can manifest in a BUG() in the
> futex requeue_pi path when the pi_state->pi_mutex->wait_lock fails the magic
> test in rt_mutex_start_proxy_lock()->raw_spin_lock(&lock->wait_lock).

That's actively wrong. You reinitialize the lock for all other cases
which call this via rt_mutex_init(). There is a reason why I moved the
spin lock initializer out of __rt_mutex_init() into
rt_mutex_init(). The lock name stuff for lockdep ends up to be
"lock->wait_lock" for all rt_mutexes, which is pretty useless when you
have to analyze a lockdep splat. Thanks for finding it nevertheless.

So the correct fix is:

Index: linux-2.6/kernel/rtmutex.c
===================================================================
--- linux-2.6.orig/kernel/rtmutex.c
+++ linux-2.6/kernel/rtmutex.c
@@ -1296,7 +1296,7 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
 void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
 				struct task_struct *proxy_owner)
 {
-	__rt_mutex_init(lock, NULL);
+	rt_mutex_init(lock);
 	debug_rt_mutex_proxy_lock(lock, proxy_owner);
 	rt_mutex_set_owner(lock, proxy_owner);
 	rt_mutex_deadlock_account_lock(lock, proxy_owner);

 

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

* Re: rt_mutex: restore wait_lock init in __rt_mutex_init
  2011-07-27  9:37 ` Thomas Gleixner
@ 2011-07-27 14:34   ` Maarten Lankhorst
  2011-07-27 15:43     ` Darren Hart
  0 siblings, 1 reply; 4+ messages in thread
From: Maarten Lankhorst @ 2011-07-27 14:34 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Darren Hart, Linux Kernel Mailing List, Steven Rostedt

On 07/27/2011 11:37 AM, Thomas Gleixner wrote:
> On Wed, 27 Jul 2011, Darren Hart wrote:
>
>> Without the raw_spin_lock_init(), the wait_lock does not get properly
>> initialized with CONFIG_DEBUG_SPINLOCK. This can manifest in a BUG() in the
>> futex requeue_pi path when the pi_state->pi_mutex->wait_lock fails the magic
>> test in rt_mutex_start_proxy_lock()->raw_spin_lock(&lock->wait_lock).
> That's actively wrong. You reinitialize the lock for all other cases
> which call this via rt_mutex_init(). There is a reason why I moved the
> spin lock initializer out of __rt_mutex_init() into
> rt_mutex_init(). The lock name stuff for lockdep ends up to be
> "lock->wait_lock" for all rt_mutexes, which is pretty useless when you
> have to analyze a lockdep splat. Thanks for finding it nevertheless.
>
> So the correct fix is:
>
> Index: linux-2.6/kernel/rtmutex.c
> ===================================================================
> --- linux-2.6.orig/kernel/rtmutex.c
> +++ linux-2.6/kernel/rtmutex.c
> @@ -1296,7 +1296,7 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
>  void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
>  				struct task_struct *proxy_owner)
>  {
> -	__rt_mutex_init(lock, NULL);
> +	rt_mutex_init(lock);
>  	debug_rt_mutex_proxy_lock(lock, proxy_owner);
>  	rt_mutex_set_owner(lock, proxy_owner);
>  	rt_mutex_deadlock_account_lock(lock, proxy_owner);
>
>  
Seems to work. I no longer get a warning from pulseaudio either.
Also darren, at least on fedora 15 glibc supports requeue_pi.
support for that is in nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_*.S

Cheers,
Maarten

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

* Re: rt_mutex: restore wait_lock init in __rt_mutex_init
  2011-07-27 14:34   ` Maarten Lankhorst
@ 2011-07-27 15:43     ` Darren Hart
  0 siblings, 0 replies; 4+ messages in thread
From: Darren Hart @ 2011-07-27 15:43 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: Thomas Gleixner, Linux Kernel Mailing List, Steven Rostedt



On 07/27/2011 07:34 AM, Maarten Lankhorst wrote:
> On 07/27/2011 11:37 AM, Thomas Gleixner wrote:
>> On Wed, 27 Jul 2011, Darren Hart wrote:
>>
>>> Without the raw_spin_lock_init(), the wait_lock does not get properly
>>> initialized with CONFIG_DEBUG_SPINLOCK. This can manifest in a BUG() in the
>>> futex requeue_pi path when the pi_state->pi_mutex->wait_lock fails the magic
>>> test in rt_mutex_start_proxy_lock()->raw_spin_lock(&lock->wait_lock).
>> That's actively wrong. You reinitialize the lock for all other cases
>> which call this via rt_mutex_init(). There is a reason why I moved the
>> spin lock initializer out of __rt_mutex_init() into
>> rt_mutex_init().

Ah... I didn't notice the move. I saw the change to the line after which
add _raw and passed the wait_lock and thought it was expected that that
call did the init (which it doesn't).

>> The lock name stuff for lockdep ends up to be
>> "lock->wait_lock" for all rt_mutexes, which is pretty useless when you
>> have to analyze a lockdep splat. Thanks for finding it nevertheless.

Right, makes sense.

>> So the correct fix is:
>>
>> Index: linux-2.6/kernel/rtmutex.c
>> ===================================================================
>> --- linux-2.6.orig/kernel/rtmutex.c
>> +++ linux-2.6/kernel/rtmutex.c
>> @@ -1296,7 +1296,7 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
>>  void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
>>  				struct task_struct *proxy_owner)
>>  {
>> -	__rt_mutex_init(lock, NULL);
>> +	rt_mutex_init(lock);

So obvious now in hindsight :)

>>  	debug_rt_mutex_proxy_lock(lock, proxy_owner);
>>  	rt_mutex_set_owner(lock, proxy_owner);
>>  	rt_mutex_deadlock_account_lock(lock, proxy_owner);
>>
>>  
> Seems to work. I no longer get a warning from pulseaudio either.

I still don't understand how pulseaudio ever caused this.

> Also darren, at least on fedora 15 glibc supports requeue_pi.
> support for that is in nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_*.S

Duh, sorry, wasn't thinking straight. The requeue_pi support went in a
while ago - what is missing is PI aware condvars which complete
requeue_pi support.

Thanks!

-- 
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel

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

end of thread, other threads:[~2011-07-27 15:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-27  8:18 rt_mutex: restore wait_lock init in __rt_mutex_init Darren Hart
2011-07-27  9:37 ` Thomas Gleixner
2011-07-27 14:34   ` Maarten Lankhorst
2011-07-27 15:43     ` Darren Hart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox