Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: sst@poczta.fm
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net,
	hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me,
	bpf@vger.kernel.org, netdev@vger.kernel.org,
	jiayuan.chen@linux.dev, phx0fer@gmail.com,
	maciej.fijalkowski@intel.com, tianyi@cloudflare.com,
	tavip@google.com, toke@redhat.com, aleksander.lobakin@intel.com,
	lorenzo@kernel.org, lorenzo.bianconi@oss.qualcomm.com,
	ihor.solodrai@linux.dev, andrew+netdev@lunn.ch,
	willemb@google.com, horms@kernel.org, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, jolsa@kernel.org, memxor@gmail.com,
	emil@etsalapatis.com, shuah@kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net v9 5/6] selftests/bpf: add xdp_shrink_frags
Date: Sat, 28 Nov 2026 10:04:00 +0000	[thread overview]
Message-ID: <179586024048.3135.6988798909394815405@kernel.org> (raw)
In-Reply-To: <20261127100132.1977890-6-sst@poczta.fm>

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

Critical: 0 · High: 0 · Medium: 1 · Low: 3

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] None of the three subtests in
  tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c can fail on…
- [Low] The commit message lists the three subtests and then says 'A
  kernel without the fix will report "Bad page state ... page_pool…
- [Low] The comment in xdp_shrink()
  (tools/testing/selftests/bpf/progs/xdp_shrink_frags.c) says the…
- [Low] Two comments say the veth path starts from a nonlinear skb.

--

selftests/bpf: add xdp_shrink_frags

This adds a selftest with an xdp.frags program that shrinks the tail by
3000 bytes, so that bpf_xdp_shrink_data() releases a page_pool frag on the
skb-backed XDP paths. Three subtests cover generic XDP on a tap device,
the veth skb path, and a veth XDP_TX bounce to the peer, and all three
skip on systems without 4K pages.

> test_veth_tx bounces the cow'd buff with XDP_TX so the peer runs a frags
> program on the resulting frame, covering the buff -> frame -> buff path.
>
> A kernel without the fix will report "Bad page state ... page_pool leak".

[Severity: Low]
Is this true for test_veth_tx?

On the baseline kernel, the XDP_TX branch of veth_xdp_rcv_skb() already
restores the rxq mem type before the buff is converted to a frame:

