Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795543115; b=hFi1agHzvtpE1E25AqIc5jr2tyZb7ncARbf3i40R9ddbtF6aPlcYtBB+QMviY00w/PHX IGOfJyjqDI97mQa9dwQhoRvHseJKW4xpmuOIlmu7qKxM+2HFf89PuINT+diQyWg36q3mO etbhvyTl4JIZYUbRdK1Ugf/t2RmxyuMSd0JHv+K7saKLxrFTd/c6OncwbtuEDBSfSobOD Sv18FeBZoSLdQ4PWX65jKNDo8n0Jd7Wa+ls0PslrCDZmH2xo36noUEnEE63w3qOaagXdT s+PbXb2PkojIPCarzg1psY10yPtezBFtcLeMOjSE6XFyNfC0XT6sTGA4bz0fhVM3QEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795543115; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=aQUx3TL65pMyWzlf2bMKB3xiAtfdB/7ZATJytxZbwVM=; b=pylmI/pV1Ve7zSg1RSRv2jCaG/IE8bYd4bxXIV+IOnJYHK8lRufcbpex3ECSl3RR95EV gCYltEcVyHSUVD5PBDpf8cdM/iGDfRUNUHN7m5DNemZp3ozTcXC3opK3J/yIDCQTq38kO FJrvKayGcC9nRKMAZYqQkgmp2htMrKAf3zSM4+HDKLF9glgyJaPN/isjCQWbGsg0kPGrQ uNvcuUCATVc2e+sFwTZUw2W4B7Ofw6e7g1HOcVVm5MOTZxk5q+nj5pZe3R2jS3EVNtn/R w1vxVSYHcHvkSv7HhNr8OwhvwS2rRsoDwSzJVeFd9rGK1gpw4RJE9JgMrYJTNM2236w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass header.d=cloudflare.com header.i=@cloudflare.com header.a=rsa-sha256 header.s=google09082023 header.b=CaJCF+Ut; arc=none smtp.remote-ip=209.85.218.53 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF2DD606A323 for ; Tue, 24 Nov 2026 17:58:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BF2DD606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.a=rsa-sha256 header.s=google09082023 header.b=CaJCF+Ut Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-c50cc7540b7so674195566b.0 for ; Tue, 24 Nov 2026 09:58:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1795543113; x=1796147913; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=aQUx3TL65pMyWzlf2bMKB3xiAtfdB/7ZATJytxZbwVM=; b=CaJCF+Ut4+fp0euaRNosEJ0+zYbVC5DJBYCBoaCM/Ta7mZpi0TIN0doFHLGqpMAYv3 KL9LzXaZcL8wmGKubksSn9bjdSC8If/vVxCKIVQPzCdgmJx4ogqShBYcPZfpB1pL/mAI RPip0q3RfpT5bNMxbzG0vloKfFYX3+uJ486DKYs+rJUylupPn518FsodC7ao4/egBijf zPXtyDx4iv8+WGY9jBX+EBbaDv2eclRZxitXE2GqPu9ITLdTxr9mRk1ahoip+gwIXPP4 CH8GQjTP3d+IJrNuz1iU9u/Z8JOm5Y7g3StzHMTQFot6WFFpysnohxOWN+rP9cxk4jia dyWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795543113; x=1796147913; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aQUx3TL65pMyWzlf2bMKB3xiAtfdB/7ZATJytxZbwVM=; b=i+uVWDATlSjEFNPZNGdPBJaIIz86ZdZP/3NG2zKGYPHa7i480Xv1InlpiysEtOyZXv j/8EhVt/OxD+RDTG8cURKyI5hPTyMCFMmJfqS95qdED/8MtKZ5/rFZWO6mDiIK0RAyWH D7h0RUhjC6ZmLWf5ZovRxylEGr6ZFdsubzDM/BgYFhdgJQKQVBcKHW5PyWbL9I+Y0WKP noXVR2KytAuyzJ7+qj2Sox5UNxvFiITzD50RckVeSnXoj3po8WqerukJ1S+/xd9Tm0iP 15Fi/XamCRh57VOybyrd5AC78yM2depd8jTqgTil4Rc50GVSZM+m0hTUlYcEBGb9UFUm ZZaA== X-Forwarded-Encrypted: i=1; AL+hErGrqGcf8l0cD7qtHNCnvvblD+f+ZSdz9bhF1FkBf4DXS4ssCo2veb0r3o0vVQ13l0pR3mc=@vger.kernel.org X-Gm-Message-State: APuU4Z99NI04Xe3mRloya5+0sYV4aU0AHW5Hpyrw/CAIqUSX9qK5Ex9g Sb4zNG+McbJ5p7U0rI11eEh9tahjlaxnf1dmOEML495AaHChw+2bJtVItCugfCyMkOc= X-Gm-Gg: AZFdTZeuT8z1gfEmaX+bdzxyvpVW6Uy00EykNDcZZQjjeDs/OzGsGgMrfmkBb24PSYP 4NfxpPvi1bVjNLjhzk0yTCtR68vIWAG59ro8zpPWraD1NXuQG5fiNFD9l6NO9V1CXFw9TZNNAo0 x5GU1KRAXVObjU9nHl/3sNOEXbwj37VY7qS8dhMus24JAB/QUOCx1CTxiVFyJM9dDrebgej2DYu ugRGtQLMuC/p3+30AKFaAYql0x5FJQEp3rzfVkP8OFutLQnbZ1rskz6v3Qni8BMs9fePfME0nuL cE0DDTsm83ILy31wsCxycG1aNUbGvAGevUpQryt3vvUhT4mu7MiZ5x6YH3rVsRZ8WvIF8XCv9GH u82GAv3BfJBWqaeMTowKcAo2FjmIrdnbmpBt2AAEuSeg8lTJLVaLcMGpqYPI3kqArXzG6PQV7h+ +04DTXGHBtu1R/sQBoTi/imomn5F7p0+hdg05Y5LMeBVe0pf+OKHAlFLTdhJ7azCYyyhF7XxZum g1vYGKac8HWKJ0JxEBztIPSdbaV9G/kyQlylc+XnDIbE3pOQyqHxOVAP7uX4QfMaYzXEVG/paZA DVs9Q2QgxNwiHMG60ncu9uCAlccuMZLBVRwq5TbMyOg6fus= X-Received: by 2002:a05:6402:42c2:b0:6ba:90e0:cc06 with SMTP id 4fb4d7f45d1cf-6ba90e0cdc0mr7601394a12.28.1795543112897; Tue, 24 Nov 2026 09:58:32 -0800 (PST) Received: from L9JK9NPFH9 ([2a09:bac6:37ad:1e5a::306:5]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6ba3711ad52sm7205762a12.35.2026.11.24.09.58.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Nov 2026 09:58:32 -0800 (PST) From: Tianyi Gao To: netdev@vger.kernel.org, Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: "David S. Miller" , Simon Horman , David Keogh , Jesper Dangaard Brouer , Daniel Borkmann , David Woodhouse , Dragos Tatulea , Nimrod Oren , Alasdair McWilliam , Willem de Bruijn , Maciej Fijalkowski , Stanislav Fomichev , Magnus Karlsson , David Ahern , Ido Schimmel , Alexei Starovoitov , John Fastabend , Donald Hunter , Andrew Lunn , Jonathan Corbet , Shuah Khan , Shuah Khan , Randy Dunlap , Breno Leitao , =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Danielle Ratson , Kuniyuki Iwashima , bpf@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@cloudflare.com, nh-open-source@amazon.com, Stephen Hemminger , "Gustavo A. R. Silva" , "Remy D. Farley" , Amery Hung , Andrii Nakryiko , Andy Roulin , Anil Kaushik , Demos Ra , Eduard Zingerman , Emil Tsalapatis , Hangbin Liu , Ihor Solodrai , Jiayuan Chen , Jiri Olsa , Joe Damato , Kumar Kartikeya Dwivedi , Li RongQing , Louis Scalbert , Marc Kleine-Budde , Martin KaFai Lau , Martin Karsten , Matt Bobrowski , Michael Bommarito , Nikolay Aleksandrov , Runyu Xiao , Song Liu , Thorsten Leemhuis , Wang Zhan , Yonghong Song , Zhou Qiuyue , Sebastian Andrzej Siewior , Jeff Layton , Tianyi Gao , Tianyi Gao Subject: [PATCH net-next v3 00/11] net: extra TX headroom for local egress Date: Tue, 24 Nov 2026 17:58:13 +0000 Message-ID: <20261124175824.60470-1-tianyi@cloudflare.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This is v3 of the series that David Keogh posted as an RFC [1]. v1 is [2], v2 is [3]. Locally generated UDP, raw and AF_PACKET packets, and AF_XDP packets in copy mode, get only the headroom that needed_headroom asks for. If an XDP or TC program needs more, the skb is reallocated or copied for every packet. This happens in three cases: - An XDP program on a veth peer needs XDP_PACKET_HEADROOM (256 bytes). The peer copies the packet. - A program at TC egress adds headers. The skb is reallocated. - A namespace sends through a veth pair, and a program at TC egress of another device, such as the host uplink, adds headers. The skb is reallocated on that device. (patches 1-2, from David Keogh) This series adds tx_extra_headroom to struct net_device. It is added only where a locally generated skb is allocated. Each case sets tx_extra_headroom in its own way, to keep the new UAPI minimal: - (patches 3-5) The kernel sets it when XDP is attached to the peer of a veth or netkit device. New skbs on the device then reserve enough headroom for XDP_PACKET_HEADROOM. - (patches 6-8) Add a BTF decl tag "tx_extra_headroom:" as UAPI. A tcx egress program declares it, and the verifier reads it at load. - (patches 9-11) Add a VETH_INFO_TX_EXTRA_HEADROOM UAPI for headers that another device pushes, such as the host uplink. It is like IFLA_NETKIT_HEADROOM for netkit [4]. The CNI plugin sets it at veth creation, as Cilium does with netkit [5]. tx_extra_headroom is the sum of the extra headroom that each case requires, limited to 512 bytes. For example, a program at TC egress pushes a header, and XDP on the peer then still needs XDP_PACKET_HEADROOM in front of it. The kernel recalculates tx_extra_headroom when XDP or a tcx program is attached or detached. For all three cases, one option is to raise needed_headroom instead. This causes a regression for TCP and forwarding, because needed_headroom is also the minimum that ip_finish_output2() and ip_forward() require. Patch 3 depends on commit f564749b3b26 ("net: record XDP programs propagated to lower devices"), which is only in net-next, so the series targets net-next. Patches 6-8 change tcx and the verifier. An Ack from the BPF maintainers on them would be appreciated. Performance: All tests run on a Xeon E5-2640 v4 with a ConnectX-4 Lx NIC, on net-next at d6816d9a93b6. Details of the artifacts are in [6]. The first table shows the regression when needed_headroom is raised to 256 on both ends of a veth pair. XDP runs on the namespace side: test net-next needed_headroom 256 netns sends TCP to host 32.1 Gbit/s 30.8 Gbit/s host forwards 1400B UDP into netns 0.583 Mpps 0.366 Mpps The second table shows the gain from tx_extra_headroom in all three cases, with 1400-byte UDP payloads. All numbers come from one kernel with this series applied, with tx_extra_headroom off and on. Between two kernels, the code layout alone changed the rate by up to 13%. Off uses a benchmark-only patch for the XDP case [6], the push program without its decl tag, and a veth pair without VETH_INFO_TX_EXTRA_HEADROOM: test off on host to netns, generic XDP_PASS in netns 0.237 Mpps 0.283 Mpps host to netns, generic XDP_DROP in netns 0.386 Mpps 0.465 Mpps host to netns, 20-byte push at TC egress 0.385 Mpps 0.468 Mpps netns to uplink, 20-byte push on the uplink 0.190 Mpps 0.219 Mpps Out of scope: - Auto-tuning for the second and third cases [7]. - Backlinking the originating netdev to set tx_extra_headroom for the third case [8]. - Native XDP on veth. veth_convert_skb_to_xdp_buff() still copies these packets. A follow-up veth patch changes this for XDP_PASS and XDP_DROP. Changes: v3: - Mount bpffs on /sys/fs/bpf in tx_extra_headroom.py if needed. NIPA's VMs boot without it (Paolo). - Mention in 3/11 and in the documentation that native XDP on veth still copies locally generated packets (Sashiko). - Document which packets get tx_extra_headroom, and the -EEXIST failure for two decl tags (Sashiko). - Bind in copy mode with xdp_helper -t (Sashiko). - Add the maximum of tx-extra-headroom to rt-link.yaml (Sashiko). - Check the value set at veth creation at tcx ingress of the peer (Sashiko). v2 [3]: - Drop "configurable" from the series title and rework the cover letter. - Drop IFLA_TX_EXTRA_HEADROOM (Willem, Stephen). - Set tx_extra_headroom on veth XDP attach (Stephen), from the BPF decl tag "tx_extra_headroom:" on tcx attach (Dragos, Willem), and with VETH_INFO_TX_EXTRA_HEADROOM at veth creation. - Turn the LL_ALLOC_SPACE() and LL_ALLOC_SPACE_EX() macros into static inline functions (Willem). - Test the veth attribute with YNL only (Jakub). v1 [2]: - Add the veth XDP case and the needed_headroom regression data to the cover letter. - Remove LL_RESERVED_SPACE_EXTRA(), which has no user. - Replace the RFC data-path selftests with a test of a push at TC egress. - Add tests of generic XDP on a veth peer and of setting both ends of a veth pair. RFC: [1] [1] https://lore.kernel.org/all/20261015235335.4162993-1-dkeogh@amazon.com/ [2] https://lore.kernel.org/all/cover.1794020868.git.tianyi@cloudflare.com/ [3] https://lore.kernel.org/all/20261119013830.36935-1-tianyi@cloudflare.com/ [4] https://git.kernel.org/torvalds/c/b9ed315d3c4c [5] https://github.com/cilium/cilium/blob/4a5cd2a20e31/pkg/datapath/connector/netkit.go#L63-L67 [6] https://github.com/tgao-cf/tx-extra-headroom-bench/tree/main [7] https://lore.kernel.org/all/20261108214356.95406-1-tianyi@cloudflare.com/ [8] https://lore.kernel.org/all/20261110201250.95225-1-tianyi@cloudflare.com/ --- David Keogh will post a TCP test as a reply to this series. The iproute2 patch for VETH_INFO_TX_EXTRA_HEADROOM will be posted after this series is accepted. David Keogh (2): net: add tx_extra_headroom and netdev_get_alloc_headroom() net: reserve extra TX headroom for local egress Tianyi Gao (9): net: set tx_extra_headroom of the peer on XDP attach selftests: net: add flag to send a frame in xdp_helper selftests: net: add tx_extra_headroom test bpf, tcx: Set tx_extra_headroom from a decl tag on egress programs selftests: net: tx_extra_headroom: test a push at TC egress selftests/bpf: Test the tx_extra_headroom decl tag veth: add VETH_INFO_TX_EXTRA_HEADROOM netlink: specs: rt-link: add veth attributes selftests: net: tx_extra_headroom: test the veth attribute Documentation/netlink/specs/rt-link.yaml | 16 + .../networking/net_cachelines/net_device.rst | 1 + Documentation/networking/netdevices.rst | 49 ++ drivers/net/veth.c | 44 ++ include/linux/bpf.h | 1 + include/linux/netdevice.h | 40 +- include/net/tcx.h | 6 + include/uapi/linux/veth.h | 5 +- kernel/bpf/tcx.c | 24 + kernel/bpf/verifier.c | 31 ++ net/core/dev.c | 44 ++ net/ipv4/ip_output.c | 2 +- net/ipv4/raw.c | 2 +- net/ipv6/ip6_output.c | 2 +- net/ipv6/raw.c | 2 +- net/packet/af_packet.c | 7 +- net/xdp/xsk.c | 6 +- tools/net/ynl/Makefile.deps | 3 +- .../selftests/bpf/prog_tests/verifier.c | 2 + .../bpf/progs/verifier_tx_extra_headroom.c | 40 ++ tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/lib/xdp_helper.c | 85 +++- .../selftests/net/tx_extra_headroom.bpf.c | 138 ++++++ .../selftests/net/tx_extra_headroom.py | 437 ++++++++++++++++++ 24 files changed, 964 insertions(+), 24 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/verifier_tx_extra_headroom.c create mode 100644 tools/testing/selftests/net/tx_extra_headroom.bpf.c create mode 100755 tools/testing/selftests/net/tx_extra_headroom.py base-commit: c2621b518b38ed38e280e008aa33e6c2d302f8cc -- 2.56.0