timekeeping: Copy the shadow-timekeeper over the real timekeeper last
authorJohn Stultz <[email protected]>
Wed, 17 Jun 2015 17:05:53 +0000 (10:05 -0700)
committerThomas Gleixner <[email protected]>
Thu, 18 Jun 2015 07:27:02 +0000 (09:27 +0200)
commit906c55579a6360dd9ef5a3101bb2e3ae396dfb97
treec105a14950a598af6aa9f2e9e74450a14a84443a
parenta9d20988ac7db47fec4510cefc966e876a4ce674
timekeeping: Copy the shadow-timekeeper over the real timekeeper last

The fix in d151832650ed9 (time: Move clock_was_set_seq update
before updating shadow-timekeeper) was unfortunately incomplete.

The main gist of that change was to do the shadow-copy update
last, so that any state changes were properly duplicated, and
we wouldn't accidentally have stale data in the shadow.

Unfortunately in the main update_wall_time() logic, we update
use the shadow-timekeeper to calculate the next update values,
then while holding the lock, copy the shadow-timekeeper over,
then call timekeeping_update() to do some additional
bookkeeping, (skipping the shadow mirror). The bug with this is
the additional bookkeeping isn't all read-only, and some
changes timkeeper state. Thus we might then overwrite this state
change on the next update.

To avoid this problem, do the timekeeping_update() on the
shadow-timekeeper prior to copying the full state over to
the real-timekeeper.

This avoids problems with both the clock_was_set_seq and
next_leap_ktime being overwritten and possibly the
fast-timekeepers as well.

Many thanks to Prarit for his rigorous testing, which discovered
this problem, along with Prarit and Daniel's work validating this
fix.

Reported-by: Prarit Bhargava <[email protected]>
Tested-by: Prarit Bhargava <[email protected]>
Tested-by: Daniel Bristot de Oliveira <[email protected]>
Signed-off-by: John Stultz <[email protected]>
Cc: Richard Cochran <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Jiri Bohac <[email protected]>
Cc: Ingo Molnar <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>
kernel/time/timekeeping.c