All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: rameshsv06@gmail.com
Cc: mkl@pengutronix.de, mailhol@kernel.org,
	linux-can@vger.kernel.org, rameshkumar.t@phytecembedded.in,
	kuba@kernel.org
Subject: Re: [PATCH v2 1/2] can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx
Date: Sat, 05 Dec 2026 00:41:58 +0000	[thread overview]
Message-ID: <179643131859.3142.7946077821412216658@kernel.org> (raw)
In-Reply-To: <20261203120559.421646-1-rameshsv06@gmail.com>

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] The fix is incomplete: vcan_tx() still makes a plain, non-
  atomic dev->stats update.

--

can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx

This patch converts vcan to NETDEV_PCPU_STAT_TSTATS. The plain dev->stats
tx/rx packet and byte updates in vcan_tx() and vcan_rx() become
dev_sw_netstats_tx_add() and dev_sw_netstats_rx_add() calls. Reporting
goes through the core dev_get_tstats64() path, so the dev->stats.tx_dropped
value from can_dropped_invalid_skb() still shows up in the totals.

> diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
> index 76e6b7b5c6a11..0108c674262ee 100644
> --- a/drivers/net/can/vcan.c
> +++ b/drivers/net/can/vcan.c

[ ... ]

> @@ -93,8 +89,7 @@ static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev)
>  		return NETDEV_TX_OK;
>  
>  	len = can_skb_get_data_len(skb);
> -	stats->tx_packets++;
> -	stats->tx_bytes += len;
> +	dev_sw_netstats_tx_add(dev, 1, len);

[Severity: Medium]
Does this conversion fully close the KCSAN race in vcan_tx()?

The return just above comes from the can_dropped_invalid_skb() check at
the top of vcan_tx(). For an invalid frame, that helper still does a plain
read-modify-write on dev->stats:

drivers/net/can/dev/skb.c:can_dropped_invalid_skb() {
    ...
inval_skb:
	dev_kfree_skb_any(skb);
	dev->stats.tx_dropped++;
	return true;
}

With NETDEV_PCPU_STAT_TSTATS set, the reader path is
dev_get_stats()->dev_get_tstats64()->netdev_stats_to_stats64(s,
&dev->stats). That reads the same fields with atomic_long_read(), and it
can run on any CPU, for example from rtnetlink or /proc/net/dev. Can this
still trigger a KCSAN report against the tx path?

Two writers can also race here and lose tx_dropped increments. vcan has no
ndo_select_queue, and rtnl_create_link() accepts IFLA_NUM_TX_QUEUES. So
"ip link add type vcan numtxqueues N" lets vcan_tx() run on several CPUs
at once under different txq locks.

A CAP_NET_RAW sender can reach this path. One example is an AF_PACKET
socket bound to vcan that sends a frame whose skb->protocol is not
ETH_P_CAN, ETH_P_CANFD or ETH_P_CANXL, or whose length is wrong.

Could can_dropped_invalid_skb() use DEV_STATS_INC(dev, tx_dropped)? If
not, could the commit message say this counter is out of scope? Right now
it only says:

    and dev->stats.tx_dropped
    updated by can_dropped_invalid_skb() is preserved.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203120559.421646-1-rameshsv06%40gmail.com

  parent reply	other threads:[~2026-12-05  0:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 11:11 [PATCH 1/2] can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx T S Rameshkumar
2026-12-03 11:11 ` [PATCH 2/2] selftests: net: can: add vcan concurrent tx/stats test T S Rameshkumar
2026-12-03 11:23   ` sashiko-bot
2026-12-05  0:14   ` netdev-bot+sashiko
2026-12-03 11:23 ` [PATCH 1/2] can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx sashiko-bot
2026-12-03 12:05 ` [PATCH v2 " T S Rameshkumar
2026-12-03 12:05   ` [PATCH v2 2/2] selftests: net: can: add vcan concurrent tx/stats test T S Rameshkumar
2026-12-03 12:37     ` sashiko-bot
2026-12-03 12:50     ` Oliver Hartkopp
2026-12-05  0:41     ` netdev-bot+sashiko
2026-12-05  0:41   ` netdev-bot+sashiko [this message]
2026-12-05  0:14 ` [PATCH 1/2] can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx 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=179643131859.3142.7946077821412216658@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=rameshkumar.t@phytecembedded.in \
    --cc=rameshsv06@gmail.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.