Skip to content

Commit

Permalink
[PATCH] hrtimers: fix posix-timer requeue race
Browse files Browse the repository at this point in the history
From: Steven Rostedtrostedt@goodmis.org <rostedt@goodmis.org>

CPU0 expires a posix-timer and runs the callback function.  The signal is
queued.

After releasing the posix-timer lock and before returning to hrtimer_run_queue
CPU0 gets interrupted.  CPU1 delivers the queued signal and rearms the timer.
CPU0 comes back to hrtimer_run_queue and sets the timer state to expired.

The next modification of the timer can result in an oops, because the state
information is wrong.

Keep track of state = RUNNING and check if the state has been in the return
path of hrtimer_run_queue.  In case the state has been changed, ignore a
restart request and do not touch the state variable.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
akpm@osdl.org authored and Linus Torvalds committed Feb 1, 2006
1 parent a16a1c0 commit ff60a5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum hrtimer_restart {
enum hrtimer_state {
HRTIMER_INACTIVE, /* Timer is inactive */
HRTIMER_EXPIRED, /* Timer is expired */
HRTIMER_RUNNING, /* Timer is running the callback function */
HRTIMER_PENDING, /* Timer is pending */
};

Expand Down
5 changes: 5 additions & 0 deletions kernel/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ static inline void run_hrtimer_queue(struct hrtimer_base *base)
fn = timer->function;
data = timer->data;
set_curr_timer(base, timer);
timer->state = HRTIMER_RUNNING;
__remove_hrtimer(timer, base);
spin_unlock_irq(&base->lock);

Expand All @@ -565,6 +566,10 @@ static inline void run_hrtimer_queue(struct hrtimer_base *base)

spin_lock_irq(&base->lock);

/* Another CPU has added back the timer */
if (timer->state != HRTIMER_RUNNING)
continue;

if (restart == HRTIMER_RESTART)
enqueue_hrtimer(timer, base);
else
Expand Down

0 comments on commit ff60a5d

Please sign in to comment.