From: Peter Zijlstra <peterz@infradead.org>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: mingo@redhat.com, will.deacon@arm.com,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH V2] kernel: locking: rtmutex: Fix a possible sleep-in-atomic-context bug in rt_mutex_handle_deadlock()
Date: Mon, 10 Sep 2018 15:56:27 +0200 [thread overview]
Message-ID: <20180910135627.GL24106@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180811030037.14885-1-baijiaju1990@gmail.com>
On Sat, Aug 11, 2018 at 11:00:37AM +0800, Jia-Ju Bai wrote:
You forgot to Cc the person who wrote this code...
> kernel/locking/rtmutex.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
> index 2823d4163a37..8f25a289abe8 100644
> --- a/kernel/locking/rtmutex.c
> +++ b/kernel/locking/rtmutex.c
> @@ -1205,7 +1205,7 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state,
> }
>
> static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
> - struct rt_mutex_waiter *w)
> + struct rt_mutex_waiter *w, struct rt_mutex *lock)
> {
> /*
> * If the result is not -EDEADLOCK or the caller requested
> @@ -1218,6 +1218,8 @@ static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
> * Yell lowdly and stop the task right here.
> */
> rt_mutex_print_deadlock(w);
> + /* We're not going anywhere, release the wait_lock */
> + raw_spin_unlock_irq(&lock->wait_lock);
> while (1) {
> set_current_state(TASK_INTERRUPTIBLE);
> schedule();
> @@ -1269,7 +1271,7 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
> if (unlikely(ret)) {
> __set_current_state(TASK_RUNNING);
> remove_waiter(lock, &waiter);
> - rt_mutex_handle_deadlock(ret, chwalk, &waiter);
> + rt_mutex_handle_deadlock(ret, chwalk, &waiter, lock);
> }
The patch is correct; but I can't find myself liking it very much. This
dinly little single use function is growing a lot of arguments.
The alternative is something like the below; not sure myself though.
Thomas?
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 2823d4163a37..a44d4034e232 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1204,18 +1204,10 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state,
return ret;
}
-static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
- struct rt_mutex_waiter *w)
+static void rt_mutex_handle_deadlock(struct rt_mutex_waiter *w)
{
/*
- * If the result is not -EDEADLOCK or the caller requested
- * deadlock detection, nothing to do here.
- */
- if (res != -EDEADLOCK || detect_deadlock)
- return;
-
- /*
- * Yell lowdly and stop the task right here.
+ * Yell loudly and stop the task right here.
*/
rt_mutex_print_deadlock(w);
while (1) {
@@ -1269,7 +1261,10 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
if (unlikely(ret)) {
__set_current_state(TASK_RUNNING);
remove_waiter(lock, &waiter);
- rt_mutex_handle_deadlock(ret, chwalk, &waiter);
+ if (chwalk == RT_MUTEX_MIN_CHAINWALK && ret == -EDEADLOCK) {
+ raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
+ rt_mutex_handle_deadlock(&waiter);
+ }
}
/*
prev parent reply other threads:[~2018-09-10 13:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-11 3:00 Jia-Ju Bai
2018-09-10 13:56 ` Peter Zijlstra [this message]
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=20180910135627.GL24106@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=baijiaju1990@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
/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
Powered by JetHome