🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13146

Re: [PATCH net v8 09/10] can: rockchip_canfd: prevent timestamp work from rearming after bus-off

#13146
From: netdev-bot+sashiko
Date: Mon, 09 Nov 2026 11:37
148 lines
13844 bytes
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] The patch is tagged Cc: stable but does not say that it depends
  on the preceding commit "can: rockchip_canfd: serialize TX with bus-…
- [Low] The commit message gives only one consequence: the worker can
  "keep polling while the controller remains bus-off".

Pre-existing issues:
- [Medium] Concern: in this commit, rkcanfd_skb_set_timestamp() reads
  priv->tc through timecounter_cyc2time() from hardirq context without…

--

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

This adds timestamp_lock and a timestamp_active flag to rkcanfd_priv.
With them, the timestamp worker reads the timecounter and requeues itself
only while timestamping is active. The start and stop helpers set or clear
the flag under the lock, and the work is cancelled outside it.

> The bus-off IRQ cancels timestamp work asynchronously. If the worker
> is already running, it can requeue itself after cancellation and keep
> polling while the controller remains bus-off.

[Severity: Low]
Can the commit message name a user-visible consequence of this polling?

The only trigger is the bus-off path:

rkcanfd_handle_state_error_int()
  rkcanfd_chip_stop()
    rkcanfd_timestamp_stop()
      cancel_delayed_work()

As far as I can tell, every way out of bus-off already stops the worker
synchronously:

- Restart through rkcanfd_set_mode() calls rkcanfd_timestamp_stop_sync()
  before rkcanfd_chip_start().
- Close goes through rkcanfd_chip_stop_sync().

In both cases cancel_delayed_work_sync() handles a work item that requeues
itself.

Runtime PM is held until after rkcanfd_chip_stop_sync() in rkcanfd_stop().
That means the stray worker never reads a clock-gated controller.

Anything it adds to priv->tc is thrown away when rkcanfd_timestamp_start()
runs timecounter_init() again.

Given the Cc: stable tag, could the message either describe a concrete
consequence or say that this is a hardening change?

> diff --git a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c
> index ad582afbbd682..1d2a122770dc8 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)

[ ... ]

>  void rkcanfd_timestamp_work_init(struct rkcanfd_priv *priv)
>  {
> +	spin_lock_init(&priv->timestamp_lock);
> +	priv->timestamp_active = false;
>  	INIT_DELAYED_WORK(&priv->timestamp, rkcanfd_timestamp_work);
>  }
>  
> +/* The caller must quiesce IRQs and timestamp work before reconfiguration. */
>  void rkcanfd_timestamp_init(struct rkcanfd_priv *priv)

[Severity: Low]
Should the commit message say that this depends on the preceding commit,
"can: rockchip_canfd: serialize TX with bus-off and restart"?

That commit added rkcanfd_timestamp_work_init() and its one-time call from
rkcanfd_probe(). It also moved INIT_DELAYED_WORK() out of
rkcanfd_timestamp_init().

Before it, the work is initialized on every rkcanfd_chip_start(), which
means on every open and every restart:

rkcanfd_timestamp_init() {
    ...
	priv->work_delay_jiffies = div_u64(work_delay_ns, 3u * NSEC_PER_SEC / HZ);
	INIT_DELAYED_WORK(&priv->timestamp, rkcanfd_timestamp_work);
    ...
}

The new comment on rkcanfd_timestamp_init() also relies on code from that
commit: the synchronize_irq() and rkcanfd_timestamp_stop_sync() calls in
rkcanfd_set_mode().

On its own, this patch won't apply to stable trees. An obvious manual
backport would put spin_lock_init() next to the old INIT_DELAYED_WORK().
That would re-initialize timestamp_lock on every restart, while an old
worker may still hold it.

Other patches in this series have a "Backports must include ..."
paragraph. Would a similar note help here?

[ ... ]

> diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h
> index 3664124a8da25..078876769a05d 100644
> --- a/drivers/net/can/rockchip/rockchip_canfd.h
> +++ b/drivers/net/can/rockchip/rockchip_canfd.h
> @@ -477,6 +477,8 @@ struct rkcanfd_priv {
>  
>  	/* Serialize TX submission/completion with bus-off and restart. */
>  	spinlock_t tx_lock;
> +	/* Protects timestamp_active and worker reads/requeueing. */
> +	spinlock_t timestamp_lock;

[Severity: Medium]
This is a pre-existing issue, not one introduced by this patch.
priv->tc still has a reader that does not take the lock.
rkcanfd_skb_set_timestamp() calls timecounter_cyc2time() from hardirq
context without timestamp_lock:

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

Meanwhile, timecounter_read() in rkcanfd_timestamp_work() and
timecounter_init() in rkcanfd_timestamp_start() now change tc under
timestamp_lock.

If a conversion on another CPU races with the worker, can it combine a
new cycle_last with an old nsec? That would give wrong or non-monotonic
hardware timestamps on RX, TX-done and error frames.

The last patch in the series fixes this: "can: rockchip_canfd: serialize
timecounter timestamp conversion". It takes timestamp_lock around
timecounter_cyc2time() in rkcanfd_skb_set_timestamp(). It also updates
this comment to "Protects tc, timestamp_active and worker requeueing."

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261108-rockchip-canfd-restart-close-v8-0-3e7a23fd9eae%40qq.com
Technical Details
Message-ID: <179422427089.994134.14595272665034265410@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359243-linux-kernel-netdev=dewy.ru
References: <20261108-rockchip-canfd-restart-close-v8-9-3e7a23fd9eae@qq.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359243-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v8 09/10] can: rockchip_canfd: prevent timestamp work
 from rearming after bus-off
Date: Mon, 09 Nov 2026 11:37:50 +0000
Organization: Usenet Network
Message-ID: <179422427089.994134.14595272665034265410@kernel.org>
References: <20261108-rockchip-canfd-restart-close-v8-9-3e7a23fd9eae@qq.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="341641"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ttAjSxyhuVhN5UOCYoNS8eHt+80= sha256:9OPbzT73sUKfyn8rk2p1RKQohG5xN3Nbq9nKC4cSnkU=
	sha1:jqM4leuV3jw47xbpfEIRIWwGMG8= sha256:j0cuuBz6ZOc6Ba5HqpCXC26wS0PPOjTBGhsnF9mMHlQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 266951137B5; Mon,  9 Nov 2026 14:41:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.301
