From: Steven Rostedt <rostedt@goodmis.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: Re: [patch 1/6] rtmutex: Fix deadlock detector for real
Date: Tue, 27 May 2014 18:09:30 -0400 [thread overview]
Message-ID: <20140527180930.1e9b020e@gandalf.local.home> (raw)
In-Reply-To: <20140522031949.725272460@linutronix.de>
On Thu, 22 May 2014 03:25:39 -0000
Thomas Gleixner <tglx@linutronix.de> wrote:
> 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 <tglx@linutronix.de>
> Cc: stable@vger.kernel.org
> ---
> kernel/locking/rtmutex.c | 27 +++++++++++++++++++++------
> 1 file changed, 21 insertions(+), 6 deletions(-)
>
> Index: tip/kernel/locking/rtmutex.c
> ===================================================================
> --- tip.orig/kernel/locking/rtmutex.c
> +++ tip/kernel/locking/rtmutex.c
> @@ -343,16 +343,22 @@ 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 (!detect_deadlock && top_waiter != task_top_pi_waiter(task))
> + goto out_unlock_pi;
> + }
The above seems obvious.
>
> /*
> * 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;
> + }
This too.
Although! if you want to micro-optimize the detect_deadlock case
where !detect_deadlock is false. You might want to reverse the order.
That way we don't need to dereference the ->prio for both waiter and
task before seeing that we don't go to the out_unlock_pi.
if (!detect_deadlock) {
if (waiter->prio == task->prio)
goto out_unlock_pi;
}
Hmm, or you did it this way for your "don't requeue" patch? Looking at
that one, it seems you did.
if (waiter->prio == task->prio) {
if (!detect_deadlock)
goto out_unlock_pi;
requeue = false;
}
Oh well. But for stable maybe have the optimized way? And change it
back when you add the requeue patch?
>
> lock = waiter->lock;
> if (!raw_spin_trylock(&lock->wait_lock)) {
> @@ -361,7 +367,12 @@ static int rt_mutex_adjust_prio_chain(st
> goto retry;
> }
>
> - /* Deadlock detection */
> + /*
> + * Deadlock detection. If the lock is the same as the original
> + * lock which caused us to walk the lock chain or if the
> + * current lock is owned by the task which initiated the chain
> + * walk, we detected a deadlock.
> + */
> if (lock == orig_lock || rt_mutex_owner(lock) == top_task) {
> debug_rt_mutex_deadlock(deadlock_detect, orig_waiter, lock);
> raw_spin_unlock(&lock->wait_lock);
> @@ -527,6 +538,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;
> +
This is an optimization, right? Does it belong for stable?
-- Steve
> raw_spin_lock_irqsave(&task->pi_lock, flags);
> __rt_mutex_adjust_prio(task);
> waiter->task = task;
>
next prev parent reply other threads:[~2014-05-27 22:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-22 3:25 [patch 0/6] rtmutex: Repair deadlock detector and cleanup Thomas Gleixner
2014-05-22 3:25 ` [patch 1/6] rtmutex: Fix deadlock detector for real Thomas Gleixner
2014-05-27 22:09 ` Steven Rostedt [this message]
2014-05-28 9:57 ` Thomas Gleixner
2014-05-28 19:28 ` [tip:core/urgent] " tip-bot for Thomas Gleixner
2014-05-22 3:25 ` [patch 2/6] rtmutex: Remove builtin tester Thomas Gleixner
2014-05-30 21:36 ` Steven Rostedt
2014-05-22 3:25 ` [patch 3/6] rtmutex: Cleanup deadlock detector debug logic Thomas Gleixner
2014-05-30 22:08 ` Steven Rostedt
2014-06-21 20:32 ` [tip:locking/core] " tip-bot for Thomas Gleixner
2014-05-22 3:25 ` [patch 4/6] rtmutex: Confine deadlock logic to futex Thomas Gleixner
2014-05-22 7:10 ` Peter Zijlstra
2014-05-28 20:28 ` Thomas Gleixner
2014-05-31 2:06 ` Steven Rostedt
2014-05-22 3:25 ` [patch 5/6] rtmutex: Clarify the lock chain walk Thomas Gleixner
2014-05-31 2:19 ` Steven Rostedt
2014-05-22 3:25 ` [patch 6/6] rtmutex: Avoid pointless requeueing in the deadlock detection " Thomas Gleixner
2014-05-27 22:49 ` Jason Low
2014-05-28 9:43 ` Thomas Gleixner
2014-05-31 2:21 ` Steven Rostedt
2014-06-21 20:33 ` [tip:locking/core] " tip-bot for Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140527180930.1e9b020e@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).