public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] timekeeping: handle epoch roll-over (2038) on 32-bit systems
@ 2013-06-03 13:34 Tobias Waldekranz
  2013-06-03 14:34 ` Thomas Gleixner
  0 siblings, 1 reply; 8+ messages in thread
From: Tobias Waldekranz @ 2013-06-03 13:34 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel

In ktime_get_update_offsets, calculate the current time in the same
way as in ktime_get.

On 32-bit systems, the current time is truncated via the call to
ktime_set, the following subtraction of offs_real will result in an
inaccurate time when the current number of seconds since epoch can no
longer fit in 31-bits (2038-01-19 03:14:07 UTC). This will send
hrtimer_interrupt into an infinite loop on some architectures (arm),
or emit an oops on others(x86).

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
 kernel/time/timekeeping.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 98cd470..b484ab2 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1600,8 +1600,8 @@ ktime_t ktime_get_update_offsets(ktime_t
*offs_real, ktime_t *offs_boot,
  do {
  seq = read_seqcount_begin(&timekeeper_seq);

- secs = tk->xtime_sec;
- nsecs = timekeeping_get_ns(tk);
+ secs = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
+ nsecs = timekeeping_get_ns(tk) + tk->wall_to_monotonic.tv_nsec;

  *offs_real = tk->offs_real;
  *offs_boot = tk->offs_boot;
@@ -1609,7 +1609,6 @@ ktime_t ktime_get_update_offsets(ktime_t
*offs_real, ktime_t *offs_boot,
  } while (read_seqcount_retry(&timekeeper_seq, seq));

  now = ktime_add_ns(ktime_set(secs, 0), nsecs);
- now = ktime_sub(now, *offs_real);
  return now;
 }
 #endif
--
1.7.10.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-08-25  0:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-03 13:34 [PATCH] timekeeping: handle epoch roll-over (2038) on 32-bit systems Tobias Waldekranz
2013-06-03 14:34 ` Thomas Gleixner
2013-06-03 19:04   ` John Stultz
2013-06-07 21:53     ` Thomas Gleixner
2013-06-20 12:34       ` Ingo Molnar
2013-08-24 23:47       ` Michael Gilbert
2013-06-04  6:59   ` Tobias Waldekranz
2013-06-07 20:57     ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox