* running hrtimer_start on an already active hrtimer?
@ 2015-05-05 13:30 Jiri Bohac
2015-05-05 15:11 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: Jiri Bohac @ 2015-05-05 13:30 UTC (permalink / raw)
To: linux-kernel; +Cc: tglx, mhocko
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
Should __hrtimer_start_range_ns() do something like
hrtimer_cancel - i.e. explicitly check for ...
HRTIMER_STATE_CALLBACK?
Thanks,
--
Jiri Bohac <jbohac@suse.cz>
SUSE Labs, SUSE CZ
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: running hrtimer_start on an already active hrtimer?
2015-05-05 13:30 running hrtimer_start on an already active hrtimer? Jiri Bohac
@ 2015-05-05 15:11 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2015-05-05 15:11 UTC (permalink / raw)
To: Jiri Bohac; +Cc: linux-kernel, mhocko
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-05 16:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-05 13:30 running hrtimer_start on an already active hrtimer? Jiri Bohac
2015-05-05 15:11 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox