From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796429680; b=WUA/No4wC8maLVCeAdxwiG9D2NIlQtxMRthLRQZs1MAOZgPFhtJh/HQhRY9tvhF10so9 V89Q7OZGC1L9EgKlqtGNj2jXdPD/oLn2x0unFGpAcp2QML+p/Yo1c95wFl1GQSRbBBhru qy8ZV3kq65oSWmDw5HXMxEFMIg6ifjkFBGmRgJ00qpnmGMyrVFwuyFryaplI3ZvNJxu5C uMLuViUta94WO7flMDmfE2K12nVqZgY4665JnDTjhLYcSx0uLqMY4/eFjmhxUumhkaDOD 5rfL4R3lTYs5/9yW0pqaBQyOeZ02cWlAEvRECtmgn1+GxEAIC61Tbv2rE1eEhBp9nSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796429680; 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=j7DtvzJez3dV6pbAYV+3OtzKtosN1f+A6v+lj7NFddE=; b=FqYyKuPUCCXSkNGWizQnofZI+3pINbngUrlB9EB/hPTELRpq4H0tTjCtmfdx1T46FZjs Zd1kF8/9mrGcyVxrqeMBvZzA1EomFV7pdlLOv7zH+s7MJNoVCHSXXB2IAzVsi1KmRAkg9 nfzfEhdnD/BpKMwqc6gYD+SYhCFOZA1NMsMWYWbS3mUSkJWNcYV5YJqCRTTJJYJjzK6o3 GVYzYKJRYyVEdXgTcE7zVc+SBIXAYrtFyaXvms/gewon4h1xjz87jNGRHX9teFmlgsk8B 5e0NG/yaAn0+FcKCnZ0kUewO2ZLCH10xQWN/e00aU1JUywfhVIuMnt3BSebl/DDBiwQ== 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=O5i3Ms9z; arc=none smtp.remote-ip=100.103.45.18 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 AB8CD606A322 for ; Sat, 5 Dec 2026 00:14:40 +0000 (UTC) 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=O5i3Ms9z Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB00F1F0092B; Sat, 5 Dec 2026 00:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796429680; bh=j7DtvzJez3dV6pbAYV+3OtzKtosN1f+A6v+lj7NFddE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=O5i3Ms9zLpuNyVTpyfaC+Weg5Vghwlm+MN5QAd19Q8ZOilt1HdvPHk2RMRVKrzYia KK2p0/YpqJjOdkD7vESzdaRGfL7Xmp1IGaqbWkE4G7uFkw18u1GgxY+PcmW4fkmOtw N8rwNZsL09bShQsruRk6JJjXieOHGv065IrfeZ1DiX9DhSbKAhrYaOCaByEql90J/d RVEe87Eohn18JqORcnu//Z04UbflgeYNnqs8pWrWa5+8gKF9O02I1nTSoIo5ouZky1 Sylg1xrCVwlpDlxmnZevCMAeF38zG9aWRqsffLfCpMw944SvTQbUPHiZ2o1b/MyCeF KJYfrfwGjIa5w== Subject: Re: [PATCH 1/2] can: vcan: use per-CPU stats to fix KCSAN data-race in vcan_tx 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 Date: Sat, 05 Dec 2026 00:14:39 +0000 Message-ID: <179642967950.3142.12522487186781373167@kernel.org> In-Reply-To: <20261203111103.379929-1-rameshsv06@gmail.com> References: <20261203111103.379929-1-rameshsv06@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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