๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by netdev-bot+sashiko Mon, 23 Nov 2026 03:59
Re: [PATCH net-next v2 03/11] net: set tx_extra_headroom of the peer on XDP attach
#20698
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 03:59
98 lines
12768 bytes
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] Native XDP on veth still copies every locally generated
  packet, and the commit message implies this patch fixes that.

--

net: set tx_extra_headroom of the peer on XDP attach

While the peer of a veth or netkit device has an XDP program, this patch
sets tx_extra_headroom of the device to XDP_PACKET_HEADROOM minus
needed_headroom, so locally generated packets have the headroom XDP
needs. netdev_update_tx_extra_headroom() recalculates the value on XDP
attach, on detach, and when an upper device propagates its program
through netif_xdp_propagate().

> diff --git a/net/core/dev.c b/net/core/dev.c
> index 85b7c61015c7c..6e053f612d720 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c

[ ... ]

> @@ -10677,6 +10678,41 @@ u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode)
>  	return prog ? prog->aux->id : 0;
>  }
>  
> +static void __netdev_update_tx_extra_headroom(struct net_device *dev,
> +					      struct net_device *peer)
> +{
> +	unsigned int needed_headroom = READ_ONCE(dev->needed_headroom);
> +	unsigned int tx_extra_headroom = 0;
> +
> +	if (peer && dev_xdp_prog_count(peer) &&
> +	    needed_headroom < XDP_PACKET_HEADROOM)
> +		tx_extra_headroom = XDP_PACKET_HEADROOM - needed_headroom;

[Severity: Medium]

Does this avoid the copy for native XDP on veth? The commit message says:

  XDP on the peer of a veth or netkit device
  then copies every packet. Generic XDP copies it in
  netif_skb_check_for_xdp(), and native XDP on veth in
  veth_convert_skb_to_xdp_buff().

veth_convert_skb_to_xdp_buff() still copies whenever the head is not a
page fragment:

drivers/net/veth.c:veth_convert_skb_to_xdp_buff() {
    ...
	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))
    ...
}

skb_head_is_locked() is true when !skb->head_frag. The local paths that
now add tx_extra_headroom are __ip_append_data(), raw_send_hdrinc(),
packet_snd() and xsk_build_skb(). All of them allocate the head with
alloc_skb() or sock_alloc_send_pskb(), so head_frag is 0 and these
packets are still copied.

veth has ndo_bpf, so dev_xdp_mode() picks XDP_MODE_DRV by default. In
that default case, every locally generated skb sent to the peer gets up
to 256 extra bytes of headroom. This can push small packets into a
larger kmalloc bucket, and no copy is saved.

The generic XDP path does look fixed. netif_receive_generic_xdp() only
checks cloned, nonlinear and headroom, not head_frag.

The note below the --- line says a follow-up veth series will fix the
head_frag condition, but git am drops that note. Could the commit message
say that native XDP on veth still copies after this patch?

The new text in Documentation/networking/netdevices.rst has the same gap:

  When the peer has an XDP program, locally generated UDP, raw and
  AF_PACKET packets and AF_XDP packets in copy mode have enough headroom
  for it.

Should it mention that native XDP on veth still copies these packets?

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119013830.36935-1-tianyi%40cloudflare.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads