mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: o.rempel@pengutronix.de
Cc: robin@protonic.nl, socketcan@hartkopp.net, mkl@pengutronix.de,
	shuah@kernel.org, kernel@pengutronix.de,
	linux-can@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, fmaurer@redhat.com,
	mailhol@kernel.org, alexander.hoelzl@gmx.net,
	quchaosheng000406@163.com, penguin-kernel@I-love.SAKURA.ne.jp,
	kuba@kernel.org
Subject: Re: [PATCH can-next v4 7/9] selftests: can: add J1939 TP/ETP multi-frame tests against CAN_RAW
Date: Thu, 19 Nov 2026 23:54:38 +0000	[thread overview]
Message-ID: <179513247817.3132.9443006972128193443@kernel.org> (raw)
In-Reply-To: <20261118-j1939-selftests-v4-7-756768d32ff2@pengutronix.de>

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

Critical: 0 · High: 0 · Medium: 1 · 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] The commit message argues that test_j1939_multi.sh can stay in
  the default TEST_PROGS run (not TEST_PROGS_EXTENDED or XFAIL) because…
- [Low] In j1939_helpers.h, errqueue_empty_ok() is documented as "Is the
  error queue of s still empty after J1939_NEG_RECV_TIMEOUT_MS?".

--

selftests: can: add J1939 TP/ETP multi-frame tests against CAN_RAW

This adds TP and ETP round-trip selftests in both directions between a
J1939 socket and a CAN_RAW peer. The TX tests check that the
TX-completion ACK comes only after the peer's EOMA. By default the peer
runs on a separate vcan behind the CAN gateway, which is meant to avoid
a known loopback echo race in the stack.

> diff --git a/tools/testing/selftests/net/can/j1939_helpers.c b/tools/testing/selftests/net/can/j1939_helpers.c
> index b7490c335d8b7..d60e49b3cc4e3 100644
> --- a/tools/testing/selftests/net/can/j1939_helpers.c
> +++ b/tools/testing/selftests/net/can/j1939_helpers.c
> @@ -523,6 +523,13 @@ bool errqueue_read_ack_ok(int s)
>  	return msg_has_tstamp_ack(&msg);
>  }
>  
> +bool errqueue_empty_ok(int s)
> +{
> +	struct pollfd pfd = { .fd = s, .events = POLLERR };
> +
> +	return poll(&pfd, 1, J1939_NEG_RECV_TIMEOUT_MS) == 0;
> +}
> +

[ ... ]

> diff --git a/tools/testing/selftests/net/can/j1939_helpers.h b/tools/testing/selftests/net/can/j1939_helpers.h
> index 92d6af3214f2d..bc5eef14bea23 100644
> --- a/tools/testing/selftests/net/can/j1939_helpers.h
> +++ b/tools/testing/selftests/net/can/j1939_helpers.h
> @@ -372,6 +372,9 @@ bool msg_has_tstamp_ack(struct msghdr *msg);
>   */
>  bool errqueue_read_ack_ok(int s);
>  
> +/* Is the error queue of s still empty after J1939_NEG_RECV_TIMEOUT_MS? */
> +bool errqueue_empty_ok(int s);

[Severity: Low]
Does this comment match what errqueue_empty_ok() checks? For a J1939
socket, POLLERR covers more than the error queue:

net/core/datagram.c:datagram_poll_queue() {
    ...
	if (READ_ONCE(sk->sk_err) ||
	    !skb_queue_empty_lockless(&sk->sk_error_queue))
		mask |= EPOLLERR |
    ...
}

So errqueue_empty_ok() also returns false when the error queue is empty
but sk_err is set, for example ENETDOWN or ENODEV from
j1939_sk_netdev_event(). It also returns false when poll() itself
returns -1.

The test fails in all of these cases. However, tp_tx_to_raw() and
etp_tx_to_raw() would then log "error-queue entry before the EOMA",
which names the wrong cause.

Should the comment, or the TH_LOG() message in the callers, also cover
the sk_err and poll() failure cases?

[ ... ]