drivers/net/veth.c:veth_xdp_rcv_skb() {
    ...
	case XDP_TX:
		veth_xdp_get(xdp);
		consume_skb(skb);
		xdp->rxq->mem = rq->xdp_mem;
		if (unlikely(veth_xdp_tx(rq, xdp, bq) < 0)) {
    ...
}

rq->xdp_mem comes from the MEM_TYPE_PAGE_SHARED registration, and the
xdp_tx program on LOCAL does not shrink anything.

So the frame that reaches PEER is PAGE_SHARED, and PEER's rxq is
PAGE_SHARED too. xdp_shrink on PEER then frees a plain page through
page_frag_free(), which is correct. An unfixed kernel would report nothing
for this subtest.

It looks like test_veth_tx only guards the reset that the veth skb-path fix
in this series adds to veth_xdp_get():

	/* the buff holds plain page references from here on */
	xdp->rxq->mem.type = MEM_TYPE_PAGE_SHARED;

If that reset went missing, the symptom would not be a "page_pool leak"
splat. A page whose pp was cleared would be sent down the page_pool return
path instead.

Every frame veth builds from the skb path is PAGE_SHARED. That means the
page_pool frame case handled by "veth: use the frame mem type when running
XDP on an xdp_frame" is not reached either, despite the "covering the
buff -> frame -> buff path" wording.

The series has four fixes, so "the fix" is also ambiguous. Could the commit
message say which fix each subtest covers and what failure it protects
against?

> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c b/tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c
> new file mode 100644
> index 0000000000000..789dfdd51b579
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c
> @@ -0,0 +1,288 @@

[ ... ]

> +static void test_tun(struct xdp_shrink_frags *skel)
> +{

[ ... ]

> +	n = writev(tap_fd, iov, ARRAY_SIZE(iov));
> +	ASSERT_EQ(n, sizeof(head) + sizeof(frag1) + sizeof(frag2), "writev");
> +
> +	wait_for_prog(skel);
> +	/* a buggy kernel only splats "page_pool leak", it does not fail here */
> +	ASSERT_GT(skel->bss->shrink_ran, 0, "xdp_prog_ran");

[Severity: Medium]
Can any of the three subtests fail on a kernel without the fixes?

This ASSERT_GT() is the only check here, and test_veth() and test_veth_tx()
use the same one. xdp_shrink() increments shrink_ran whenever
bpf_xdp_adjust_tail(ctx, -3000) returns 0:

	if (bpf_xdp_adjust_tail(ctx, -3000) == 0)
		__sync_fetch_and_add(&shrink_ran, 1);

That happens on fixed and buggy kernels alike. It also happens on any
linear buff longer than about 3014 bytes, where there is no frag at all.

The regression only shows up as "BUG: Bad page state ... page_pool leak"
from bad_page(). Nothing in the test reads /proc/sys/kernel/tainted or
scans kmsg, so unless the harness scans dmesg, test_progs reports PASS on
a regressed kernel.

The subtests would also keep passing, without testing anything, if a later
change to skb_pp_cow_data() or veth stopped leaving a frag after the cow.

bad_page() calls add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE) even when
its printk is rate-limited. Would it work to compare the TAINT_BAD_PAGE bit
(bit 5) of /proc/sys/kernel/tainted before and after each subtest?

Another option is for xdp_shrink() to count only when the buff had frags
before the shrink and lost one. It could compare bpf_xdp_get_buff_len()
against data_end - data to tell.

> +
> +	bpf_xdp_detach(ifindex, 0, NULL);

[ ... ]

> +/* A large ping builds a nonlinear skb that veth cow's into its page_pool. */
> +static void test_veth(struct xdp_shrink_frags *skel)

[Severity: Low]
Is the skb here actually nonlinear?

With MTU 8000 and a 5000-byte ping, __ip_append_data() puts the payload in
the linear area. paged is false because ping has no gso_size, zerocopy or
MSG_SPLICE_PAGES. Also fraglen + alloc_extra < SKB_MAX_ALLOC, so
alloclen = fraglen.

veth_convert_skb_to_xdp_buff() then cows the skb only because of the
headroom check, or because the skb is shared or its head is locked:

	if (skb_shared(skb) || skb_head_is_locked(skb) ||
	    skb_is_nonlinear(skb) ||
	    skb_headroom(skb) < XDP_PACKET_HEADROOM) {

The skb only becomes nonlinear as a result of skb_pp_cow_data(). The file
header comment ("skb-backed XDP first cow's the nonlinear skb into
page_pool memory") has the same problem for the veth path.

If the sender ever left at least XDP_PACKET_HEADROOM of headroom, veth
would run the program on the linear skb without a cow. The 3000-byte
shrink would still succeed, and this subtest would pass without reaching
the page_pool frag path.

Could the comment describe the headroom dependency instead?

[ ... ]

> diff --git a/tools/testing/selftests/bpf/progs/xdp_shrink_frags.c b/tools/testing/selftests/bpf/progs/xdp_shrink_frags.c
> new file mode 100644
> index 0000000000000..5d8e26f1b3a63
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/xdp_shrink_frags.c
> @@ -0,0 +1,34 @@

[ ... ]

> +SEC("xdp.frags")
> +int xdp_shrink(struct xdp_md *ctx)
> +{
> +	/*
> +	 * Runs on both skb-backed XDP paths (generic XDP via tun, and veth):
> +	 * the nonlinear skb is cow'd into page_pool memory before we run, so
> +	 * shrinking the tail releases a whole frag that has to go back to that
> +	 * pool. The counter only tells us the program ran and the helper
> +	 * succeeded -- a linear buff returns 0 as well -- it does not prove a
> +	 * frag was released.
> +	 */

[Severity: Low]
This comment only describes the skb-backed case, but test_veth_tx() also
attaches xdp_shrink to VETH_PEER:

	if (veth_attach(ns1, VETH_PEER, bpf_program__fd(skel->progs.xdp_shrink)))

On PEER the program runs from veth_xdp_rcv_one() on the xdp_frame that
LOCAL bounced with XDP_TX, not on a cow'd skb.

By then veth_xdp_get() has switched those frags to plain page references
with MEM_TYPE_PAGE_SHARED. The released frag must go through
page_frag_free() rather than back to a pool. The comment above
test_veth_tx() itself says that freeing it "as page_pool memory" is the
bug.

Should this comment mention the frame case on PEER?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127100132.1977890-1-sst%40poczta.fm

  reply	other threads:[~2026-11-28 10:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 10:01 [PATCH net v9 0/6] xdp: fix page_pool leaks Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 1/6] xdp: run generic XDP on frags with a copy of the rxq info Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 2/6] bpf: test_run: Set frag_size on " Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 3/6] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 4/6] veth: use the page_pool mem type when running XDP on an skb Slawomir Stepien
2026-11-28 10:03   ` netdev-bot+sashiko
2026-11-27 10:01 ` [PATCH net v9 5/6] selftests/bpf: add xdp_shrink_frags Slawomir Stepien
2026-11-28 10:04   ` netdev-bot+sashiko [this message]
2026-11-27 10:01 ` [PATCH net v9 6/6] selftests/bpf: Grow test_run and generic XDP frags after a test run Slawomir Stepien

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=179586024048.3135.6988798909394815405@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --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=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lorenzo.bianconi@oss.qualcomm.com \
    --cc=lorenzo@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=phx0fer@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=sst@poczta.fm \
    --cc=tavip@google.com \
    --cc=tianyi@cloudflare.com \
    --cc=toke@redhat.com \
    --cc=willemb@google.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