[tip: timers/urgent] timekeeping: Update offsets on sequence counter retry in ktime_get_update_offsets_now()
From: tip-bot2 for Thomas Weißschuh (Schneider Electric)
Date: Fri Oct 23 2026 - 16:17:16 EST
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 6541fbc942f3b63bb8bd44e34eee6223e0abe719
Gitweb: https://git.kernel.org/tip/6541fbc942f3b63bb8bd44e34eee6223e0abe719
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
AuthorDate: Fri, 23 Oct 2026 13:49:17 +02:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Fri, 23 Oct 2026 21:52:01 +02:00
timekeeping: Update offsets on sequence counter retry in ktime_get_update_offsets_now()
The sequence counter of the cwsseq target is modified during the
sequence counter loop. If the loop retries, cwsseq will now match
but the offsets contain the values from the previous loop iteration.
These are not guaranteed to be consistent in themselves or with the
current loops "now.
Save the target's original sequence counter value so that the update
also happens on loop retries.
Fixes: 868a3e915f7f ("hrtimer: Make offset update smarter")
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Link: https://patch.msgid.link/20261023-timekeeping-clock_was_set_seq-v1-1-61c4c53d031c@xxxxxxxxxxxxx
---
kernel/time/timekeeping.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 1b34282..cae3e51 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -2849,6 +2849,7 @@ ktime_t ktime_get_update_offsets_now(u32 *cwsseq, ktime_t *offs_real,
ktime_t *offs_boot, ktime_t *offs_tai)
{
struct timekeeper *tk = &tk_core.timekeeper;
+ u32 cwsseq_orig = *cwsseq;
unsigned int seq;
ktime_t base;
u64 nsecs;
@@ -2860,7 +2861,7 @@ ktime_t ktime_get_update_offsets_now(u32 *cwsseq, ktime_t *offs_real,
nsecs = timekeeping_get_ns(&tk->tkr_mono);
base = ktime_add_ns(base, nsecs);
- if (*cwsseq != tk->clock_was_set_seq) {
+ if (cwsseq_orig != tk->clock_was_set_seq) {
*cwsseq = tk->clock_was_set_seq;
*offs_real = tk->offs_real;
*offs_boot = tk->offs_boot;