From: Thomas Gleixner <tglx@kernel.org>
To: David Woodhouse <dwmw2@infradead.org>,
Miroslav Lichvar <mlichvar@redhat.com>
Cc: "Richard Cochran" <richardcochran@gmail.com>,
"Wen Gu" <guwen@linux.alibaba.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"John Stultz" <jstultz@google.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Arnd Bergmann" <arnd@arndb.de>,
"Julien Ridoux" <ridouxj@amazon.com>,
"Ryan Luu" <rluu@amazon.com>,
linux-kernel@vger.kernel.org,
"Marcelo Tosatti" <mtosatti@redhat.com>
Subject: Re: [RFC PATCH v2 0/8] timekeeping: Fix draft tracking precision and add feed-forward discipline via vmclock
Date: Sun, 24 May 2026 17:37:09 +0200 [thread overview]
Message-ID: <87h5nwu8d6.ffs@tglx> (raw)
In-Reply-To: <87jyssu9dw.ffs@tglx>
On Sun, May 24 2026 at 17:15, Thomas Gleixner wrote:
> On Fri, May 22 2026 at 17:50, David Woodhouse wrote:
>> On Fri, 2026-05-22 at 17:28 +0200, Thomas Gleixner wrote:
>>>
>>> git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git timers/ptp/timekeeping
>>
>> In 94dd85a8d0a ("timekeeping: Add system_counterval_t to struct
>> system_device_crosststamp") my version ditched the system_counterval_t
>> on the stack and just used the one in xtstamp directly.
>
> Which is wrong. I did it the way I did for a very good reason.
>
>> The convert_base_to_cs() function probably wants to scv->id=cs->id for
>> itself anyway; otherwise it's leaving behind an inconsistent
>> system_counterval_t object which... will lead to exactly the bug my
>> first version of that had, that I see you avoided :)
>
> No. It can't because that would corrupt the object for the retry case,
> which would then hand back the wrong value.
>
> The object _IS_ consistent because the csid in there is related to the
> PTM value and not to the clocksource. The function updates the @cycles
> value and leaves everything else untouched. The clock ID for the @cyles
> value is guaranteed to be the clock ID of the system clocksource, so
> using this is the right thing to do.
>
> Just because it looks tempting or your AI buddy told you so doesn't make
> it correct.
And it's worse. We both are wrong :)
There is an existing bug in that code for the retry case. Fix below.
Thanks,
tglx
---
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1343,12 +1343,14 @@ static bool convert_clock(u64 *val, u32
return true;
}
-static bool convert_base_to_cs(struct system_counterval_t *scv)
+static bool convert_base_to_cs(struct system_counterval_t *scv, u64 *cycles)
{
struct clocksource *cs = tk_core.timekeeper.tkr_mono.clock;
struct clocksource_base *base;
u32 num, den;
+ *cycles = scv->cycles;
+
/* The timestamp was taken from the time keeper clock source */
if (cs->id == scv->cs_id)
return true;
@@ -1364,10 +1366,10 @@ static bool convert_base_to_cs(struct sy
num = scv->use_nsecs ? cs->freq_khz : base->numerator;
den = scv->use_nsecs ? USEC_PER_SEC : base->denominator;
- if (!convert_clock(&scv->cycles, num, den))
+ if (!convert_clock(cycles, num, den))
return false;
- scv->cycles += base->offset;
+ *cycles += base->offset;
return true;
}
@@ -1479,9 +1481,8 @@ int get_device_system_crosststamp(int (*
* installed timekeeper clocksource
*/
if (system_counterval.cs_id == CSID_GENERIC ||
- !convert_base_to_cs(&system_counterval))
+ !convert_base_to_cs(&system_counterval, &cycles))
return -ENODEV;
- cycles = system_counterval.cycles;
/*
* Check whether the system counter value provided by the
next prev parent reply other threads:[~2026-05-24 15:37 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-17 21:25 [RFC PATCH v2 0/8] timekeeping: Fix draft tracking precision and add feed-forward discipline via vmclock David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 1/8] timekeeping: Remove xtime_remainder from ntp_error accumulation David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 2/8] timekeeping: Account for clawback adjustment in ntp_error David Woodhouse
2026-05-19 1:59 ` John Stultz
2026-05-19 10:04 ` David Woodhouse
2026-05-19 19:28 ` John Stultz
2026-05-20 10:47 ` Miroslav Lichvar
2026-05-20 12:37 ` David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 3/8] timekeeping: Clamp time_offset delta to prevent infinite tail David Woodhouse
2026-05-19 13:25 ` Miroslav Lichvar
2026-05-19 13:31 ` David Woodhouse
2026-05-19 14:17 ` Miroslav Lichvar
2026-05-19 15:06 ` David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 4/8] timekeeping: Add absolute reference for feed-forward clock discipline David Woodhouse
2026-05-19 2:09 ` John Stultz
2026-05-19 11:07 ` David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 5/8] ptp_vmclock: Feed reference to timekeeping for feed-forward discipline David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 6/8] timekeeping: Guard against divide-by-zero in timekeeping_adjust David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 7/8] timekeeping: Drive time_offset skew via per-tick ntp_error transfer David Woodhouse
2026-05-17 21:25 ` [RFC PATCH v2 8/8] WIP: kernel/time: Add /dev/vmclock_host miscdev David Woodhouse
2026-05-19 13:16 ` [RFC PATCH v2 0/8] timekeeping: Fix draft tracking precision and add feed-forward discipline via vmclock Miroslav Lichvar
2026-05-19 15:50 ` David Woodhouse
2026-05-20 10:39 ` Miroslav Lichvar
2026-05-20 12:21 ` David Woodhouse
2026-05-21 6:35 ` Miroslav Lichvar
2026-05-21 9:54 ` David Woodhouse
2026-05-25 8:08 ` Miroslav Lichvar
2026-05-25 9:14 ` David Woodhouse
2026-05-26 7:10 ` Miroslav Lichvar
2026-05-26 10:00 ` David Woodhouse
2026-05-27 7:46 ` Miroslav Lichvar
2026-05-27 12:28 ` David Woodhouse
2026-05-21 18:30 ` Thomas Gleixner
2026-05-21 21:06 ` David Woodhouse
2026-05-22 8:02 ` Thomas Gleixner
2026-05-22 10:01 ` David Woodhouse
2026-05-22 15:28 ` Thomas Gleixner
2026-05-22 16:23 ` David Woodhouse
2026-05-24 12:36 ` Thomas Gleixner
2026-05-24 13:13 ` David Woodhouse
2026-05-24 15:05 ` Thomas Gleixner
2026-05-25 8:06 ` Arthur Kiyanovski
2026-05-25 8:41 ` David Woodhouse
2026-05-26 14:12 ` Thomas Gleixner
2026-05-22 16:50 ` David Woodhouse
2026-05-24 15:15 ` Thomas Gleixner
2026-05-24 15:37 ` Thomas Gleixner [this message]
2026-05-24 15:48 ` Thomas Gleixner
2026-05-24 16:36 ` Thomas Gleixner
2026-05-24 16:42 ` David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h5nwu8d6.ffs@tglx \
--to=tglx@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=anna-maria@linutronix.de \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=dwmw2@infradead.org \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=guwen@linux.alibaba.com \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=richardcochran@gmail.com \
--cc=ridouxj@amazon.com \
--cc=rluu@amazon.com \
--cc=sboyd@kernel.org \
--cc=shuah@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox