Skip to content

Commit

Permalink
hrtimer: catch expired CLOCK_REALTIME timers early
Browse files Browse the repository at this point in the history
A CLOCK_REALTIME timer, which has an absolute expiry time less than
the clock realtime offset calls with a negative delta into the clock
events code and triggers the WARN_ON() there.

This is a false positive and needs to be prevented. Check the result
of timer->expires - timer->base->offset right away and return -ETIME
right away.

Thanks to Frans Pop, who reported the problem and tested the fixes.

Signed-off-by: Thomas Gleixner <[email protected]>
Tested-by: Frans Pop <[email protected]>
  • Loading branch information
KAGA-KOKO committed Feb 14, 2008
1 parent 5a7780e commit 63070a7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kernel/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ static int hrtimer_reprogram(struct hrtimer *timer,
ktime_t expires = ktime_sub(timer->expires, base->offset);
int res;

WARN_ON_ONCE(timer->expires.tv64 < 0);

/*
* When the callback is running, we do not reprogram the clock event
* device. The timer callback is either running on a different CPU or
Expand All @@ -452,6 +454,15 @@ static int hrtimer_reprogram(struct hrtimer *timer,
if (hrtimer_callback_running(timer))
return 0;

/*
* CLOCK_REALTIME timer might be requested with an absolute
* expiry time which is less than base->offset. Nothing wrong
* about that, just avoid to call into the tick code, which
* has now objections against negative expiry values.
*/
if (expires.tv64 < 0)
return -ETIME;

if (expires.tv64 >= expires_next->tv64)
return 0;

Expand Down

0 comments on commit 63070a7

Please sign in to comment.