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 2/2] selftests: net: can: add vcan concurrent tx/stats test
Date: Sat, 05 Dec 2026 00:14:40 +0000	[thread overview]
Message-ID: <179642968042.3142.2861763799301446361@kernel.org> (raw)
In-Reply-To: <20261203111103.379929-2-rameshsv06@gmail.com>

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

Critical: 0 · High: 0 · Medium: 2 · 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).

- [Medium] test_vcan_stats passes the same way on kernels with and
  without the companion fix "can: vcan: use per-CPU stats to fix KCSAN…
- [Medium] test_vcan_stats.sh sets `trap cleanup EXIT` (line 32) before
  it calls `setup` (line 33).
- [Low] The new test_vcan_stats.sh runs `source $net_dir/lib.sh` (line 9,
  i.e. tools/testing/selftests/net/lib.sh), and net/lib.sh in turn…

--

selftests: net: can: add vcan concurrent tx/stats test

This adds a kselftest, test_vcan_stats. It starts four concurrent PF_CAN
raw transmitters on vcan0 while another thread reads /proc/net/dev. It
then checks the exact rx/tx packet and byte counter deltas. A wrapper
script creates the vcan interface and deletes it afterwards.

> diff --git a/tools/testing/selftests/net/can/Makefile b/tools/testing/selftests/net/can/Makefile
> index 5b82e60a03e75..c2e4903b9f43b 100644
> --- a/tools/testing/selftests/net/can/Makefile
> +++ b/tools/testing/selftests/net/can/Makefile
> @@ -3,9 +3,10 @@
>  top_srcdir = ../../../../..
>  
>  CFLAGS += -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include $(KHDR_INCLUDES)
> +LDLIBS += -lpthread
>  
> -TEST_PROGS := test_raw_filter.sh
> +TEST_PROGS := test_raw_filter.sh test_vcan_stats.sh

[Severity: Low]
test_vcan_stats.sh sources $net_dir/lib.sh, and net/lib.sh in turn
sources lib/sh/defer.sh. Should these files be listed in TEST_INCLUDES
here? net/mptcp/Makefile and net/forwarding/Makefile both do this:

TEST_INCLUDES := ../lib.sh $(wildcard ../lib/sh/*.sh)

Only the parent net target ships net/lib.sh, through its TEST_FILES. So
after "make -C tools/testing/selftests TARGETS=net/can install" the
installed script can't source lib.sh. That leaves ksft_skip, check_err,
log_test and tests_run undefined, and the test doesn't run.

test_raw_filter.sh already has the same gap. This patch adds a second
script that depends on lib.sh.

>  
> -TEST_GEN_FILES := test_raw_filter
> +TEST_GEN_FILES := test_raw_filter test_vcan_stats
>  
>  include ../../lib.mk
> diff --git a/tools/testing/selftests/net/can/test_vcan_stats.c b/tools/testing/selftests/net/can/test_vcan_stats.c
> new file mode 100644
> index 0000000000000..1a4f715adead8
> --- /dev/null
> +++ b/tools/testing/selftests/net/can/test_vcan_stats.c
> @@ -0,0 +1,181 @@

[ ... ]

> +static void *stats_reader(void *arg)
> +{
> +	struct net_dev_stats st;
> +
> +	while (!atomic_load(&stop_reader))
> +		read_if_stats(canif, &st);
> +
> +	return NULL;
> +}

[ ... ]

> +	EXPECT_EQ(after.tx_packets - before.tx_packets, exp_pkts);
> +	EXPECT_EQ(after.tx_bytes - before.tx_bytes, exp_bytes);
> +	EXPECT_EQ(after.rx_packets - before.rx_packets, exp_pkts);
> +	EXPECT_EQ(after.rx_bytes - before.rx_bytes, exp_bytes);
> +}

[Severity: Medium]
Can these checks ever fail because of the stats race this test seems to
target?

vcan_setup() sets dev->tx_queue_len = 0, so vcan gets the noqueue
qdisc, and vcan does not set lltx. That means every vcan_tx() call is
serialized by the txq xmit lock:

write()->can_send()->dev_queue_xmit()->__dev_queue_xmit()
    HARD_TX_LOCK(dev, txq, cpu);
    dev_hard_start_xmit()->vcan_tx()

All the tx and rx counter updates in vcan_tx(), and in vcan_rx() for
echo mode, happen inside that one critical section. So the older plain
dev->stats increments already gave exact deltas.

As far as I can tell, these EXPECT_EQ checks pass the same way with or
without the companion change "can: vcan: use per-CPU stats to fix KCSAN
data-race in vcan_tx".

That race is between a serialized writer and the lockless /proc/net/dev
reader. It only shows up as a KCSAN report in dmesg.

stats_reader() throws away every sample and ignores the return value of
read_if_stats(). Nothing in the test looks at dmesg for KCSAN reports.

Could the commit message say which defect this test is meant to catch,
and whether it needs a KCSAN-enabled kernel? Alternatively, could the
test check something the concurrent reader side can actually get wrong?

[ ... ]

> diff --git a/tools/testing/selftests/net/can/test_vcan_stats.sh b/tools/testing/selftests/net/can/test_vcan_stats.sh
> new file mode 100755
> index 0000000000000..1153699cb176b
> --- /dev/null
> +++ b/tools/testing/selftests/net/can/test_vcan_stats.sh
> @@ -0,0 +1,37 @@

[ ... ]

> +setup()
> +{
> +	ip link add name $CANIF type vcan || exit $ksft_skip
> +	ip link set dev $CANIF up
> +}
> +
> +cleanup()
> +{
> +	ip link set dev $CANIF down
> +	ip link delete $CANIF
> +}

[ ... ]

> +trap cleanup EXIT
> +setup

[Severity: Medium]
What happens when "ip link add" fails in setup()? Two ways that can
happen are vcan0 already existing, or CANIF being exported as a real
CAN device such as can0.

setup() then runs exit $ksft_skip. The EXIT trap is already armed, so
cleanup() runs:

	ip link set dev $CANIF down
	ip link delete $CANIF

Won't that take down or delete an interface this script didn't create?
With CANIF=can0 the hardware CAN interface is set down. With a
pre-existing vcan0, the user's interface is deleted.

test_raw_filter.sh uses the same CANIF variable and guards the delete
with:

	if [[ $CANIF == vcan* ]]; then

The new script has no such guard. It also doesn't record whether it
created the link, and it doesn't use a private netns.

-- 
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 [this message]
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 ` [PATCH " 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=179642968042.3142.2861763799301446361@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