From: Thomas Gleixner <tglx@linutronix.de>
To: Jiri Bohac <jbohac@suse.cz>
Cc: linux-kernel@vger.kernel.org, mhocko@suse.cz
Subject: Re: running hrtimer_start on an already active hrtimer?
Date: Tue, 5 May 2015 17:11:40 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.11.1505051657130.4225@nanos> (raw)
In-Reply-To: <20150505133054.GA20643@midget.suse.cz>
On Tue, 5 May 2015, Jiri Bohac wrote:
> Hi,
>
>
> I came across a strange bug (in a very old kernel) that triggers
> the
> BUG_ON(timer->state != HRTIMER_STATE_CALLBACK);
> in __run_hrtimer().
>
> The code runs hrtimer_start() on an already started hrtimer.
> Looking at the description of hrtimer_start() it looks
> like something that is allowed:
> /**
> * hrtimer_start - (re)start an hrtimer on the current CPU
> ...
> * Returns:
> * 0 on success
> * 1 when the timer was active
>
> Is this really supposed to work?
>
> I think it's not immune to this race condition:
>
> CPU0 CPU1
> __run_hrtimer()
> __remove_hrtimer(...HRTIMER_STATE_CALLBACK)
> //clears HRTIMER_STATE_ENQUEUED
> ...
> raw_spin_unlock(&cpu_base->lock);
> restart = fn(timer);
> hrtimer_start()
> __hrtimer_start_range_ns()
> //remove_hrtimer() does nothing because
> // HRTIMER_STATE_ENQUEUED is not set
> enqueue_hrtimer()
> raw_spin_lock(&cpu_base->lock);
> ...
> BUG_ON(timer->state != HRTIMER_STATE_CALLBACK);
> // state has HRTIMER_STATE_ENQUEUED set
>
That's in the conditional path:
if (restart != HRTIMER_NORESTART) {
BUG_ON(timer->state != HRTIMER_STATE_CALLBACK);
....
Which was intentional when we implemented hrtimers in the very
beginning. We wanted to enforce that restart from the callback is not
mixed with a start from some other place.
We removed that restriction recently (queued for 4.2 in
tip/timers/core)
> Should __hrtimer_start_range_ns() do something like
> hrtimer_cancel - i.e. explicitly check for ...
> HRTIMER_STATE_CALLBACK?
No, you cannot do anything about it other than lifting the restriction
or preventing the site which handles the hrtimer to start it.
Thanks,
tglx
prev parent reply other threads:[~2015-05-05 16:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-05 13:30 Jiri Bohac
2015-05-05 15:11 ` Thomas Gleixner [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=alpine.DEB.2.11.1505051657130.4225@nanos \
--to=tglx@linutronix.de \
--cc=jbohac@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@suse.cz \
/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
all inboxes | Powered by JetHome®