All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "T S Rameshkumar" <rameshsv06@gmail.com>
Cc: linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH 2/2] selftests: net: can: add vcan concurrent tx/stats test
Date: Thu, 03 Dec 2026 11:23:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-247669@kernel.org> (raw)
In-Reply-To: <20261203111103.379929-2-rameshsv06@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] selftests: net: can: premature EXIT trap and missing netns
  isolation
- [Medium] selftests: net: can: missing barrier and unchecked reads in
  stats_reader()
- [Low] selftests: net: can: missing CAN_RAW skip handling in test and
  wrapper
--

commit b3f673b3db7d63b8eb092b5a5498ad7f078fc788
Author: T S Rameshkumar <rameshkumar.t@phytecembedded.in>

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

This commit adds a kselftest that spawns concurrent PF_CAN transmitters
on a vcan interface while reading /proc/net/dev in parallel and checks
the resulting rx/tx packet and byte counter deltas.

> 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

[ ... ]

> +static void *tx_worker(void *arg)
> +{
> +	int id = (int)(long)arg;
> +	struct sockaddr_can addr = {};
> +	struct can_frame frame = {};
> +	struct ifreq ifr = {};
> +	int s;
> +
> +	s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
> +	if (s < 0)
> +		return (void *)(long)-errno;

[Severity: Low]
Should this test skip rather than fail when CONFIG_CAN_RAW is disabled?

CONFIG_CAN_VCAN does not depend on or select CONFIG_CAN_RAW, so creating
the vcan interface does not guarantee CAN_RAW socket support.  When
socket() fails with EPROTONOSUPPORT or EAFNOSUPPORT, tx_worker() returns
a negative errno and ASSERT_EQ((long)res, 0) fails the test instead of
probing CAN_RAW upfront and calling SKIP() with a reason string.

In test_vcan_stats.sh, check_err() also treats any non-zero exit status
(including ksft_skip) as a failure, so the wrapper would need to
propagate a skip exit status from test_vcan_stats.

[ ... ]

> +static void *stats_reader(void *arg)
> +{
> +	struct net_dev_stats st;
> +
> +	while (!atomic_load(&stop_reader))
> +		read_if_stats(canif, &st);
> +
> +	return NULL;
> +}
> +
> +TEST(vcan_concurrent_tx_stats)
> +{
> +	struct net_dev_stats before, after;
> +	pthread_t tx[NUM_THREADS], reader;
> +	unsigned long long exp_pkts, exp_bytes;
> +	int ret;
> +
> +	ret = read_if_stats(canif, &before);
> +	ASSERT_EQ(ret, 0)
> +		TH_LOG("failed to read initial stats for %s", canif);
> +
> +	atomic_store(&stop_reader, 0);
> +	ret = pthread_create(&reader, NULL, stats_reader, NULL);
> +	ASSERT_EQ(ret, 0);
> +
> +	for (long i = 0; i < NUM_THREADS; i++) {
> +		ret = pthread_create(&tx[i], NULL, tx_worker, (void *)i);
> +		ASSERT_EQ(ret, 0);
> +	}

[Severity: Medium]
Can all tx_worker() threads finish before stats_reader() ever runs?

Sending 1000 in-memory frames on vcan takes only a few milliseconds, and
no startup barrier (such as pthread_barrier_t) aligns the threads.  All
transmitters can finish and set stop_reader before stats_reader() runs
once, giving a silent false pass.

stats_reader() also ignores the return value of read_if_stats() and
never inspects or counts the snapshots it reads, so /proc/net/dev read
errors, zero concurrent reads, or non-monotonic counter values go
undetected.

> 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

[ ... ]

> +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]
Can cleanup() delete a pre-existing host vcan0 interface if setup()
fails?

trap cleanup EXIT is armed before setup() runs in the root network
namespace.  If $CANIF already exists on the host, ip link add fails with
EEXIST and exits with $ksft_skip, triggering cleanup() to bring down and
delete an interface this test did not create.

Running in the root namespace also lets concurrent host traffic skew the
exact /proc/net/dev deltas checked by test_vcan_stats.  Isolating the
device with setup_ns and cleanup_all_ns from the already-sourced
net/lib.sh avoids both issues.

In setup(), exiting on ip link add failure also omits a skip reason
message (while still firing cleanup() errors when vcan is unavailable),
and ip link set dev $CANIF up does not check its return status.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203111103.379929-1-rameshsv06@gmail.com?part=2

  reply	other threads:[~2026-12-03 11:23 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 [this message]
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 ` [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=sashiko-outbox-247669@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=rameshsv06@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=socketcan@hartkopp.net \
    /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.