X-Spam-Status: No, score=-2.301 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001,
	DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id RmoNjHGfbD3n;
	Mon,  9 Nov 2026 14:41:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359243-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 3580F1137A8; Mon,  9 Nov 2026 14:41:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 671D6A3159; Mon,  9 Nov 2026 11:38:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794224279;
	b=W8M8NoJgbYJKFxTs+G1Lz6WlEEVXjI114HEa+O6F2zA/j8Mja3qjs3rzlLKQu15yyXMc
	 1djirG6PG9nmu9h/1AAM4miNZ9Sw+hdzKTaWtL8MLEHla4ak66sIP+OHDSVxgR7YuEHVC
	 h87rKAyWOsP3zN4WHmk1fU9Q6rez/nPmWSnbhRZW2r63qKfLj6hnly0ZS+G6Ql0nNWA0J
	 IxOulKp7X53bhEEtAgwdEgnG7hTdnVTQG+yRc46IYlWuvoDpgC2gmp0x1mf7kjyVSJsUC
	 SUMi5WjGkr8V3Tt1QrGMSysdrvWTFoLwkkNYgyKh28qoetL1cNh8S26IASwXYSnBC4Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794224279;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Y3RNcp4pnRlKxAjxnzkLeSDjNbMJzP30RaISr73JjaU=;
	b=nZY6MjZYbWbpRmZgV7huRfuqQSWcD+/8zg/0BloaTcHUus8HPgtnyvXqH2eO2yaCt48q
	 +CwBJDf82f+YxcSPQxZRGepWfY8W/BkffJm93kVpBGutcCxZ9u6xvgjOqEit2RW5wUKE3
	 phKvPBBpeZzZjnfpyBYd8eVxeVgbv0B8zfE6dXrUWLzYrCOP/AXLvrUyNekSzxFUqFiJA
	 eHL4aRnBTh/jziRllsWEJMoTRJOFUEDndmiT6XdXb2B9oPI7tazSp/H9h7Hm1O3fCUoRl
	 eEkeqkYQJdc81XJtIUQb7ZW1cLfdnY9io5BupVYgkAjwcHYlVWD1TK1wxU2mlNOvMjw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e7UoJ4qU;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 02310606D82B;
	Mon,  9 Nov 2026 11:37:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e7UoJ4qU
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794224273;
	b=EDizFNsl29ItOByQpRbdOgo0c54CDnTsUd+Umn1uNGdkWKRlv0m03BBVqfeRa6oU+NBt
	 yPHHJ3Bfc5cPiCAfVYW8dKHKQXoGMjGDgbcbK9X2QLuffRuOJeL04VHj43hjpaA2UJmMe
	 OtXAV6wgqc3Bc7C/eCtLuloahl4j9kTRWLDDgjRHcgM+0ilZoIZNomWHEsXon8hsR7Fqf
	 ijslIJOcqeOJcrfxEBUzVh+PT5f+5uhUWmZbV9fEmVqGhefltvhBj5yGX5HMiEpWDSt+5
	 n0C0GAIHLRJnfdnAUB7Aak35rf0wgX42E6oku2w9Fmc4X3sPo5Jteeqp5++zw4GR2mA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794224273;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Y3RNcp4pnRlKxAjxnzkLeSDjNbMJzP30RaISr73JjaU=;
	b=zCAV/5fFwkghedoTo8zexcWS8YGI8/K04yfvfss00dBErGYk8QQK//MAnc8HYvrpTYE/
	 HP9DLT1d9UCOI9p05j+Xy1/mgO9G5rw7pRL5lKQTM85TtPXZHOUuIugxj2yZ+MZibP38A
	 7ksKU7yzzT0bY4AlsGjO7ANPVQPW9yo8k/h/N3JppGeW0OHa6pY87psknAy990ydvK6iR
	 Igmzqa65nb+8JLf3N557cXJvC1wnJUFm278mGm1EtsX2pSN3dUcqO+rCKp5apCryRRvaw
	 uHZ2ToR/PM+FKru9zR+d/EmsJphIIt7Kyd1PcrJescjOnaJ6E4bkP2XM9luJRcTWF7A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e7UoJ4qU;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D66EA606A33E;
	Mon,  9 Nov 2026 11:37:52 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54AE21F008A4;
	Mon,  9 Nov 2026 11:37:51 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794224272;
	bh=Y3RNcp4pnRlKxAjxnzkLeSDjNbMJzP30RaISr73JjaU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=e7UoJ4qUmetFXicfvMj8lPo0PrvfWYyqNGOclNmOE61ADo7Ev5ENGKxyb2g0mBSxj
	 x5CS7Gpx7hTutSFF1uRljrxkOvT+sGm9RAo2PofvivVJOa4ofl64azJqvqPELGIEAd
	 jSjfSjG688iFxZ4gTfAPOScmUOzaDq5oUFvhloVmXgVXwlf0XHO6bmGnhi6TcMLpgS
	 ultz0EvbSLsISi6FIL6lm2jCR3MjXWIkoWkuESbElTkf2T5lv447srR0jWBNX8Q+Bv
	 3YU+PgFi46QH7giBAc4jZI0wRxYZCMLbEgoq9XJp+VlRUNAf8WyV4v0RbYjk5lo6TM
	 sBAEqO3v4mQ/Q==
X-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, netdev@vger.kernel.org,
 linux-doc@vger.kernel.org
X-In-Reply-To: <20261108-rockchip-canfd-restart-close-v8-9-3e7a23fd9eae@qq.com>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list