From: netdev-bot+sashiko@kernel.org
To: bochaolucky@gmail.com
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev, shuah@kernel.org,
davem@davemloft.net, kuba@kernel.org, hawk@kernel.org,
john.fastabend@gmail.com, sdf@fomichev.me, andrew+netdev@lunn.ch,
edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
alexis.lothore@bootlin.com, lorenzo@kernel.org,
tiozhang@didiglobal.com, willemdebruijn.kernel@gmail.com,
petrm@nvidia.com
Subject: Re: [PATCH net-next v6 1/5] selftests/bpf: Fix XDP feature test setup and teardown
Date: Mon, 19 Oct 2026 14:55:02 +0000 [thread overview]
Message-ID: <179242170282.3135.3655485232785325877@kernel.org> (raw)
In-Reply-To: <20261018-xdp-v5-send-20261008-v6-1-7336e1282ca3@gmail.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The `xdp_attached` guard only records that an attach succeeded at
some point.
Pre-existing issues:
- [Medium] test_xdp_features.sh uses only the tester's exit status, and
tester_run() returns 0 whether or not the capability is DETECTED or…
- [Low] In tester_run(), the settimeo() and connect() failure paths
return directly without close(sockfd), which leaks the control socket.
- [Low] recv_msg() accepts payloads shorter than val_size and copies only
the bytes it received.
--
selftests/bpf: Fix XDP feature test setup and teardown
This commit fixes several setup and teardown problems in the xdp_features
selftest tool. It initializes the DUT state and socket address lengths,
hands the echo socket back to the caller, and stops and joins the echo
thread only if it was started. It also samples the tester counters before
teardown, and it detaches XDP programs only after a successful attach.
> diff --git a/tools/testing/selftests/bpf/xdp_features.c b/tools/testing/selftests/bpf/xdp_features.c
> index a27ed663967c4..3076fdda61fa4 100644
> --- a/tools/testing/selftests/bpf/xdp_features.c
> +++ b/tools/testing/selftests/bpf/xdp_features.c
[ ... ]
> @@ -341,10 +343,14 @@ static int recv_msg(int sockfd, void *buf, size_t bufsize, void *val,
> size_t val_size)
> {
> struct tlv_hdr *tlv = (struct tlv_hdr *)buf;
> - size_t len;
> + ssize_t len;
>
> len = recv(sockfd, buf, bufsize, 0);
> - if (len != ntohs(tlv->len) || len < sizeof(*tlv))
> + if (len < 0)
> + return -errno;
> + if (!len)
> + return -ECONNRESET;
> + if (len < sizeof(*tlv) || len != ntohs(tlv->len))
> return -EINVAL;
>
> if (val) {
[Severity: Low]
This isn't a bug introduced by this patch, but recv_msg() only rejects
payloads that are larger than val_size:
if (val) {
len -= sizeof(*tlv);
if (len > val_size)
return -ENOMEM;
memcpy(val, tlv->data, len);
}
Can a short payload leave part of the destination unwritten?
In tester_run(), stats and advertised_feature are both declared without
an initial value. Leftover stack bytes could then affect the feature
result that gets printed.
A later patch in this series changes the check to:
if (len != val_size)
return -ENOMEM;
That rejects short payloads before the memcpy().
[ ... ]
> @@ -403,9 +412,12 @@ static int dut_run(struct xdp_features *skel)
> if (err)
> goto out;
>
> + xdp_attached = true;
> +
> err = dut_run_echo_thread(&dut_thread, &echo_sockfd);
[ ... ]
> @@ -422,6 +434,7 @@ static int dut_run(struct xdp_features *skel)
>
> exiting = true;
> bpf_xdp_detach(env.ifindex, flags, NULL);
> + xdp_attached = false;
[Severity: Low]
The xdp_attached flag records that bpf_xdp_attach() succeeded at some
point. However, bpf_xdp_detach(env.ifindex, flags, NULL) removes
whatever program is attached to the device at the time it runs.
If another privileged user replaces the program between the attach and
the detach, would this still remove that other program?
The out: label in tester_run() uses the same pattern:
if (xdp_attached)
bpf_xdp_detach(env.ifindex, flags, NULL);
A later patch in this series appears to fix this. The DUT attaches with
bpf_link_create() and cleans up with close(link_fd). The tester no
longer attaches an XDP program at all, because it uses AF_PACKET.
>
> tlv->type = htons(CMD_ACK);
> tlv->len = htons(sizeof(*tlv));
[ ... ]
> @@ -578,7 +596,7 @@ static int tester_run(struct xdp_features *skel)
> struct bpf_program *prog;
> unsigned int stats;
> int i, err, sockfd;
> - bool detected_cap;
> + bool detected_cap, xdp_attached = false;
>
> sockfd = socket(AF_INET6, SOCK_STREAM, 0);
> if (sockfd < 0) {
[Severity: Low]
This is a pre-existing issue, but the settimeo() and connect() failure
paths just below this return without closing sockfd:
if (settimeo(sockfd, 1000) < 0)
return -EINVAL;
err = connect(sockfd, (struct sockaddr *)&env.dut_ctrl_addr,
sizeof(env.dut_ctrl_addr));
if (err) {
...
return -errno;
}
Does this leak the control socket? Now that xdp_attached starts out
false, could these paths go to the out: label instead?
A later patch in this series changes them to "err = -errno; goto out;".
[ ... ]
> @@ -636,19 +655,21 @@ static int tester_run(struct xdp_features *skel)
> if (err)
> goto out;
>
> + /* Sample before teardown, which can produce additional echo traffic. */
> + detected_cap = tester_collect_detected_cap(skel, ntohl(stats));
> +
> /* stop the test */
[ ... ]
> fprintf(stdout, "Feature %s: [%s][%s]\n", get_xdp_feature_str(),
> detected_cap ? GREEN("DETECTED") : RED("NOT DETECTED"),
> env.feature.drv_feature & advertised_feature ? GREEN("ADVERTISED")
> : RED("NOT ADVERTISED"));
> out:
> - bpf_xdp_detach(env.ifindex, flags, NULL);
> + if (xdp_attached)
> + bpf_xdp_detach(env.ifindex, flags, NULL);
> close(sockfd);
> return err < 0 ? err : 0;
> }
[Severity: Medium]
This isn't a bug introduced by this patch, but detected_cap and
advertised_feature are only printed here. tester_run() returns 0
whatever their values are.
test_xdp_features.sh checks only the exit status of the tester:
ip netns exec ${NS} ./xdp_features -t -f XDP_PASS \
-D $V1_IP6 -C $V1_IP6 \
-T $V0_IP6 v0
[ $? -ne 0 ] && exit
Could a broken or unadvertised XDP action still pass the selftest?
A later patch in this series ("selftests/bpf: Track XDP test processes
and isolate namespaces") adds:
if (!err && detected_cap != !!(env.feature.drv_feature & advertised_feature))
err = -EINVAL;
The same series also replaces the shell script with
drivers/net/hw/xdp_features.py.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261018-xdp-v5-send-20261008-v6-0-7336e1282ca3%40gmail.com
next prev parent reply other threads:[~2026-10-19 14:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 14:05 [PATCH net-next v6 0/5] selftests: Fix and migrate the XDP feature test Bochao Cao via B4 Relay
2026-10-18 14:05 ` [PATCH net-next v6 1/5] selftests/bpf: Fix XDP feature test setup and teardown Bochao Cao via B4 Relay
2026-10-19 14:55 ` netdev-bot+sashiko [this message]
2026-10-18 14:05 ` [PATCH net-next v6 2/5] selftests/bpf: Track XDP test processes and isolate namespaces Bochao Cao via B4 Relay
2026-10-19 14:55 ` netdev-bot+sashiko
2026-10-18 14:05 ` [PATCH net-next v6 3/5] selftests/bpf: Send XDP feature probes with AF_PACKET Bochao Cao via B4 Relay
2026-10-19 14:55 ` netdev-bot+sashiko
2026-10-18 14:05 ` [PATCH net-next v6 4/5] selftests/net: Add a shared BPF skeleton rule Bochao Cao via B4 Relay
2026-10-19 14:55 ` netdev-bot+sashiko
2026-10-18 14:05 ` [PATCH net-next v6 5/5] selftests/net: Move the XDP feature test to drivers/net/hw Bochao Cao via B4 Relay
2026-10-19 14:55 ` 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=179242170282.3135.3655485232785325877@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=alexis.lothore@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bochaolucky@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tiozhang@didiglobal.com \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yonghong.song@linux.dev \
/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®