Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] In am65_cpts_gtc_push_try() (drivers/net/ethernet/ti/am65-cpts.c), the cycles returned by… -- net: ethernet: ti: am65-cpts: implement PTP_SYS_OFFSET_PRECISE This adds getcrosststamp support to the TI K3 CPTS driver. It routes a GTC counter bit, exported on the GTC push event output, to a CPTS hardware timestamp input. The CPTS timestamp of that edge is paired with the computed GTC edge value, which is derived from clocksource snapshots taken around enabling the input.
> diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c > index d5c0a6a079656..a00e34954a9f0 100644 > --- a/drivers/net/ethernet/ti/am65-cpts.c > +++ b/drivers/net/ethernet/ti/am65-cpts.c
[ ... ]
> +static int am65_cpts_gtc_push_read(ktime_t *device, > + struct system_counterval_t *system, > + void *ctx) > +{ > + struct am65_cpts_gtc_push *push = ctx; > + > + *device = ns_to_ktime(push->ts); > + system->cycles = push->cycles; > + system->cs_id = CSID_ARM_ARCH_COUNTER; > + system->use_nsecs = false; > + > + return 0; > +}
[ ... ]
> +static int am65_cpts_gtc_push_try(struct am65_cpts *cpts, clockid_t clock_id, > + struct system_time_snapshot *before, > + struct am65_cpts_gtc_push *push) > +{
[ ... ]
> + ktime_get_snapshot_id(clock_id, before); > + am65_cpts_gtc_push_enable(cpts, true); > + ktime_get_snapshot_id(clock_id, &after); > + > + if (!before->valid || !after.valid || > + before->cs_id != CSID_ARM_ARCH_COUNTER || > + after.cs_id != CSID_ARM_ARCH_COUNTER) { > + ret = -ENODEV; > + goto disable; > + } > + > + edge = am65_cpts_gtc_push_next_edge(before->cycles);
[Severity: Medium] What happens here when the arch timer clocksource is reading the virtual counter with a non-zero CNTVOFF? The only check is that cs_id is CSID_ARM_ARCH_COUNTER. On arm64, when Linux is entered at EL1, arch_counter_register() in drivers/clocksource/arm_arch_timer.c picks the virtual counter: if ((IS_ENABLED(CONFIG_ARM64) && !is_hyp_mode_available()) || arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI || In that case before->cycles is CNTVCT, which is GTC - CNTVOFF. The cs_id is still CSID_ARM_ARCH_COUNTER, so this check passes. A boot at EL2 is fine, because el2_setup.h clears CNTVOFF_EL2, and a VHE host sees an offset of 0. A hypervisor can leave CNTVOFF non-zero, though. Xen, for example, gives each domain, dom0 included, a virtual timer offset. If CNTVOFF mod 2^16 is not 0, am65_cpts_gtc_push_next_edge() predicts an edge that is not a real GTC edge. The CPTS timestamp of the real edge is still paired with that value in am65_cpts_gtc_push_read(). The check in am65_cpts_gtc_push_wait() compares one virtual count with another, so it would not catch the offset. As far as I can tell, PTP_SYS_OFFSET_PRECISE would then return a PHC/system pair that is off by up to one push period (about 328 us at 200 MHz), and no error is reported. The commit message states the assumption: The driver reads the GTC through the clocksource, which assumes that the clocksource counter value equals the GTC count, that is a CNTVOFF of 0. The code does not enforce it, though. Could getcrosststamp be withheld when !is_hyp_mode_available(), or the setup otherwise detected, so that an unsupported configuration gets -EOPNOTSUPP instead of wrong values?
> + if (edge <= after.cycles) { > + dev_dbg(cpts->dev, "%s: edge %llu during enable\n", > + __func__, edge); > + ret = -EAGAIN; > + goto disable; > + }
[ ... ]
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cove…%40jclark.com