Re: [PATCH v2 1/2] timekeeping: Read getboottime64() offsets under the sequence counter
From: John Stultz
Date: Fri Oct 30 2026 - 14:41:13 EST
On Thu, Oct 29, 2026 at 10:42 PM Hungyu Lin <dennylin0707@xxxxxxxxx> wrote:
>
> 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")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
> ---
> New prerequisite in v2, addressing Andrew Morton's review.
>
> 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 dcf47f1ffdcf..7d7a7372f3c8 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);
> }
Seems reasonable to me. Thanks for sending this out!
Acked-by: John Stultz <jstultz@xxxxxxxxxx>