Skip to content

Commit

Permalink
time: Fix change_clocksource locking
Browse files Browse the repository at this point in the history
change_clocksource() fails to grab locks or call timekeeping_update(),
which leaves a race window for time inconsistencies.

This adds proper locking and a call to timekeeping_update() to fix this.

CC: Andy Lutomirski <[email protected]>
CC: Thomas Gleixner <[email protected]>
Signed-off-by: John Stultz <[email protected]>
  • Loading branch information
johnstultz-work committed Mar 16, 2012
1 parent a939e81 commit f695cf9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,23 @@ EXPORT_SYMBOL(timekeeping_inject_offset);
static int change_clocksource(void *data)
{
struct clocksource *new, *old;
unsigned long flags;

new = (struct clocksource *) data;

write_seqlock_irqsave(&timekeeper.lock, flags);

timekeeping_forward_now();
if (!new->enable || new->enable(new) == 0) {
old = timekeeper.clock;
timekeeper_setup_internals(new);
if (old->disable)
old->disable(old);
}
timekeeping_update(true);

write_sequnlock_irqrestore(&timekeeper.lock, flags);

return 0;
}

Expand Down

0 comments on commit f695cf9

Please sign in to comment.