From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795543173; b=1JLiTB5cquZ6Ehdwr4lYFAotbpgXp6XsE1Cx8Jc+w8tinq587gukyDurb2WHTJe8A/+V xqigsTKqs57trQvDyF3gIw1MVgZYKjdtMWMlCfaDxa4ZNxS+5BoVkuBA02a/6kUX8y6pt uZ5Tw0+20jzakTQWFzx1E8UERkMoxare3ovVUlMX59Ul9QWWE02ugfIauOxzOS42e/Q+O 0G+F/w7mZC7FFJvjuutdJlTJRJms6Fnt8b4f+vBPktQIQXR8uyNJxFsOmX3wMtnsBwXvP ERl4M0wp0L1roR7cnASyY05E8qeeyRGRkH6iY24PLQpr6eRgMMRZIemDJ/mU0B418Fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795543173; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=VstwBcVMyFIpXX/g8y4uvl7osWjH+5lZKKsPgtW24Oc=; b=2Ui/iP9QgYk2jCzLT6oJofzmln3EJZ8LEwKybYzc8vIA4LP5HR/UwjQ0rjRPMtVVrJ0m LFtD0U21RyWW2GpoieIjnkNLbk2EFjIFctu9Wbmf+p6ghy0mSTauzsPR70FH2oZzbPdV/ pAJxTQhiMJkJzorNFSDOuhe9ZJGJz69xW/tk/dXuJZ+r3+yAlAyuQdPqD4wYVE9PFcEAn O44Z7sTVW87FItZCDmNQ6ZidHBX69xesmhSR2aUmtkMXong0Gpa1bKQtZbsixCFvIOBaM twk9zCVoaSVDHxOEV2WZdKFJn4SUaBvvltPmbM55bJQw9BI9SNMyOn2hFI3BXp5gU5g== 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=Jrr002Km; arc=none smtp.remote-ip=209.85.208.46 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 9F6B5606A321 for ; Tue, 24 Nov 2026 17:59:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F6B5606A321 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=Jrr002Km Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-6b47c1a3c74so6597559a12.3 for ; Tue, 24 Nov 2026 09:59:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1795543171; x=1796147971; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VstwBcVMyFIpXX/g8y4uvl7osWjH+5lZKKsPgtW24Oc=; b=Jrr002KmZMdjmj84UDe2P0H7GbLpNHFvoTA1wnEQ7c9pgiAZ1SZ0l3cbfYhBCB7LJ3 fplxaTNGi73FiLhUHANqUifOA+wK/1+BfHxDb70iH3tqlY568hSPfTpSHaosctnTYZSj oNKaulN4KG2nyP9MIVLBzomPgdG+DwroARfjl7szX1wNIi8+s6vSA+HGUdnMZmjQ+YtY 1ZliiDyJJoHHxCQ8a5DnytA2Nx40aBdXtlpvai9K2CH103KNbQhCPL8R3wnA06tPTh2h e++7Mo8NH2rgA6uG69VEmdjXOYB6/pnwGnvAQQkTr/dmKMwKqHJ6FwIu+TNUTutQgO4p xLyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795543171; x=1796147971; h=content-transfer-encoding:mime-version:references:in-reply-to :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=VstwBcVMyFIpXX/g8y4uvl7osWjH+5lZKKsPgtW24Oc=; b=QCj+3rZkHmFKLa79P709bUtN4JjI5fAF3ty21/F0YnoiSjOgem6yPhssjtS2Ne1o9t Sxg40n6R4W7T91lRgS4kpfdC1xe1xZ6Mh9x2ZG0vf1m21WVru7iipr2xShuD21W1+RlD VwSSugMldQ/yfL9lPFacDVFIwlw07juKrjBkIq39aAumons+/iok2iJqWaz9cdmFMgDt /o1sUUyuV+NIYQ8VxnkooFcVjS+N2nWRwcHV1KvlN2TvAq4y1dinD0KAbdXK3qvhzF31 bxsFZ3WuU3RVIQYfx2yjtU81/SdYy5ss/bDAFMItn8FR8foa1c6NGgw38R4FLg1vXSOc JTdw== X-Forwarded-Encrypted: i=1; AL+hErEiZbd4h6+LlLoEdITq7xtj5LsSEbcR6MRe6I/CBQYl9Q7HDpt9EeDCf6ixH34LYLRpeXdMqr2Gw+o=@vger.kernel.org X-Gm-Message-State: APuU4Z9MpAW2xu62aczrQhv2FR8eighh1rjh2ZMty3WfbSu3+CSmaJK0 y0EPtBdDsjfkpVOvOxjef/Mq56TSSvOhyMrSokaaRXdwsCI38OWa5DKuDJ6P8czl4mc= X-Gm-Gg: AZFdTZeIaslQy61CTh1E2ZKVgZj2Cvkn7GKS6AXfq9XPfnVf2rP6SyTuo33N6duu7bl 4OVAHOmZtS+1UXjWHTK84S8XkD547uXxCELwEy85u5ewME48xXE0lgSJMXGhMVD23hKRLul84w+ Ks20sTAtMkS9Tkry8r2EuXZO4kOAU7EYKz5B0ldjp9bvMG9jk/2NQU6Dj/tZCxj7WuCJ36w3S4+ q07h1qcwUt+O5nqu/jRopf2na141RZyvpRETqt0K7k8+pHzKdmRtfuUnQdYBEIVKOieCKZ1kjsH pFJv5atjw4SUg9Hg3K/1nBLFaLnJj0IZjerg7lNxe2t1rsZd5ouRBBn539juvljLC/fSTmeZVqh CcGE3LBHcBAee9UHNAX4ocEPR8Hhw87cLrY2cV22YL8yNSSAFuIIB2v31XQJlLMD+/ViVHTiM14 FdTFo3KVRoogCzDjBD2V4txm0shAo4EpitK8iAP1pDpNcv+/ypEZXWe9VLbiReo+cVzEE0e8oqB 95QObeV+aMsrZ9hE/91tRV0IOHCl5rStWJhUb3rBSCWZRHTCKyZfiJw1zbVYIsGXCKFOGV8EiW6 MuFI6ydRUIypvCavM5oUMYXDSQISuAuBMb1y46HyHY9wjY8= X-Received: by 2002:a05:6402:15c3:b0:6b5:9133:309f with SMTP id 4fb4d7f45d1cf-6ba37c7a619mr8952583a12.2.1795543170978; Tue, 24 Nov 2026 09:59:30 -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.59.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Nov 2026 09:59:29 -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 09/11] veth: add VETH_INFO_TX_EXTRA_HEADROOM Date: Tue, 24 Nov 2026 17:58:22 +0000 Message-ID: <20261124175824.60470-10-tianyi@cloudflare.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261124175824.60470-1-tianyi@cloudflare.com> References: <20261124175824.60470-1-tianyi@cloudflare.com> X-Mailing-List: linux-doc@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 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 --- 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 280ad3bf5559..a427e445ba35 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -464,6 +464,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 The kernel updates ``tx_extra_headroom`` when an XDP program is attached to or detached from the peer, to reserve the headroom that XDP needs. @@ -485,6 +486,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``. Loading a program with two tags fails with ``-EEXIST``. +``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 2051f6e04432..973040c371dc 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; }; @@ -1548,6 +1549,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) { @@ -1699,6 +1707,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, @@ -1800,6 +1809,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; @@ -1822,6 +1832,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; @@ -1843,6 +1857,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; @@ -1876,6 +1893,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; @@ -1898,6 +1918,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); @@ -1940,9 +1962,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); @@ -1971,6 +2013,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 2486b0d10474..94acbf3ea581 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 dd34daf5f3b4..76007f788bdf 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10693,6 +10693,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