> diff --git a/tools/testing/selftests/net/can/test_j1939_multi.c b/tools/testing/selftests/net/can/test_j1939_multi.c
> new file mode 100644
> index 0000000000000..a97fa8b998b89
> --- /dev/null
> +++ b/tools/testing/selftests/net/can/test_j1939_multi.c
> @@ -0,0 +1,682 @@
> +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
> +/*
> + * J1939 multi-frame wire selftests: TP and ETP against CAN_RAW.
> + *
> + * A CAN_RAW socket plays the transport peer against the kernel J1939 stack,
> + * in both directions. It takes the other side of the RTS/CTS/DT/EOMA
> + * exchange, for TP with a short message and for ETP with a payload that
> + * spans several CTS blocks (DPO windows).
> + *
> + * Known stack race: the stack updates a session from the loopback echo of
> + * its own TP and ETP frames. A CAN_RAW peer on the same vcan can read
> + * that echo first. If the peer replies quickly, the stack can cancel the
> + * session. See j1939_lib.sh for where the peer runs. The fix belongs in
> + * the stack; this file does not work around it.

[Severity: Medium]
The commit message says:

  By default the peer runs on its own vcan behind the CAN gateway that
  j1939_lib.sh sets up. With RPS off on that vcan, the peer then gets
  each frame only after the stack has handled its echo.

The notes below the cut line add "RPS must be off on the peer's vcan.
It is off by default."

Does anything in the series make sure RPS is off on CANIF_RAW?
vcan_setup() in j1939_lib.sh creates the interface with:

	if ! ip link add name "$dev" type vcan; then

setup() then starts j1939_gw, but nothing writes or checks
/sys/class/net/$CANIF_RAW/queues/rx-0/rps_cpus.

If the host has net.core.rps_default_mask set, the new vcan1 gets a
non-empty RPS map:

net/core/net-sysfs.c:rx_queue_default_mask() {
    ...
	rps_default_mask = dev_net(dev)->core.rps_default_mask;
	if (rps_default_mask && !cpumask_empty(rps_default_mask))
		res = netdev_rx_queue_set_rps_mask(queue, rps_default_mask);
    ...
}

The gateway's copy for the peer then goes through:

can_send()->vcan_tx()->vcan_rx()->netif_rx()->netif_rx_internal()->
get_rps_cpu()

A CAN skb always has a non-zero flow hash, so get_rps_cpu() picks a CPU
from the map. That CPU may not be the one handling the J1939 stack's
loopback echo.

In that setup, can the CAN_RAW peer reply before the stack has handled
its echo? That would bring back the race this comment describes, and
tp_rx_from_raw, tp_tx_to_raw, etp_rx_from_raw and etp_tx_to_raw could
fail at random in the default TEST_PROGS run.

j1939_test_main() only warns when the peer shares the vcan:

	if (j1939_needs_raw && !strcmp(CANIF_RAW, CANIF))

So this case would fail without any warning, and it would look like the
protected default setup.

Since the test stays in TEST_PROGS, should j1939_lib.sh clear rps_cpus
on CANIF_RAW, or at least warn or skip when it is set?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-j1939-selftests-v4-0-756768d32ff2%40pengutronix.de

  reply	other threads:[~2026-11-19 23:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  8:42 [PATCH can-next v4 0/9] selftests: can: add J1939 socket and transport tests Oleksij Rempel
2026-11-18  8:42 ` [PATCH can-next v4 1/9] selftests: can: install net/lib.sh with the CAN tests Oleksij Rempel
2026-11-18  8:42 ` [PATCH can-next v4 2/9] selftests: can: add J1939 test helper header and library Oleksij Rempel
2026-11-19 23:54   ` netdev-bot+sashiko
2026-11-18  8:42 ` [PATCH can-next v4 3/9] selftests: can: add J1939 base functional tests Oleksij Rempel
2026-11-18  8:42 ` [PATCH can-next v4 4/9] selftests: can: add J1939 socket option and metadata tests Oleksij Rempel
2026-11-18  8:42 ` [PATCH can-next v4 5/9] selftests: can: add J1939 addressing and concurrency tests Oleksij Rempel
2026-11-18  8:42 ` [PATCH can-next v4 6/9] selftests: can: add J1939 wire-format tests against CAN_RAW Oleksij Rempel
2026-11-18  8:42 ` [PATCH can-next v4 7/9] selftests: can: add J1939 TP/ETP multi-frame " Oleksij Rempel
2026-11-19 23:54   ` netdev-bot+sashiko [this message]
2026-11-18  8:42 ` [PATCH can-next v4 8/9] selftests: can: cover J1939 transport abort and timeout paths Oleksij Rempel
2026-11-18  8:42 ` [PATCH can-next v4 9/9] selftests: can: check SO_J1939_PROMISC receive effect Oleksij Rempel

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=179513247817.3132.9443006972128193443@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexander.hoelzl@gmx.net \
    --cc=fmaurer@redhat.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=quchaosheng000406@163.com \
    --cc=robin@protonic.nl \
    --cc=shuah@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®