From: netdev-bot+sashiko@kernel.org
To: 1579567540@qq.com
Cc: mkl@pengutronix.de, kernel@pengutronix.de, mailhol@kernel.org,
heiko@sntech.de, socketcan@hartkopp.net, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
rdunlap@infradead.org, wg@grandegger.com,
linux-can@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net v10 07/10] can: rockchip_canfd: serialize TX with bus-off and restart
Date: Sat, 21 Nov 2026 00:02:21 +0000 [thread overview]
Message-ID: <179521934168.3131.3588718854244956629@kernel.org> (raw)
In-Reply-To: <20261119-rockchip-canfd-restart-close-v10-7-df23913aa33a@qq.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In struct rkcanfd_priv
(drivers/net/can/rockchip/rockchip_canfd.h), the patch replaces the…
Pre-existing issues:
- [Low] At this commit, priv->tc is read with no lock from the hardirq
handler, via rkcanfd_skb_set_timestamp() -> timecounter_cyc2time(), on…
--
can: rockchip_canfd: serialize TX with bus-off and restart
This patch uses tx_lock and a new tx_enabled flag to drain TX and RX-side
echo users before CAN_STATE_BUS_OFF is published, and it drops consumed RX
FIFO entries while TX is disabled. Before reinitializing the controller,
restart masks device interrupts, suspends the shared IRQ handler through
irq_suspended and synchronize_irq(), and drains the timestamp work.
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111-rockchip-canfd-restart-close-v9-0-6643f3825ba3%40qq.com
> diff --git a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> index 72774cd2f94b7..ad582afbbd682 100644
> --- a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> +++ b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> @@ -37,6 +37,11 @@ static void rkcanfd_timestamp_work(struct work_struct *work)
> schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies);
> }
>
> +void rkcanfd_timestamp_work_init(struct rkcanfd_priv *priv)
> +{
> + INIT_DELAYED_WORK(&priv->timestamp, rkcanfd_timestamp_work);
> +}
> +
[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?
rkcanfd_timestamp_work() updates the timecounter without taking a lock:
rkcanfd_timestamp_work() {
priv = container_of(delayed_work, struct rkcanfd_priv, timestamp);
timecounter_read(&priv->tc);
schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies);
}
The hardirq handler reads the same timecounter, also without a lock. It
does this on the RX, TX-done and error-skb paths through
rkcanfd_skb_set_timestamp():
ns = timecounter_cyc2time(&priv->tc, timestamp);
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?
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.
This patch adds rkcanfd_timestamp_stop_sync() only on the restart path.
That covers timecounter_init(), but not these two cases.
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.
> diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h
> index 077dd57d42de9..8fdb59025bfaf 100644
> --- a/drivers/net/can/rockchip/rockchip_canfd.h
> +++ b/drivers/net/can/rockchip/rockchip_canfd.h
> @@ -475,7 +475,7 @@ struct rkcanfd_priv {
> struct can_rx_offload offload;
> struct net_device *ndev;
>
> - /* Protect running TX/RX echo state, queue updates and TX commands. */
> + /* Serialize TX submission/completion with bus-off and restart. */
> spinlock_t tx_lock;
[ ... ]
> @@ -485,6 +485,9 @@ struct rkcanfd_priv {
> u32 reg_int_mask_default;
> struct rkcanfd_devtype_data devtype_data;
>
> + bool tx_enabled;
> + bool irq_suspended;
> +
[Severity: Low]
This isn't a bug, but the new tx_lock comment covers less than the lock
actually protects.
tx_lock still serializes TX command writes. rkcanfd_start_xmit_write_cmd()
asserts it because rkcanfd_start_xmit() and the RX-side
rkcanfd_xmit_retry() share the erratum-12 MODE/CMD/MODE sequence:
rkcanfd_start_xmit_write_cmd() {
lockdep_assert_held(&priv->tx_lock);
if (priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_12)
rkcanfd_write(priv, RKCANFD_REG_MODE, priv->reg_mode_default |
...
}
The lock also still covers the echo ring and the queue/BQL updates in
rkcanfd_tx_tail_is_eff(), rkcanfd_get_effective_tx_free(),
rkcanfd_rxstx_filter() and rkcanfd_handle_tx_done_one().
Could the comment keep listing the TX command and echo ring duties?
Also, nothing says how the two new fields are synchronized. tx_enabled is
only accessed under tx_lock. irq_suspended takes no lock and relies on the
WRITE_ONCE()/smp_store_release() and smp_load_acquire() pairing plus
synchronize_irq().
Would a short note on each field help? At the end of the series the
tx_lock comment is still narrow, and the later tx_retry_enabled and
tx_retry_pending fields have no comment either.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119-rockchip-canfd-restart-close-v10-0-df23913aa33a%40qq.com
WARNING: multiple messages have this Message-ID (diff)
From: netdev-bot+sashiko@kernel.org
To: 1579567540@qq.com
Cc: mkl@pengutronix.de, kernel@pengutronix.de, mailhol@kernel.org,
heiko@sntech.de, socketcan@hartkopp.net, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
rdunlap@infradead.org, wg@grandegger.com,
linux-can@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net v10 07/10] can: rockchip_canfd: serialize TX with bus-off and restart
Date: Sat, 21 Nov 2026 00:02:21 +0000 [thread overview]
Message-ID: <179521934168.3131.3588718854244956629@kernel.org> (raw)
In-Reply-To: <20261119-rockchip-canfd-restart-close-v10-7-df23913aa33a@qq.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In struct rkcanfd_priv
(drivers/net/can/rockchip/rockchip_canfd.h), the patch replaces the…
Pre-existing issues:
- [Low] At this commit, priv->tc is read with no lock from the hardirq
handler, via rkcanfd_skb_set_timestamp() -> timecounter_cyc2time(), on…
--
can: rockchip_canfd: serialize TX with bus-off and restart
This patch uses tx_lock and a new tx_enabled flag to drain TX and RX-side
echo users before CAN_STATE_BUS_OFF is published, and it drops consumed RX
FIFO entries while TX is disabled. Before reinitializing the controller,
restart masks device interrupts, suspends the shared IRQ handler through
irq_suspended and synchronize_irq(), and drains the timestamp work.
Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111-rockchip-canfd-restart-close-v9-0-6643f3825ba3%40qq.com
> diff --git a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> index 72774cd2f94b7..ad582afbbd682 100644
> --- a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> +++ b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> @@ -37,6 +37,11 @@ static void rkcanfd_timestamp_work(struct work_struct *work)
> schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies);
> }
>
> +void rkcanfd_timestamp_work_init(struct rkcanfd_priv *priv)
> +{
> + INIT_DELAYED_WORK(&priv->timestamp, rkcanfd_timestamp_work);
> +}
> +
[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?
rkcanfd_timestamp_work() updates the timecounter without taking a lock:
rkcanfd_timestamp_work() {
priv = container_of(delayed_work, struct rkcanfd_priv, timestamp);
timecounter_read(&priv->tc);
schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies);
}
The hardirq handler reads the same timecounter, also without a lock. It
does this on the RX, TX-done and error-skb paths through
rkcanfd_skb_set_timestamp():
ns = timecounter_cyc2time(&priv->tc, timestamp);
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?
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.
This patch adds rkcanfd_timestamp_stop_sync() only on the restart path.
That covers timecounter_init(), but not these two cases.
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.
> diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h
> index 077dd57d42de9..8fdb59025bfaf 100644
> --- a/drivers/net/can/rockchip/rockchip_canfd.h
> +++ b/drivers/net/can/rockchip/rockchip_canfd.h
> @@ -475,7 +475,7 @@ struct rkcanfd_priv {
> struct can_rx_offload offload;
> struct net_device *ndev;
>
> - /* Protect running TX/RX echo state, queue updates and TX commands. */
> + /* Serialize TX submission/completion with bus-off and restart. */
> spinlock_t tx_lock;
[ ... ]
> @@ -485,6 +485,9 @@ struct rkcanfd_priv {
> u32 reg_int_mask_default;
> struct rkcanfd_devtype_data devtype_data;
>
> + bool tx_enabled;
> + bool irq_suspended;
> +
[Severity: Low]
This isn't a bug, but the new tx_lock comment covers less than the lock
actually protects.
tx_lock still serializes TX command writes. rkcanfd_start_xmit_write_cmd()
asserts it because rkcanfd_start_xmit() and the RX-side
rkcanfd_xmit_retry() share the erratum-12 MODE/CMD/MODE sequence:
rkcanfd_start_xmit_write_cmd() {
lockdep_assert_held(&priv->tx_lock);
if (priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_12)
rkcanfd_write(priv, RKCANFD_REG_MODE, priv->reg_mode_default |
...
}
The lock also still covers the echo ring and the queue/BQL updates in
rkcanfd_tx_tail_is_eff(), rkcanfd_get_effective_tx_free(),
rkcanfd_rxstx_filter() and rkcanfd_handle_tx_done_one().
Could the comment keep listing the TX command and echo ring duties?
Also, nothing says how the two new fields are synchronized. tx_enabled is
only accessed under tx_lock. irq_suspended takes no lock and relies on the
WRITE_ONCE()/smp_store_release() and smp_load_acquire() pairing plus
synchronize_irq().
Would a short note on each field help? At the end of the series the
tx_lock comment is still narrow, and the later tx_retry_enabled and
tx_retry_pending fields have no comment either.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119-rockchip-canfd-restart-close-v10-0-df23913aa33a%40qq.com
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
next prev parent reply other threads:[~2026-11-21 0:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:39 [PATCH net v10 00/10] can: fix Rockchip TX stalls and bus-off restart/close races Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-19 8:39 ` [PATCH net v10 01/10] can: rockchip_canfd: prevent TX stall on echo skb failure Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-19 8:39 ` [PATCH net v10 02/10] can: rockchip_canfd: serialize TX state and command writes Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-19 8:39 ` [PATCH net v10 03/10] can: dev: check netif_running() before bus-off recovery Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-19 8:39 ` [PATCH net v10 04/10] can: dev: add close_candev_cancel_restart_sync() Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-19 8:39 ` [PATCH net v10 05/10] can: rockchip_canfd: cancel bus-off restart before closing the device Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-21 0:02 ` netdev-bot+sashiko
2026-11-21 0:02 ` netdev-bot+sashiko
2026-11-19 8:39 ` [PATCH net v10 06/10] can: rockchip_canfd: disable RX offload on open failure Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-19 8:39 ` [PATCH net v10 07/10] can: rockchip_canfd: serialize TX with bus-off and restart Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-21 0:02 ` netdev-bot+sashiko [this message]
2026-11-21 0:02 ` netdev-bot+sashiko
2026-11-19 8:39 ` [PATCH net v10 08/10] can: rockchip_canfd: retry the outstanding TX buffer Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-21 0:02 ` netdev-bot+sashiko
2026-11-21 0:02 ` netdev-bot+sashiko
2026-11-19 8:39 ` [PATCH net v10 09/10] can: rockchip_canfd: prevent timestamp work from rearming after bus-off Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-19 8:39 ` [PATCH net v10 10/10] can: rockchip_canfd: serialize timecounter timestamp conversion Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu via B4 Relay
2026-11-19 8:39 ` Cunhao Lu
2026-11-21 0:02 ` netdev-bot+sashiko
2026-11-21 0:02 ` netdev-bot+sashiko
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=179521934168.3131.3588718854244956629@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=1579567540@qq.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=heiko@sntech.de \
--cc=horms@kernel.org \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=socketcan@hartkopp.net \
--cc=stable@vger.kernel.org \
--cc=wg@grandegger.com \
/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.