locking: rtmutex: Fix wake_q logic in task_blocks_on_rt_mutex
Subsystems (2)
PATCH RESEND 1/1 locking: rtmutex: Fix wake_q logic in task_blocks_on_rt_mutex
Anders had bisected a crash using PREEMPT_RT with linux-next and isolated it down to commit 894d1b3db41c ("locking/mutex: Remove wakeups from under mutex::wait_lock"), where it seemed the wake_q structure was somehow getting corrupted causing a null pointer traversal.
I was able to easily repoduce this with PREEMPT_RT and managed to isolate down that through various call stacks we were actually calling wake_up_q() twice on the same wake_q.
I found that in the problematic commit, I had added the wake_up_q() call in task_blocks_on_rt_mutex() around __ww_mutex_add_waiter(), following a similar pattern in __mutex_lock_common().
However, its just wrong. We haven't dropped the lock->wait_lock, so its contrary to the point of the original patch. And it didn't match the __mutex_lock_common() logic of re-initializing the wake_q after calling it midway in the stack.
Looking at it now, the wake_up_q() call is incorrect and should just be removed. So drop the erronious logic I had added.
---
Apologies for being noisy, I recognize its only been a week, but I wanted to resend this now as the problematic commit just landed in Linus' tree and I've not seen this get queued yet.
thanks
-john
--- kernel/locking/rtmutex.c | 3 --- 1 file changed, 3 deletions(-)
kernel/locking/rtmutex.c +0 -3
@@ -1248,10 +1248,7 @@ static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock,/* Check whether the waiter should back out immediately */ rtm = container_of(lock, struct rt_mutex, rtmutex); -preempt_disable (); res =__ww_mutex_add_waiter (waiter, rtm, ww_ctx, wake_q); -wake_up_q (wake_q); -preempt_enable ();if (res) {raw_spin_lock (&task->pi_lock);rt_mutex_dequeue (lock, waiter);
Signature · 1 line
2.47.0.338.g60cca15819-goog
Peter Zijlstra
maintainerQuoted 57 lines · John Stultz
Anders had bisected a crash using
PREEMPT_RTwith linux-next and isolated it down to commit894d1b3db41c("locking/mutex: Remove wakeups from undermutex::wait_lock"), where it seemed thewake_qstructure was somehow getting corrupted causing a null pointer traversal.I was able to easily repoduce this with
PREEMPT_RTand managed to isolate down that through various call stacks we were actually callingwake_up_q()twice on the samewake_q.I found that in the problematic commit, I had added the
wake_up_q()call intask_blocks_on_rt_mutex()around__ww_mutex_add_waiter(), following a similar pattern in__mutex_lock_common().However, its just wrong. We haven't dropped the
lock->wait_lock, so its contrary to the point of the original patch. And it didn't match the__mutex_lock_common()logic of re-initializing thewake_qafter calling it midway in the stack.Looking at it now, the
wake_up_q()call is incorrect and should just be removed. So drop the erronious logic I had added.Cc Peter Zijlstra <[email protected]>Cc Joel Fernandes <[email protected]>Cc Qais Yousef <[email protected]>Cc Ingo Molnar <[email protected]>Cc Juri Lelli <[email protected]>Cc Vincent Guittot <[email protected]>Cc Dietmar Eggemann <[email protected]>Cc Valentin Schneider <[email protected]>Cc Steven Rostedt <[email protected]>Cc Benjamin Segall <[email protected]>Cc Zimuzo Ezeozue <[email protected]>Cc Mel Gorman <[email protected]>Cc Will Deacon <[email protected]>Cc Waiman Long <[email protected]>Cc Boqun Feng <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Metin Kaya <[email protected]>Cc Xuewen Yan <[email protected]>Cc K Prateek Nayak <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Daniel Lezcano <[email protected]>Cc Davidlohr Bueso <[email protected]>Cc Thorsten Leemhuis <[email protected]>Cc Anders Roxell <[email protected]>Fixes 894d1b3db41c ("locking/mutex: Remove wakeups from under mutex::wait_lock")Reported-by Anders Roxell <[email protected]>Reported-by Arnd Bergmann <[email protected]>Tested-by Anders Roxell <[email protected]>Tested-by K Prateek Nayak <[email protected]>Reviewed-by Juri Lelli <[email protected]>Signed-off-by John Stultz <[email protected]>
Quoted 4 lines
---
Apologies for being noisy, I recognize its only been a week, but I wanted to resend this now as the problematic commit just landed in Linus' tree and I've not seen this get queued yet.
Right, I picked up the old one a few days ago, but will not be sticking it in any git tree until -rc1.