From: Jakub Kicinski <kuba@kernel.org>
To: jiayuan.chen@linux.dev
Cc: Jakub Kicinski <kuba@kernel.org>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
syzbot+237bbeed8dfe0699b7f5@syzkaller.appspotmail.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net,
hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me,
horms@kernel.org, martin.lau@linux.dev, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
ihor.solodrai@linux.dev, shuah@kernel.org, kuniyu@google.com,
liuhangbin@gmail.com, krikku@gmail.com, mkarsten@uwaterloo.ca,
toke@redhat.com, lorenzo.bianconi@oss.qualcomm.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf v2 2/2] selftests/bpf: add xdp_shrink_frags
Date: Thu, 27 Aug 2026 12:19:46 -0700 [thread overview]
Message-ID: <20260827191946.4007873-1-kuba@kernel.org> (raw)
In-Reply-To: <20260824030705.266049-2-jiayuan.chen@linux.dev>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
selftests/bpf: add xdp_shrink_frags
Adds a new test_progs test with two subtests (tun and veth) that attach an
xdp.frags program shrinking the tail by 3000 bytes so a whole frag is
released. The intent is to reproduce a page_pool frag being freed with the
wrong memory type on skb-backed XDP paths.
Two questions below about what the test actually observes.
> 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..f3d8a84a6dc9c
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c
> @@ -0,0 +1,163 @@
[ ... ]
> +/*
> + * Similar to flow_dissector.c: writev() an IFF_NAPI_FRAGS tap to build a
> + * nonlinear skb (sized for 4K pages, like xdp_adjust_tail.c) that tun runs
> + * through do_xdp_generic().
> + */
> +static void test_tun(struct xdp_shrink_frags *skel)
> +{
> + __u8 head[74], frag1[2048], frag2[2048];
[Severity: Medium]
Is the 74 + 2048 + 2048 byte frame guaranteed to still be nonlinear when the
program runs on kernels with PAGE_SIZE larger than 4096?
skb_pp_cow_data() in net/core/skbuff.c bounds the linear head by the page
size:
max_head_size = SKB_WITH_OVERHEAD(PAGE_SIZE - headroom);
...
size = min_t(u32, skb->len, max_head_size);
...
for (i = 0; i < MAX_SKB_FRAGS && off < skb->len; i++) {
With PAGE_SIZE 16384 or 65536 the whole 4170-byte frame fits in the head, so
the frag loop body never runs and the xdp_buff has no frags.
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c handles this by
branching on getpagesize():
int page_size = getpagesize();
...
if (page_size == 65536)
test_xdp_adjust_frags_tail_grow_64k();
Would a getpagesize() branch or skip be appropriate here too, given that
config.aarch64 is shipped in the bpf selftests?
[ ... ]
> + n = writev(tap_fd, iov, ARRAY_SIZE(iov));
> + ASSERT_EQ(n, sizeof(head) + sizeof(frag1) + sizeof(frag2), "writev");
> +
> + usleep(100 * 1000);
> + ASSERT_GT(skel->bss->shrink_ran, 0, "xdp_prog_ran");
[Severity: Medium]
Can this subtest distinguish a buggy kernel from a fixed one?
The failure mode the commit message names ("Bad page state ... page_pool
leak") is produced by bad_page() in mm/page_alloc.c, with the reason string
set in page_bad_reason():
if (unlikely(page_pool_page_is_pp(page)))
bad_reason = "page_pool leak";
bad_page() is a static void that only emits pr_alert()/dump_page()/
dump_stack() and then:
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
No error is propagated back to bpf_xdp_adjust_tail(), writev() or ping, and
the test does not read /proc/sys/kernel/tainted, scan kmsg, or look at
page_pool inflight statistics.
So the assertions here (bpf_xdp_attach, the writev length, and shrink_ran)
all succeed identically on a kernel with and without the fix. Would it make
sense to add an observable oracle (taint bit, kmsg scan, or page_pool
stats), or alternatively to state in the commit message that this is a splat
generator requiring manual dmesg inspection?
[ ... ]
> +static void test_veth(struct xdp_shrink_frags *skel)
> +{
[ ... ]
> + SYS_NOFAIL("ip netns exec " VETH_NETNS
> + " ping -q -s 5000 -c 3 -W 1 " VETH_LOCAL_IP);
> +
> + ASSERT_GT(skel->bss->shrink_ran, 0, "xdp_prog_ran");
[Severity: Medium]
The same two concerns apply here. The ping runs under SYS_NOFAIL and the
only assertion is shrink_ran > 0, so nothing observes whether the released
frag went back to its page_pool.
Additionally, the frag layout of a ~5 KB ping through an 8000-MTU veth is
decided by the sender's SG/GRO behaviour rather than by the test. If the
skb ends up with a single frag larger than 3000 bytes, the shrink happens in
place and no page is released at all.
On large-PAGE_SIZE kernels veth_convert_skb_to_xdp_buff() takes the other
branch after the COW leaves no frags:
if (skb_shinfo(skb)->nr_frags) {
...
xdp_buff_set_frag_pp(xdp);
} else {
xdp_buff_clear_frags_flag(xdp);
}
which bypasses the frag-release code entirely.
> 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..62e3791ac81d9
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/xdp_shrink_frags.c
> @@ -0,0 +1,23 @@
[ ... ]
> + /*
> + * The program is loaded with BPF_F_XDP_HAS_FRAGS (xdp.frags), so a
> + * nonlinear skb entering generic XDP is cow'd into page_pool memory
> + * before we run. Shrinking the tail far enough releases at least one
> + * whole frag, which must be returned to its page_pool. Count only a
> + * successful shrink so a too-small frame (e.g. ARP) does not satisfy
> + * the test.
> + */
> + if (bpf_xdp_adjust_tail(ctx, -3000) == 0)
> + __sync_fetch_and_add(&shrink_ran, 1);
[Severity: Medium]
Does a return value of 0 here really imply a frag was released?
bpf_xdp_adjust_tail() in net/core/filter.c only enters the frag path when
the buffer is nonlinear:
if (unlikely(xdp_buff_has_frags(xdp))) { /* non-linear xdp buff */
if (offset < 0)
return bpf_xdp_frags_shrink_tail(xdp, -offset);
...
xdp->data_end = data_end;
return 0;
A purely linear buffer takes the bottom path and also returns 0, so
shrink_ran gets incremented without bpf_xdp_shrink_data() ever running.
That seems to contradict the comment's claim that only a genuine
frag-releasing shrink is counted.
Would asserting somewhere that the buffer actually had frags (for example
comparing ctx->data_end - ctx->data against the total frame length) make the
counter mean what the comment says?
next prev parent reply other threads:[~2026-08-27 19:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 3:02 [PATCH bpf v2 0/2] net: xdp: fix bpf_xdp_shrink_data() page handling on generic XDP and veth Jiayuan Chen
2026-08-24 3:06 ` [PATCH bpf v2 1/2] bpf, veth: xdp: fix page_pool page leak on skb-backed XDP Jiayuan Chen
2026-08-24 3:06 ` [PATCH bpf v2 2/2] selftests/bpf: add xdp_shrink_frags Jiayuan Chen
2026-08-24 3:58 ` bot+bpf-ci
2026-08-24 4:53 ` Jiayuan Chen
2026-08-27 19:19 ` Jakub Kicinski [this message]
2026-08-24 10:31 ` [PATCH bpf v2 1/2] bpf, veth: xdp: fix page_pool page leak on skb-backed XDP Lorenzo Bianconi
2026-08-24 12:19 ` Jiayuan Chen
2026-08-24 14:50 ` Lorenzo Bianconi
2026-08-25 12:06 ` Jiayuan Chen
2026-08-27 19:19 ` Jakub Kicinski
2026-08-27 19:20 ` Jakub Kicinski
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=20260827191946.4007873-1-kuba@kernel.org \
--to=kuba@kernel.org \
--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@google.com \
--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=krikku@gmail.com \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=liuhangbin@gmail.com \
--cc=lorenzo.bianconi@oss.qualcomm.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mkarsten@uwaterloo.ca \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=syzbot+237bbeed8dfe0699b7f5@syzkaller.appspotmail.com \
--cc=toke@redhat.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