From: Peter Zijlstra <peterz@infradead.org>
To: bsegall@google.com
Cc: Roman Gushchin <klamm@yandex-team.ru>,
linux-kernel@vger.kernel.org, pjt@google.com,
chris.j.arges@canonical.com, gregkh@linuxfoundation.org,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] sched: tg_set_cfs_bandwidth() causes rq->lock deadlock
Date: Tue, 20 May 2014 16:01:55 +0200 [thread overview]
Message-ID: <20140520140155.GS13658@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20140520131526.GE11096@twins.programming.kicks-ass.net>
[-- Attachment #1: Type: text/plain, Size: 1936 bytes --]
On Tue, May 20, 2014 at 03:15:26PM +0200, Peter Zijlstra wrote:
> Which leads us to what I think is a BUG in the current hrtimer code (and
> one wonders why we never hit that), because we drop the cpu_base->lock
> over calling hrtimer::function, hrtimer_start_range_ns() can in fact
> come in and (re)enqueue the timer, if hrtimer::function then returns
> HRTIMER_RESTART, we'll hit that BUG_ON() before trying to enqueue the
> timer once more.
> ---
> kernel/hrtimer.c | 9 ++++++---
> kernel/sched/core.c | 10 ++++++----
> kernel/sched/fair.c | 42 +++---------------------------------------
> kernel/sched/sched.h | 2 +-
> 4 files changed, 16 insertions(+), 47 deletions(-)
>
> diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
> index 3ab28993f6e0..28942c65635e 100644
> --- a/kernel/hrtimer.c
> +++ b/kernel/hrtimer.c
> @@ -1273,11 +1273,14 @@ static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
> * Note: We clear the CALLBACK bit after enqueue_hrtimer and
> * we do not reprogramm the event hardware. Happens either in
> * hrtimer_start_range_ns() or in hrtimer_interrupt()
> + *
> + * Note: Because we dropped the cpu_base->lock above,
> + * hrtimer_start_range_ns() can have popped in and enqueued the timer
> + * for us already.
> */
> - if (restart != HRTIMER_NORESTART) {
> - BUG_ON(timer->state != HRTIMER_STATE_CALLBACK);
> + if (restart != HRTIMER_NORESTART &&
> + !(timer->state & HRTIMER_STATE_ENQUEUED))
> enqueue_hrtimer(timer, base);
> - }
>
> WARN_ON_ONCE(!(timer->state & HRTIMER_STATE_CALLBACK));
>
Hmm,. doesn't this also mean its entirely unsafe to call
hrtimer_forward*() from the timer callback, because it might be changing
the time of an already enqueued timer, which would corrupt the rb-tree
order.
Lemme go find a nice way out of this mess, I think I'm responsible for
creating it in the first place :-(
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2014-05-20 14:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-15 16:58 [PATCH] sched: tg_set_cfs_bandwidth() causes rq->lock deadlock Roman Gushchin
2014-05-15 17:43 ` bsegall
2014-05-16 8:38 ` Roman Gushchin
2014-05-16 17:57 ` bsegall
2014-05-19 11:10 ` Roman Gushchin
2014-05-19 17:40 ` bsegall
2014-05-19 10:32 ` Peter Zijlstra
2014-05-19 11:37 ` Roman Gushchin
2014-05-19 17:35 ` bsegall
2014-05-19 17:30 ` bsegall
2014-05-20 13:15 ` Peter Zijlstra
2014-05-20 14:01 ` Peter Zijlstra [this message]
2014-05-20 14:55 ` Peter Zijlstra
2014-05-20 14:21 ` Roman Gushchin
2014-05-20 14:28 ` Peter Zijlstra
2014-05-20 14:34 ` Roman Gushchin
2014-05-20 19:08 ` bsegall
2014-05-21 7:58 ` Peter Zijlstra
2014-05-19 10:40 ` Peter Zijlstra
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=20140520140155.GS13658@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=chris.j.arges@canonical.com \
--cc=gregkh@linuxfoundation.org \
--cc=klamm@yandex-team.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=pjt@google.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