From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752149AbaENUDP (ORCPT ); Wed, 14 May 2014 16:03:15 -0400 Received: from www.linutronix.de ([62.245.132.108]:47695 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751124AbaENUDN (ORCPT ); Wed, 14 May 2014 16:03:13 -0400 Message-Id: <20140514200104.569449934@linutronix.de> User-Agent: quilt/0.60-1 Date: Wed, 14 May 2014 20:03:26 -0000 From: Thomas Gleixner To: LKML Cc: Steven Rostedt , Lai Jiangshan , Peter Zijlstra , Ingo Molnar Subject: [patch 1/2] rtmutex: Fix deadlock detector for real References: <20140514195705.618583609@linutronix.de> Content-Disposition: inline; filename=rtmutex-fix-deadlock-detector-for-real.patch X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current deadlock detection logic does not work reliably due to the following early exit path: /* * Drop out, when the task has no waiters. Note, * top_waiter can be NULL, when we are in the deboosting * mode! */ if (top_waiter && (!task_has_pi_waiters(task) || top_waiter != task_top_pi_waiter(task))) goto out_unlock_pi; So this not only exits when the task has no waiters, it also exits unconditionally when the current waiter is not the top priority waiter of the task. So in a nested locking scenario, it might abort the lock chain walk and therefor miss a potential deadlock. Simple fix: Continue the chain walk, when deadlock detection is enabled. Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org --- kernel/locking/rtmutex.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) Index: linux-2.6/kernel/locking/rtmutex.c =================================================================== --- linux-2.6.orig/kernel/locking/rtmutex.c +++ linux-2.6/kernel/locking/rtmutex.c @@ -343,16 +343,24 @@ static int rt_mutex_adjust_prio_chain(st * top_waiter can be NULL, when we are in the deboosting * mode! */ - if (top_waiter && (!task_has_pi_waiters(task) || - top_waiter != task_top_pi_waiter(task))) - goto out_unlock_pi; + if (top_waiter) { + if (!task_has_pi_waiters(task)) + goto out_unlock_pi; + + if (top_waiter != task_top_pi_waiter(task)) { + if (!detect_deadlock) + goto out_unlock_pi; + } + } /* * When deadlock detection is off then we check, if further * priority adjustment is necessary. */ - if (!detect_deadlock && waiter->prio == task->prio) - goto out_unlock_pi; + if (waiter->prio == task->prio) { + if (!detect_deadlock) + goto out_unlock_pi; + } lock = waiter->lock; if (!raw_spin_trylock(&lock->wait_lock)) { @@ -527,6 +535,10 @@ static int task_blocks_on_rt_mutex(struc unsigned long flags; int chain_walk = 0, res; + /* Early deadlock detection */ + if (detect_deadlock && owner == task) + return -EDEADLK; + raw_spin_lock_irqsave(&task->pi_lock, flags); __rt_mutex_adjust_prio(task); waiter->task = task;