# Re: \[PATCH v6 bpf 1/3\] xdp: introduce xdp\_convert\_skb\_to\_buff()

- From: bot+bpf-ci@kernel.org
- Date: 2026-11-04 12:53:35 
- List: netdev
- Page: https://ratatoskr.run/netdev/2026/11/17860578
- Thread: https://ratatoskr.run/netdev/2026/11/17860336/t.md

```text
> xdp: introduce xdp_convert_skb_to_buff()

TL;DR:
- Persistent mem.type store in shared rxq may make BPF_PROG_TEST_RUN frag
  release hit page_pool path: WARN, leaked page
- Commit message nits: inaccurate "assigned to xdp_buff", stale "about to be
  integrated"

> diff --git a/include/net/xdp.h b/include/net/xdp.h
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h

[ ... ]

> +/**
> + * xdp_convert_skb_to_buff - build an xdp_buff on top of an skb
> + * @skb: skb to describe, packet data is taken from its MAC header onwards
> + * @xdp: xdp_buff to initialize
> + * @xdp_rxq: Rx queue info to attach to @xdp
> + *
> + * The memory type set on @xdp_rxq is only used to release fragments that
> + * the XDP program consumes; the head can not be freed from under the skb.
> + * A non-linear @skb is expected to have gone through skb_pp_cow_data(), so
> + * all of its fragments are page_pool backed.
> + */

[ ... ]

> +	DEBUG_NET_WARN_ON_ONCE(skb_is_nonlinear(skb) && !skb->pp_recycle);
> +	xdp->rxq->mem.type = MEM_TYPE_PAGE_POOL;
> +}

Can this store break other users of the same xdp_rxq_info?

bpf_prog_run_generic_xdp() passes &netif_get_rxqueue(skb)->xdp_rxq, which
is the device's long-lived dev->_rx[i].xdp_rxq.  The new mem.type is never
restored, so after the first generic XDP packet the queue stays
MEM_TYPE_PAGE_POOL.  Before this patch nothing wrote this field, and it
stayed at MEM_TYPE_PAGE_SHARED from xdp_rxq_info_reg().

bpf_prog_test_run_xdp() builds its xdp_buff on the same structure:

    rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0);
    rxqueue->xdp_rxq.frag_size = PAGE_SIZE;
    xdp_init_buff(&xdp, rxqueue->xdp_rxq.frag_size, &rxqueue->xdp_rxq);

(or the rxq selected by ctx->ingress_ifindex in xdp_convert_md_to_buff()).
It allocates its frags with alloc_page(GFP_KERNEL) and relies on the
default MEM_TYPE_PAGE_SHARED.

If an xdp.frags program run through BPF_PROG_TEST_RUN then releases a whole
frag with bpf_xdp_adjust_tail() or bpf_xdp_pull_data():

bpf_xdp_shrink_data()
  __xdp_return(netmem, MEM_TYPE_PAGE_POOL, ...)
    page_pool_put_full_netmem(netmem_get_pp(netmem), ...)

this runs the page_pool path on an ordinary page.  pp_ref_count overlays
page->private, which is 0, so page_pool_unref_netmem() sees
atomic_long_sub_return() return -1 and hits WARN_ON(ret < 0).  The page is
not freed, and it has already been removed from sinfo->frags, so the
__free_page() loop at the end of bpf_prog_test_run_xdp() does not free it
either.

To reproduce, attach a generic XDP program to lo, pass one packet, then run
BPF_PROG_TEST_RUN on an xdp.frags program with data_size_in larger than one
page whose bpf_xdp_adjust_tail() shrinks by at least the last frag.  The
result is a WARN (a panic with panic_on_warn) and a leaked page per run.

The kdoc says "The memory type set on @xdp_rxq is only used to release
fragments that the XDP program consumes", and the commit message says "The
mem type is only consulted when the program releases fragments".  Both
describe only the generic XDP buffer, and neither mentions that the value
persists in shared rxq state.

Could mem.type be saved and restored around the program run, or could
bpf_prog_test_run_xdp() set the mem type it needs (or use its own
xdp_rxq_info)?  The later veth commits in this series only touch
drivers/net/veth.c and do not address this.

Also, the commit message says:

> Pull out the existing code from bpf_prog_run_generic_xdp() that
> init/prepares xdp_buff onto new helper xdp_convert_skb_to_buff() and
> embed there rxq's mem_type initialization that is assigned to xdp_buff.

Is "assigned to xdp_buff" accurate?  struct xdp_buff has no mem type field;
the helper writes xdp->rxq->mem.type, i.e. netdev_rx_queue::xdp_rxq.mem.type.

And the commit message also says:

> This problem was triggered by syzbot as well as AF_XDP test suite which
> is about to be integrated to BPF CI.

This isn't a bug, but is "about to be integrated" still accurate?
selftests/bpf test_xsk.c already appears to be integrated into test_progs
in this tree (d1aec26fce25), so the wording looks stale.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41828746707
```
