--- 26e2f3705cc159e75324c28e3caacfdfea379484 +++ f5e362f12fe25a198f2b70a2c197e48aa4009f9c @@ -168,8 +168,15 @@ int __read_mostly timekeeping_suspended; static struct timespec xtime_cache __attribute__ ((aligned (16))); void update_xtime_cache(u64 nsec) { - xtime_cache = xtime; - timespec_add_ns(&xtime_cache, nsec); + /* + * Use temporary variable so get_seconds() cannot catch + * an intermediate xtime_cache.tv_sec value. + * The ACCESS_ONCE() keeps the compiler from optimizing + * out the intermediate value. + */ + struct timespec ts = xtime; + timespec_add_ns(&ts, nsec); + ACCESS_ONCE(xtime_cache) = ts; } /* must hold xtime_lock */