public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtmutex: ensure we wake up the top waiter
@ 2023-01-17 17:26 Wander Lairson Costa
  2023-01-17 19:32 ` Waiman Long
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Wander Lairson Costa @ 2023-01-17 17:26 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng,
	open list:LOCKING PRIMITIVES
  Cc: Wander Lairson Costa

In task_blocked_on_lock() we save the owner, release the wait_lock and
call rt_mutex_adjust_prio_chain(). Before we acquire the wait_lock
again, the owner may release the lock and deboost.

rt_mutex_adjust_prio_chain() acquires the wait_lock. In the requeue
phase, waiter may be initially in the top of the queue, but after
dequeued and requeued it may no longer be true.

This scenario ends up waking the wrong task, which will verify it is no
the top waiter and comes back to sleep. Now we have a situation in which
no task is holding the lock but no one acquires it.

We can reproduce the bug in PREEMPT_RT with stress-ng:

while true; do
    stress-ng --sched deadline --sched-period 1000000000 \
    	    --sched-runtime 800000000 --sched-deadline \
    	    1000000000 --mmapfork 23 -t 20
done

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
---
 kernel/locking/rtmutex.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 010cf4e6d0b8..728f434de2bb 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -901,8 +901,9 @@ static int __sched rt_mutex_adjust_prio_chain(struct task_struct *task,
 		 * then we need to wake the new top waiter up to try
 		 * to get the lock.
 		 */
-		if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
-			wake_up_state(waiter->task, waiter->wake_state);
+		top_waiter = rt_mutex_top_waiter(lock);
+		if (prerequeue_top_waiter != top_waiter)
+			wake_up_state(top_waiter->task, top_waiter->wake_state);
 		raw_spin_unlock_irq(&lock->wait_lock);
 		return 0;
 	}
-- 
2.39.0


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

end of thread, other threads:[~2023-02-06 14:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-17 17:26 [PATCH] rtmutex: ensure we wake up the top waiter Wander Lairson Costa
2023-01-17 19:32 ` Waiman Long
2023-01-17 19:40   ` Waiman Long
2023-01-17 20:01     ` Wander Lairson Costa
2023-01-17 20:00   ` Wander Lairson Costa
2023-01-18  0:05 ` Thomas Gleixner
2023-01-18 18:49   ` Wander Lairson Costa
2023-01-19 20:53     ` Thomas Gleixner
2023-01-31 17:46       ` Wander Lairson Costa
2023-01-31 17:53         ` Wander Lairson Costa
2023-02-02  7:48           ` Thomas Gleixner
2023-02-02 11:20             ` Wander Lairson Costa
2023-02-06 14:12 ` [tip: locking/urgent] rtmutex: Ensure that the top waiter is always woken up tip-bot2 for Wander Lairson Costa

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