From: Peter Zijlstra <peterz@infradead.org>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: mingo@redhat.com,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [BUG] kernel: locking: a possible sleep-in-atomic-context bug in rt_mutex_slowlock()
Date: Thu, 21 Jun 2018 09:36:29 +0200 [thread overview]
Message-ID: <20180621073629.GP2494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <10fdf749-b47c-587c-96cb-9a877d8760ac@gmail.com>
On Thu, Jun 21, 2018 at 11:14:49AM +0800, Jia-Ju Bai wrote:
> The kernel may sleep with holding a spinlock.
> The function call path (from bottom to top) in Linux-4.16.7 is:
>
> [FUNC] schedule
> kernel/locking/rtmutex.c, 1223: schedule in rt_mutex_handle_deadlock
> kernel/locking/rtmutex.c, 1273: rt_mutex_handle_deadlock in
> rt_mutex_slowlock
> kernel/locking/rtmutex.c, 1249: _raw_spin_lock_irqsave in rt_mutex_slowlock
>
> This bug is found by my static analysis tool (DSAC-2) and checked by my
> code review.
>
> I do not know how to correctly fix this bug, so I just report them.
I think the below will do. The purpose seems to be to take out the task
when we cannot return -EDEADLOCK to userspace. And it can do so just
fine after we unlock the wait_lock.
Thomas?
---
kernel/locking/rtmutex.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 4f014be7a4b8..d33446a05681 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1269,7 +1269,6 @@ 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);
}
/*
@@ -1280,6 +1279,8 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
+ rt_mutex_handle_deadlock(ret, chwalk, &waiter);
+
/* Remove pending timer: */
if (unlikely(timeout))
hrtimer_cancel(&timeout->timer);
prev parent reply other threads:[~2018-06-21 7:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-21 3:14 [BUG] kernel: locking: a possible sleep-in-atomic-context bug in rt_mutex_slowlock() Jia-Ju Bai
2018-06-21 7:36 ` 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=20180621073629.GP2494@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=baijiaju1990@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--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