Skip to content

Commit 37e8abf

Browse files
KAGA-KOKOPeter Zijlstra
authored andcommitted
locking/rtmutex: Dequeue waiter on ww_mutex deadlock
The rt_mutex based ww_mutex variant queues the new waiter first in the lock's rbtree before evaluating the ww_mutex specific conditions which might decide that the waiter should back out. This check and conditional exit happens before the waiter is enqueued into the PI chain. The failure handling at the call site assumes that the waiter, if it is the top most waiter on the lock, is queued in the PI chain and then proceeds to adjust the unmodified PI chain, which results in RB tree corruption. Dequeue the waiter from the lock waiter list in the ww_mutex error exit path to prevent this. Fixes: add4613 ("locking/rtmutex: Extend the rtmutex core to support ww_mutex") Reported-by: Sebastian Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent c3123c4 commit 37e8abf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/locking/rtmutex.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,13 @@ static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock,
10821082
/* Check whether the waiter should back out immediately */
10831083
rtm = container_of(lock, struct rt_mutex, rtmutex);
10841084
res = __ww_mutex_add_waiter(waiter, rtm, ww_ctx);
1085-
if (res)
1085+
if (res) {
1086+
raw_spin_lock(&task->pi_lock);
1087+
rt_mutex_dequeue(lock, waiter);
1088+
task->pi_blocked_on = NULL;
1089+
raw_spin_unlock(&task->pi_lock);
10861090
return res;
1091+
}
10871092
}
10881093

10891094
if (!owner)

0 commit comments

Comments
 (0)