All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cunhao Lu" <1579567540@qq.com>
Cc: linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH net v3 4/5] can: rockchip_canfd: prevent timestamp work from rearming after bus-off
Date: Wed, 14 Oct 2026 13:35:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-171361@kernel.org> (raw)
In-Reply-To: <20261014-rockchip-canfd-restart-close-v3-4-f0eb41090242@qq.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] can: rockchip_canfd: torn read and data race on timecounter state
--

commit ba848a69df4d87c5d955ac1607d9318a5bab577e
Author: Cunhao Lu <1579567540@qq.com>

can: rockchip_canfd: prevent timestamp work from rearming after bus-off

This commit adds a timestamp_lock and timestamp_active flag to prevent the
timestamp work from requeuing itself after cancellation. It synchronizes the
worker's active check, timecounter read, and self-requeue.

> diff --git a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> index ad582afbbd682..0fa791849c957 100644
> --- a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> +++ b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> @@ -30,18 +30,27 @@ static void rkcanfd_timestamp_work(struct work_struct *work)
>  {
>  	const struct delayed_work *delayed_work = to_delayed_work(work);
>  	struct rkcanfd_priv *priv;
> +	unsigned long flags;
>  
>  	priv = container_of(delayed_work, struct rkcanfd_priv, timestamp);
> -	timecounter_read(&priv->tc);
> -
> -	schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies);
> +	spin_lock_irqsave(&priv->timestamp_lock, flags);
> +	if (priv->timestamp_active) {
> +		timecounter_read(&priv->tc);

[Severity: Medium]
Does this leave a data race with datapath readers?

The worker thread updates the timecounter state here while holding
timestamp_lock. However, the RX/TX datapath calls
rkcanfd_skb_set_timestamp() which reads the timecounter locklessly:

rkcanfd_skb_set_timestamp() {
    ...
    ns = timecounter_cyc2time(&priv->tc, timestamp);
    ...
}

Since timecounter_read() modifies the timecounter state non-atomically,
can the concurrent lockless read result in torn reads or an inconsistent
observation of the cycle counter and nanoseconds, especially on 32-bit
platforms?

> +
> +		/* Serialize requeueing with timestamp_stop(). */
> +		schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies);
> +	}
> +	spin_unlock_irqrestore(&priv->timestamp_lock, flags);
>  }

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261014-rockchip-canfd-restart-close-v3-0-f0eb41090242@qq.com?part=4

  reply	other threads:[~2026-10-14 13:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 13:24 [PATCH net v3 0/5] can: fix bus-off restart and device close races Cunhao Lu
2026-10-14 13:24 ` Cunhao Lu via B4 Relay
2026-10-14 13:24 ` Cunhao Lu via B4 Relay
2026-10-14 13:24 ` [PATCH net v3 1/5] can: dev: prevent bus-off recovery when the interface is not running Cunhao Lu
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:24 ` [PATCH net v3 2/5] can: dev: add close_candev_cancel_restart_sync() Cunhao Lu
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:24 ` [PATCH net v3 3/5] can: rockchip_canfd: cancel bus-off restart before closing the device Cunhao Lu
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:35   ` sashiko-bot
2026-10-14 13:24 ` [PATCH net v3 4/5] can: rockchip_canfd: prevent timestamp work from rearming after bus-off Cunhao Lu
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:35   ` sashiko-bot [this message]
2026-10-14 13:24 ` [PATCH net v3 5/5] can: rockchip_canfd: serialize TX with bus-off and restart Cunhao Lu
2026-10-14 13:24   ` Cunhao Lu via B4 Relay
2026-10-14 13:24   ` Cunhao Lu via B4 Relay

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=sashiko-outbox-171361@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=1579567540@qq.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=socketcan@hartkopp.net \
    /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.