From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Antoine Gagniere <antoine@gagniere.dev>
Cc: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
jonathan.lemon@gmail.com
Subject: Re: [PATCH] ptp: ocp: Fix PCI delay estimation
Date: Mon, 18 Aug 2025 14:17:11 +0100 [thread overview]
Message-ID: <6848f9cc-a713-4eee-abf2-e4159fea50c2@linux.dev> (raw)
In-Reply-To: <20250817222933.21102-1-antoine@gagniere.dev>
On 17/08/2025 23:29, Antoine Gagniere wrote:
> Since linux 6.12, a sign error causes the initial value of ts_window_adjust, (used in gettimex64) to be impossibly high, causing consumers like chrony to reject readings from PTP_SYS_OFFSET_EXTENDED.
>
> This patch fixes ts_window_adjust's inital value and the sign-ness of various format flags
>
> Context
> -------
>
> The value stored in the read-write attribute ts_window_adjust is a number of nanoseconds subtracted to the post_ts timestamp of the reading in gettimex64, used notably in the ioctl PTP_SYS_OFFSET_EXTENDED, to compensate for PCI delay.
> Its initial value is set by estimating PCI delay.
>
> Bug
> ---
>
> The PCI delay estimation starts with the value U64_MAX and makes 3 measurements, taking the minimum value.
> However because the delay was stored in a s64, U64_MAX was interpreted as -1, which compared as smaller than any positive values measured.
> Then, that delay is divided by ~10 and placed in ts_window_adjust, which is a u32.
> So ts_window_adjust ends up with (u32)(((s64)U64_MAX >> 5) * 3) inside, which is 4294967293
>
> Symptom
> -------
>
> The consequence was that the post_ts of gettimex64, returned by PTP_SYS_OFFSET_EXTENDED, was substracted 4.29 seconds.
> As a consequence chrony rejected all readings from the PHC
>
> Difficulty to diagnose
> ----------------------
>
> Using cat to read the attribute value showed -3 because the format flags %d was used instead of %u, resulting in a re-interpret cast.
>
> Fixes
> -----
>
> 1. Using U32_MAX as initial value for PCI delays: no one is expecting an ioread to take more than 4 s
> This will correctly compare as bigger that actual PCI delay measurements.
> 2. Fixing the sign of various format flags
>
> Signed-off-by: Antoine Gagniere <antoine@gagniere.dev>
JFYI, for the next version could you please organize the commit message
to fit into 80 chars per line and specify net tree as well as patch
which you believe introduced the problem using Fixes tag.
More details on formatting can be found at
https://docs.kernel.org/process/submitting-patches.html#submittingpatches
next prev parent reply other threads:[~2025-08-18 13:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250817222933.21102-1-antoine.ref@gagniere.dev>
2025-08-17 22:29 ` [PATCH] ptp: ocp: Fix PCI delay estimation Antoine Gagniere
2025-08-18 10:46 ` Vadim Fedorenko
2025-08-18 13:17 ` Vadim Fedorenko [this message]
2025-08-18 21:31 ` Antoine Gagniere
2025-08-25 3:57 ` David Laight
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=6848f9cc-a713-4eee-abf2-e4159fea50c2@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=antoine@gagniere.dev \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.