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 4/6] veth: use the page_pool mem type when running XDP on an skb
Date: Sat, 28 Nov 2026 10:03:57 +0000	[thread overview]
Message-ID: <179586023747.3135.10147454988994351806@kernel.org> (raw)
In-Reply-To: <20261127100132.1977890-5-sst@poczta.fm>

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

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

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] In drivers/net/veth.c, veth_convert_skb_to_xdp_buff() now
  always sets rxq->mem.type = MEM_TYPE_PAGE_POOL.

--

veth: use the page_pool mem type when running XDP on an skb

veth now runs the XDP program on an skb with an on-stack rxq info whose
mem type is MEM_TYPE_PAGE_POOL. Frags that the program shrinks away go
back to the page_pool they came from. On XDP_TX and XDP_REDIRECT,
veth_xdp_get() switches the mem type back to MEM_TYPE_PAGE_SHARED, and
the saved rq->xdp_mem is removed.

Link: https://lore.kernel.org/all/DN3QVHST3PUQ.3NINFUW0FL9IW@gmail.com/

> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index cce253b58c2bc..8bb015c133760 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c

[ ... ]

> @@ -773,7 +776,9 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
>  	/* SKB "head" area always have tailroom for skb_shared_info */
>  	frame_sz = skb_end_pointer(skb) - skb->head;
>  	frame_sz += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> -	xdp_init_buff(xdp, frame_sz, &rq->xdp_rxq);
> +	/* the prog can free only frags and they came from skb_pp_cow_data() */
> +	rxq->mem.type = MEM_TYPE_PAGE_POOL;
> +	xdp_init_buff(xdp, frame_sz, rxq);

[Severity: Medium]
Is the invariant in this comment guaranteed by the code?

Earlier in veth_convert_skb_to_xdp_buff(), the copy into page_pool
memory depends on skb_is_nonlinear(), which tests skb->data_len:

	if (skb_shared(skb) || skb_head_is_locked(skb) ||
	    skb_is_nonlinear(skb) ||
	    skb_headroom(skb) < XDP_PACKET_HEADROOM) {
		if (skb_pp_cow_data(rq->page_pool, pskb, XDP_PACKET_HEADROOM))
			goto drop;

The frags flag set just below depends on nr_frags instead:

	if (skb_shinfo(skb)->nr_frags) {
		skb_shinfo(skb)->xdp_frags_size = skb->data_len;
		xdp_buff_set_frags_flag(xdp);

Take an skb that is unshared and unlocked, has enough headroom, and has
nr_frags > 0 but data_len == 0 (all frags are zero-length). It skips
skb_pp_cow_data() and keeps its original frag pages, which are not
page_pool pages. It still gets XDP_FLAGS_HAS_FRAGS and runs with
MEM_TYPE_PAGE_POOL.

Suppose a frags-aware program then calls bpf_xdp_adjust_tail() with a
negative offset. For each zero-size frag, bpf_xdp_frags_shrink_tail()
computes shrink = 0, and bpf_xdp_shrink_data() treats the frag as fully
consumed:

bpf_xdp_adjust_tail()
  bpf_xdp_frags_shrink_tail()
    bpf_xdp_shrink_data()        /* release = (size == shrink) */
      __xdp_return(netmem, MEM_TYPE_PAGE_POOL, ...)
        page_pool_put_full_netmem(netmem_get_pp(netmem), ...)

For MEM_TYPE_PAGE_POOL, __xdp_return() does not check netmem_is_pp().
Wouldn't netmem_get_pp() then read a pp pointer from a page that was
never part of a page_pool? Before this patch, the same frag went through
page_frag_free() under MEM_TYPE_PAGE_SHARED, which releases it correctly.

I could not find a concrete source of such an skb reaching veth_xmit(),
and the usual skb helpers avoid leaving zero-size frags behind. However,
nothing in veth rejects that state.

The sibling change "xdp: run generic XDP on frags with a copy of the rxq
info" uses skb_is_nonlinear() for the copy decision, the frags flag and
MEM_TYPE_PAGE_POOL. Could the frags flag here also be set from
skb_is_nonlinear()? Alternatively, MEM_TYPE_PAGE_POOL could be used only
when skb_pp_cow_data() actually ran, keeping MEM_TYPE_PAGE_SHARED
otherwise.

[ ... ]

-- 
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 [this message]
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
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=179586023747.3135.10147454988994351806@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