Re: [PATCH net v10 07/10] can: rockchip_canfd: serialize TX with bus-off and restart
From: Cunhao Lu
Date: Sat Nov 21 2026 - 03:05:57 EST
Hi,
> [Severity: Low]
> This isn't a bug introduced by this patch, but can priv->tc be updated
> here while the IRQ handler is reading it?
>
> [...]
>
> timecounter_read() writes cycle_last, frac and nsec as separate stores.
> Suppose the worker runs on one CPU while the CAN IRQ converts a timestamp
> on another. Can the conversion then combine a new cycle_last with an old
> nsec and produce a wrong hardware timestamp?
Yes, at 07/10 it can. This patch drains timestamp work and IRQ handlers
before restart reinitializes the timecounter. It does not serialize the
worker with timestamp conversion during normal operation. Patch 09/10
puts timecounter_read() and timecounter_init() under timestamp_lock;
10/10 takes the same lock around timecounter_cyc2time() in the IRQ path.
> Separately, the bus-off path in rkcanfd_chip_stop() only does a non-sync
> cancel:
>
> rkcanfd_timestamp_stop(priv);
> __rkcanfd_chip_stop(priv, state);
>
> Here rkcanfd_timestamp_stop() is cancel_delayed_work(). If the worker is
> already running, it can re-arm itself and keep reading the counter while
> the controller is in reset.
That race also predates 07/10. It is fixed in 09/10: the bus-off path
clears timestamp_active under the same lock the worker holds while
reading the counter. An in-flight read therefore finishes before reset,
and disable_delayed_work() prevents the worker from rearming itself.
> Both appear to be fixed later in this series:
>
> "can: rockchip_canfd: serialize timecounter timestamp conversion" holds
> timestamp_lock around timecounter_cyc2time(), timecounter_read() and
> timecounter_init().
>
> "can: rockchip_canfd: prevent timestamp work from rearming after
> bus-off" uses disable_delayed_work() and a timestamp_active flag.
Best regards,
Cunhao Lu