[tip: timers/urgent] timekeeping: Read getboottime64() offsets under the sequence counter
From: tip-bot2 for Hungyu Lin
Date: Mon Nov 09 2026 - 14:22:28 EST
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 385b5ec1f31dd39297578eed42be74b07ae74017
Gitweb: https://git.kernel.org/tip/385b5ec1f31dd39297578eed42be74b07ae74017
Author: Hungyu Lin <dennylin0707@xxxxxxxxx>
AuthorDate: Fri, 30 Oct 2026 05:42:26
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Mon, 09 Nov 2026 20:15:58 +01:00
timekeeping: Read getboottime64() offsets under the sequence counter
getboottime64() computes the wall-clock boot timestamp from offs_real
minus offs_boot without checking tk_core.seq. A concurrent timekeeping
update can leave the reader with an inconsistent pair of offsets or,
on 32-bit systems, a torn 64-bit offset, producing an incorrect boot
timestamp.
Read both offsets under tk_core.seq and retry if an update overlaps
the sample. Convert the resulting local value to a timespec64 afterward.
Fixes: 7c3f1a573237 ("Introduce boot based time")
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Acked-by: John Stultz <jstultz@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Link: https://patch.msgid.link/20261030054227.35453-2-dennylin0707@xxxxxxxxx
---
kernel/time/timekeeping.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index dcf47f1..7d7a737 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -2700,7 +2700,13 @@ void update_wall_time(void)
void getboottime64(struct timespec64 *ts)
{
struct timekeeper *tk = &tk_core.timekeeper;
- ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot);
+ unsigned int seq;
+ ktime_t t;
+
+ do {
+ seq = read_seqcount_begin(&tk_core.seq);
+ t = ktime_sub(tk->offs_real, tk->offs_boot);
+ } while (read_seqcount_retry(&tk_core.seq, seq));
*ts = ktime_to_timespec64(t);
}