From: Tianyi Gao <tianyi@cloudflare.com>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
"Simon Horman" <horms@kernel.org>,
"David Keogh" <dkeogh@amazon.com>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"David Woodhouse" <dwmw2@infradead.org>,
"Dragos Tatulea" <dtatulea@nvidia.com>,
"Nimrod Oren" <noren@nvidia.com>,
"Alasdair McWilliam" <alasdair@mcwilliam.dev>,
"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Magnus Karlsson" <magnus.karlsson@intel.com>,
"David Ahern" <dsahern@kernel.org>,
"Ido Schimmel" <idosch@nvidia.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
"Donald Hunter" <donald.hunter@gmail.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Shuah Khan" <shuah@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Breno Leitao" <leitao@debian.org>,
"Asbjørn Sloth Tønnesen" <ast@fiberby.net>,
"Danielle Ratson" <danieller@nvidia.com>,
"Kuniyuki Iwashima" <kuniyu@google.com>,
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" <stephen@networkplumber.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"Remy D. Farley" <one-d-wide@protonmail.com>,
"Amery Hung" <ameryhung@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Andy Roulin" <aroulin@nvidia.com>,
"Anil Kaushik" <anilkaushikwireless@gmail.com>,
"Demos Ra" <demosthenes.ra@gmail.com>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Hangbin Liu" <hangbin.liu@linux.dev>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Jiayuan Chen" <jiayuan.chen@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>, "Joe Damato" <joe@dama.to>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Li RongQing" <lirongqing@baidu.com>,
"Louis Scalbert" <louis.scalbert@6wind.com>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Martin Karsten" <mkarsten@uwaterloo.ca>,
"Matt Bobrowski" <mattbobrowski@google.com>,
"Michael Bommarito" <michael.bommarito@gmail.com>,
"Nikolay Aleksandrov" <razor@blackwall.org>,
"Runyu Xiao" <runyu.xiao@seu.edu.cn>,
"Song Liu" <song@kernel.org>,
"Thorsten Leemhuis" <linux@leemhuis.info>,
"Wang Zhan" <wang.zhan@smartx.com>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Zhou Qiuyue" <n0ps1edzz@gmail.com>,
"Tianyi Gao" <tianyi.gao@linux.dev>,
"Tianyi Gao" <tianyi@cloudflare.com>
Subject: [PATCH net-next v2 09/11] veth: add VETH_INFO_TX_EXTRA_HEADROOM
Date: Thu, 19 Nov 2026 01:38:28 +0000 [thread overview]
Message-ID: <20261119013830.36935-10-tianyi@cloudflare.com> (raw)
In-Reply-To: <20261119013830.36935-1-tianyi@cloudflare.com>
Packets that a namespace sends through a veth pair can be encapsulated
on another device, for example by a program at TC egress of the host
uplink. The veth device cannot see this, so the packets are reallocated
on the uplink.
Add VETH_INFO_TX_EXTRA_HEADROOM, so that the CNI plugin can set the
headroom for both devices when it creates the pair. It cannot be changed
later, like IFLA_NETKIT_HEADROOM.
Store the value in struct veth_priv, and add ndo_get_tx_extra_headroom
so that the core reads it whenever it recalculates tx_extra_headroom.
The value cannot be written to tx_extra_headroom itself, because the
core recalculates tx_extra_headroom from scratch when XDP on the peer
or a program at tcx egress is attached or detached. A new field in
struct net_device would also work, but it would grow struct net_device.
IFLA_NETKIT_HEADROOM, added by commit b9ed315d3c4c ("netkit: Allow for
configuring needed_{head,tail}room"), is similar but differs in two
ways:
- it is the total headroom of the device and sets needed_headroom;
- it is a u16. The new attribute is a uint, as commit 374d345d9b5e
("netlink: add variable-length / auto integers") recommends.
Signed-off-by: Tianyi Gao <tianyi@cloudflare.com>
---
The iproute2 patch for VETH_INFO_TX_EXTRA_HEADROOM will be posted after
this series is accepted.
v2:
- New patch, replaces IFLA_TX_EXTRA_HEADROOM for headers pushed on
another device (Willem, Stephen).
---
Documentation/networking/netdevices.rst | 5 +++
drivers/net/veth.c | 44 +++++++++++++++++++++++++
include/linux/netdevice.h | 5 +++
include/uapi/linux/veth.h | 1 +
net/core/dev.c | 3 ++
5 files changed, 58 insertions(+)
diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst
index 128a93303a6d..cf7b84897f61 100644
--- a/Documentation/networking/netdevices.rst
+++ b/Documentation/networking/netdevices.rst
@@ -460,6 +460,7 @@ values:
* ``XDP_PACKET_HEADROOM`` (256 bytes) minus ``needed_headroom``, when the
peer of a veth or netkit device has an XDP program
* the headroom that the programs at tcx egress of the device declare
+* ``VETH_INFO_TX_EXTRA_HEADROOM`` of a veth device
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
@@ -480,6 +481,10 @@ tail call targets, freplace programs and programs at tcx ingress are
ignored. Loading a program whose tag is above 512 or does not parse fails
with ``-EINVAL``.
+``VETH_INFO_TX_EXTRA_HEADROOM`` is for headers that are pushed on another
+device, for example at TC egress of the uplink. It is set for both
+devices of a veth pair when the pair is created.
+
NETDEV_INTERNAL symbol namespace
================================
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 0539b3661793..06f691568f3a 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -77,6 +77,7 @@ struct veth_priv {
struct bpf_prog *_xdp_prog;
struct veth_rq *rq;
unsigned int requested_headroom;
+ unsigned int tx_extra_headroom;
netdevice_tracker peer_tracker;
};
@@ -1580,6 +1581,13 @@ static void veth_set_rx_headroom(struct net_device *dev, int new_hr)
rcu_read_unlock();
}
+static unsigned int veth_get_tx_extra_headroom(const struct net_device *dev)
+{
+ const struct veth_priv *priv = netdev_priv(dev);
+
+ return priv->tx_extra_headroom;
+}
+
static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog,
struct netlink_ext_ack *extack)
{
@@ -1731,6 +1739,7 @@ static const struct net_device_ops veth_netdev_ops = {
.ndo_set_features = veth_set_features,
.ndo_features_check = passthru_features_check,
.ndo_set_rx_headroom = veth_set_rx_headroom,
+ .ndo_get_tx_extra_headroom = veth_get_tx_extra_headroom,
.ndo_bpf = veth_xdp,
.ndo_xdp_xmit = veth_ndo_xdp_xmit,
.ndo_get_peer_dev = veth_peer_dev,
@@ -1832,6 +1841,7 @@ static int veth_newlink(struct net_device *dev,
struct net *peer_net = rtnl_newlink_peer_net(params);
struct nlattr **data = params->data;
struct nlattr **tb = params->tb;
+ unsigned int tx_extra_headroom = 0;
int err;
struct net_device *peer;
struct veth_priv *priv;
@@ -1854,6 +1864,10 @@ static int veth_newlink(struct net_device *dev,
tbp = tb;
}
+ if (data && data[VETH_INFO_TX_EXTRA_HEADROOM])
+ tx_extra_headroom =
+ nla_get_uint(data[VETH_INFO_TX_EXTRA_HEADROOM]);
+
if (ifmp && tbp[IFLA_IFNAME]) {
nla_strscpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ);
name_assign_type = NET_NAME_USER;
@@ -1875,6 +1889,9 @@ static int veth_newlink(struct net_device *dev,
netif_inherit_tso_max(peer, dev);
+ priv = netdev_priv(peer);
+ priv->tx_extra_headroom = tx_extra_headroom;
+
err = veth_init_queues(peer, tbp);
if (err)
goto err_register_peer;
@@ -1908,6 +1925,9 @@ static int veth_newlink(struct net_device *dev,
else
snprintf(dev->name, IFNAMSIZ, DRV_NAME "%%d");
+ priv = netdev_priv(dev);
+ priv->tx_extra_headroom = tx_extra_headroom;
+
err = veth_init_queues(dev, tb);
if (err)
goto err_register_dev;
@@ -1930,6 +1950,8 @@ static int veth_newlink(struct net_device *dev,
rcu_assign_pointer(priv->peer, dev);
netdev_hold(dev, &priv->peer_tracker, GFP_KERNEL);
+ netdev_update_tx_extra_headroom(dev);
+
veth_disable_gro(dev);
/* update XDP supported features */
veth_set_xdp_features(dev);
@@ -1972,9 +1994,29 @@ static void veth_dellink(struct net_device *dev, struct list_head *head)
}
static const struct nla_policy veth_policy[VETH_INFO_MAX + 1] = {
+ [VETH_INFO_UNSPEC] = { .strict_start_type =
+ VETH_INFO_TX_EXTRA_HEADROOM },
[VETH_INFO_PEER] = { .len = sizeof(struct ifinfomsg) },
+ [VETH_INFO_TX_EXTRA_HEADROOM] =
+ NLA_POLICY_MAX(NLA_UINT, NETDEV_TX_EXTRA_HEADROOM_MAX),
};
+static size_t veth_get_size(const struct net_device *dev)
+{
+ return nla_total_size(sizeof(u64)); /* VETH_INFO_TX_EXTRA_HEADROOM */
+}
+
+static int veth_fill_info(struct sk_buff *skb, const struct net_device *dev)
+{
+ const struct veth_priv *priv = netdev_priv(dev);
+
+ if (nla_put_uint(skb, VETH_INFO_TX_EXTRA_HEADROOM,
+ priv->tx_extra_headroom))
+ return -EMSGSIZE;
+
+ return 0;
+}
+
static struct net *veth_get_link_net(const struct net_device *dev)
{
struct veth_priv *priv = netdev_priv(dev);
@@ -2003,6 +2045,8 @@ static struct rtnl_link_ops veth_link_ops = {
.policy = veth_policy,
.peer_type = VETH_INFO_PEER,
.maxtype = VETH_INFO_MAX,
+ .get_size = veth_get_size,
+ .fill_info = veth_fill_info,
.get_link_net = veth_get_link_net,
.get_num_tx_queues = veth_get_num_queues,
.get_num_rx_queues = veth_get_num_queues,
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 786b63f21d4f..b99e3afc89ce 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1416,6 +1416,9 @@ struct netdev_net_notifier {
* appropriate rx headroom value allows avoiding skb head copy on
* forward. Setting a negative value resets the rx headroom to the
* default value.
+ * unsigned int (*ndo_get_tx_extra_headroom)(const struct net_device *dev);
+ * Return the headroom that the device adds to tx_extra_headroom.
+ * The caller must hold RTNL and be under RCU read context.
* int (*ndo_bpf)(struct net_device *dev, struct netdev_bpf *bpf);
* This function is used to set or query state related to XDP on the
* netdevice and manage BPF offload. See definition of
@@ -1688,6 +1691,8 @@ struct net_device_ops {
struct sk_buff *skb);
void (*ndo_set_rx_headroom)(struct net_device *dev,
int needed_headroom);
+ unsigned int (*ndo_get_tx_extra_headroom)(
+ const struct net_device *dev);
int (*ndo_bpf)(struct net_device *dev,
struct netdev_bpf *bpf);
int (*ndo_xdp_xmit)(struct net_device *dev, int n,
diff --git a/include/uapi/linux/veth.h b/include/uapi/linux/veth.h
index 52b58e587e23..04cb408e5b3a 100644
--- a/include/uapi/linux/veth.h
+++ b/include/uapi/linux/veth.h
@@ -5,6 +5,7 @@
enum {
VETH_INFO_UNSPEC,
VETH_INFO_PEER,
+ VETH_INFO_TX_EXTRA_HEADROOM,
__VETH_INFO_MAX
#define VETH_INFO_MAX (__VETH_INFO_MAX - 1)
diff --git a/net/core/dev.c b/net/core/dev.c
index 6d11d5ad13e1..6c655b0a949e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10688,6 +10688,9 @@ static void __netdev_update_tx_extra_headroom(struct net_device *dev,
needed_headroom < XDP_PACKET_HEADROOM)
tx_extra_headroom = XDP_PACKET_HEADROOM - needed_headroom;
tx_extra_headroom += tcx_tx_extra_headroom(dev);
+ if (dev->netdev_ops->ndo_get_tx_extra_headroom)
+ tx_extra_headroom +=
+ dev->netdev_ops->ndo_get_tx_extra_headroom(dev);
WRITE_ONCE(dev->tx_extra_headroom,
min(tx_extra_headroom, NETDEV_TX_EXTRA_HEADROOM_MAX));
--
2.56.0
next prev parent reply other threads:[~2026-11-19 1:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 1:38 [PATCH net-next v2 00/11] net: extra TX headroom for local egress Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 01/11] net: add tx_extra_headroom and netdev_get_alloc_headroom() Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 02/11] net: reserve extra TX headroom for local egress Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 03/11] net: set tx_extra_headroom of the peer on XDP attach Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 04/11] selftests: net: add flag to send a frame in xdp_helper Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 05/11] selftests: net: add tx_extra_headroom test Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 06/11] bpf, tcx: Set tx_extra_headroom from a decl tag on egress programs Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 07/11] selftests: net: tx_extra_headroom: test a push at TC egress Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 08/11] selftests/bpf: Test the tx_extra_headroom decl tag Tianyi Gao
2026-11-19 1:38 ` Tianyi Gao [this message]
2026-11-19 1:38 ` [PATCH net-next v2 10/11] netlink: specs: rt-link: add veth attributes Tianyi Gao
2026-11-19 1:38 ` [PATCH net-next v2 11/11] selftests: net: tx_extra_headroom: test the veth attribute Tianyi Gao
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=20261119013830.36935-10-tianyi@cloudflare.com \
--to=tianyi@cloudflare.com \
--cc=alasdair@mcwilliam.dev \
--cc=ameryhung@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=anilkaushikwireless@gmail.com \
--cc=aroulin@nvidia.com \
--cc=ast@fiberby.net \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=danieller@nvidia.com \
--cc=davem@davemloft.net \
--cc=demosthenes.ra@gmail.com \
--cc=dkeogh@amazon.com \
--cc=donald.hunter@gmail.com \
--cc=dsahern@kernel.org \
--cc=dtatulea@nvidia.com \
--cc=dwmw2@infradead.org \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=gustavoars@kernel.org \
--cc=hangbin.liu@linux.dev \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ihor.solodrai@linux.dev \
--cc=jiayuan.chen@linux.dev \
--cc=joe@dama.to \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leitao@debian.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@leemhuis.info \
--cc=lirongqing@baidu.com \
--cc=louis.scalbert@6wind.com \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=mattbobrowski@google.com \
--cc=memxor@gmail.com \
--cc=michael.bommarito@gmail.com \
--cc=mkarsten@uwaterloo.ca \
--cc=mkl@pengutronix.de \
--cc=n0ps1edzz@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nh-open-source@amazon.com \
--cc=noren@nvidia.com \
--cc=one-d-wide@protonmail.com \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=rdunlap@infradead.org \
--cc=runyu.xiao@seu.edu.cn \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=song@kernel.org \
--cc=stephen@networkplumber.org \
--cc=tianyi.gao@linux.dev \
--cc=wang.zhan@smartx.com \
--cc=willemdebruijn.kernel@gmail.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