Linux CAN drivers development
 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 1/2] can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx
Date: Sat, 05 Dec 2026 00:14:39 +0000	[thread overview]
Message-ID: <179642967950.3142.12522487186781373167@kernel.org> (raw)
In-Reply-To: <20261203111103.379929-1-rameshsv06@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

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).

- [High] The patch only partly fixes the KCSAN data race in vcan_tx()
  that it claims to fix.
- [Low] can: vcan: redundant ndo_get_stats64 callback with
  NETDEV_PCPU_STAT_TSTATS

--

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

This commit moves the vcan tx/rx packet and byte counters from plain
dev->stats updates to per-CPU tstats with dev_sw_netstats_tx_add() and
dev_sw_netstats_rx_add(). It also installs dev_get_tstats64() as
ndo_get_stats64, so dev->stats.tx_dropped is still reported.

> diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
> index 76e6b7b5c6a11..15ebd814fe75f 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: High]
Does this fully fix the data race in vcan_tx() that the subject refers to?

Just above this, vcan_tx() still calls can_dropped_invalid_skb(). For an
invalid skb, that helper 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 dev_get_tstats64() installed as ndo_get_stats64, the reader still
goes through netdev_stats_to_stats64(s, &dev->stats). That function reads
each field with atomic_long_read(). So the plain tx_dropped++ can still
race with dev_get_stats(), which is reached from /proc/net/dev,
rtnetlink or sysfs:

vcan_tx()
  can_dropped_invalid_skb()
    dev->stats.tx_dropped++

dev_get_stats()
  dev_get_tstats64()
    netdev_stats_to_stats64()
      atomic_long_read()

KCSAN treats ++ as a compound read-write access, so it would still report
this race under the default config.

vcan can be created with several TX queues and is not LLTX. Could two
CPUs then run this increment at the same time and lose updates?

The commit message relies on this counter:

  "dev_get_tstats64() also preserves dev->stats.tx_dropped updated by
  can_dropped_invalid_skb()"

Would it make sense to convert can_dropped_invalid_skb() to
DEV_STATS_INC(dev, tx_dropped) as part of this fix?

An invalid frame sent to a vcan device through AF_PACKET, for example one
with the wrong length or protocol, would reach this path. The selftest in
the series ("selftests: net: can: add vcan concurrent tx/stats test")
only sends valid CAN_RAW frames, so it does not exercise this path.

[ ... ]

> @@ -161,6 +155,7 @@ static int vcan_change_mtu(struct net_device *dev, int new_mtu)
>  static const struct net_device_ops vcan_netdev_ops = {
>  	.ndo_start_xmit = vcan_tx,
>  	.ndo_change_mtu = vcan_change_mtu,
> +	.ndo_get_stats64 = dev_get_tstats64,
>  };
>  
>  static const struct ethtool_ops vcan_ethtool_ops = {

[Severity: Low]
Is the explicit ndo_get_stats64 assignment needed here?

vcan_setup() now sets dev->pcpu_stat_type to NETDEV_PCPU_STAT_TSTATS.
With that set, dev_get_stats() in net/core/dev.c already calls
dev_get_tstats64() itself when the driver provides neither
ndo_get_stats64 nor ndo_get_stats:

net/core/dev.c:dev_get_stats() {
    ...
	} else if (dev->pcpu_stat_type == NETDEV_PCPU_STAT_TSTATS) {
		dev_get_tstats64(dev, storage);
    ...
}

Because the callback is set, dev_get_stats() takes the
ops->ndo_get_stats64 branch instead. That branch does a
memset(storage, 0, sizeof(*storage)) and an indirect call. Then
dev_get_tstats64() overwrites and zero-pads the whole buffer through
netdev_stats_to_stats64() anyway, so the memset is wasted work.

The reported values are identical either way, so this is only a
small cleanup. Drivers that opt into NETDEV_PCPU_STAT_TSTATS normally
leave ndo_get_stats64 unset and let the core handle the collection.

Could this line be dropped, with the commit message updated so it no
longer says dev_get_tstats64() is wired up explicitly? The core path
still goes through dev_get_tstats64(), so dev->stats.tx_dropped from
can_dropped_invalid_skb() is still reported.

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

      parent reply	other threads:[~2026-12-05  0:14 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   ` [PATCH v2 1/2] can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx netdev-bot+sashiko
2026-12-05  0:14 ` netdev-bot+sashiko [this message]

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=179642967950.3142.12522487186781373167@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox