From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796401678; b=kV3dm9PWkHUZjS6u4i3kyqV0QbEB1o5g54lal+9fk7ZZPfcu1nhYLfgWoYW7PN2/HAfS j37g2lGb/z1/ACgIMY7SHQbihK01V2pVmbepsHdEmluMZF9d+OkoMMReTNtmmRIqv8NqY F9RnsI3NqZsTeXn7bv2BZOppC1P1Z6/8FV2tJ2R1K7lY2ELWv43hqGDrEvz2N8rUr2Dky N+KViNYh5A2o54GCkNH3FaXbio2R3OfN/Mn35gW15Zlx0lGdcl40jK37Glm5XOYDOb97G LwkM67/19M6E4OYEYd4FhkA+405rE1wPKv7nBsec4+7HniEoZ6e8pXdvMqFVnbBlkbw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796401678; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=ytm8fd6whRx+25y8ADBsNQuX7TeR+E/2oxToW/6StCY=; b=u7cMaBi4th6KnqGDiSdvZd0M3t3k4L+kpr02BCoIhOrokgIMq9bax8LbLRTsNz6naJA0 bpoMIPjjhpuvhTEKnGRG/c7YVQGAQu3Q5SoedBx0AglKQ2p8+FKZ2fLpw1CV4EoU83EqA Eh3GRT6DOTyF8zz3G1e1xPPquAWKcANqPoEJcKbGmMkSEGcwZUA7NnEFiFrOfsqulCPVm Dd/bVSG5sQe1fvOgF2zEbTID/6icSHP/1xD50muVix3ecShOsgplf48LaJw+ALE59/ucr m4F6NePHx5994AxnjQX1FUWsVNzn4nOc0WutAg2B2zkiKo5WR0TryN5vbZmD1u5Nf/g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e2bX2dqW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7526F606A322; Fri, 4 Dec 2026 16:27:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e2bX2dqW Received: by smtp.kernel.org (Postfix) with ESMTPSA id A58831F000CE; Fri, 4 Dec 2026 16:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796401678; bh=ytm8fd6whRx+25y8ADBsNQuX7TeR+E/2oxToW/6StCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e2bX2dqWBx93OkZfFj8jpldPpq4Pm/pw2XQASluFGWLdI6q6TZMBvSLJasXIjZbfb 5j9NYjEKk9bad/Y6nxqkjZZmPQbNxbKFMqj+9J7O2t0j70T7jCu/r1utoFpO2I8Cra bjtg0jPsdrT+yG7u3XbRHi/NNpZhKXtmQ5mYUpacR1fSFd67OrBSKb/hHWNfl/Uv3J zgFMGmXmYPfHP7/0SOvr8KdHwqyIPeXCW39FRyx5dI5K7Acx6RO7GhrcNBoJ8vPxto uHcglOnnUnNEMLWUfufDVyBSOdVDk8z43Hv/ZCgTINUbL39tuElc0yRMu60MCxBEAi C916Duzz9GL7Q== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Nikolay Aleksandrov , Andrew Lunn , Ilias Apalodimas , Magnus Karlsson , Maciej Fijalkowski , Donald Hunter , Alexander Duyck , Saeed Mahameed , Tariq Toukan , Mark Bloch , Leon Romanovsky , Shuah Khan , Jonathan Corbet , netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Simon Horman , Stanislav Fomichev , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , David Wei , Tao Cui , linux-kernel@vger.kernel.org, kernel-team@meta.com, "Mike Marciniszyn (Meta)" , linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan , Randy Dunlap , linux-doc@vger.kernel.org Subject: [PATCH net-next v2 02/15] net: Add memory providers that only feed XDP Date: Fri, 4 Dec 2026 17:27:07 +0100 Message-ID: <20261204162723.755897-3-bjorn@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204162723.755897-1-bjorn@kernel.org> References: <20261204162723.755897-1-bjorn@kernel.org> X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So far, the core requires header split for memory providers and refuses native XDP next to them, as they serve payload to the stack. The AF_XDP provider later in this series feeds only XDP. Let a provider declare itself XDP-only with MP_XDP_ONLY, which lifts both rules. Drivers opt in with PP_FLAG_ALLOW_XDP_ONLY_NETMEM, and the install fails on others. The provider takes no lock. With the flag, the driver lets one context at a time use the queue's buffers, its NAPI or an operation that runs only while that NAPI cannot use the rings. It runs that NAPI once after the queue starts, so that a queue that starts with FILL empty asks for a wakeup, and passes the buffers only to the queue's AF_XDP socket. Add netif_rxq_has_xdp_only_mp() for drivers that size a queue before its page pools exist. Until now, classic zero copy could not bind next to any provider of the device. Refuse it only next to providers that block native XDP. Signed-off-by: Björn Töpel --- Notes (v2changes): Changes in v2: - Fold in v1 patch 11, netif_rxq_has_xdp_only_mp(), which drivers call before the page pools of a queue exist. - Refuse classic zero copy, also through netkit, only next to providers that block native XDP, so that it binds next to an XDP-only provider on another queue of the device, in either order (Sashiko). - Say that the private data of such a provider starts with its net_iov area, and that a driver that sets the flag lets one context at a time use the buffers of the queue and runs its NAPI once after a start, as the provider takes no lock. - Say in a comment that the core counts an XDP-only provider as unreadable. drivers/net/netkit.c | 2 +- include/linux/netdevice.h | 1 + include/net/netdev_queues.h | 1 + include/net/page_pool/helpers.h | 4 +- include/net/page_pool/memory_provider.h | 19 +++++++++ include/net/page_pool/types.h | 23 ++++++++++- net/core/dev.c | 21 +++++++++- net/core/netdev_rx_queue.c | 51 +++++++++++++++++++++---- net/core/page_pool.c | 16 ++++++-- net/ethtool/rings.c | 5 ++- net/xdp/xsk_buff_pool.c | 2 +- 11 files changed, 126 insertions(+), 19 deletions(-) diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c index 82e608e733d9..b1f8e3b9292a 100644 --- a/drivers/net/netkit.c +++ b/drivers/net/netkit.c @@ -289,7 +289,7 @@ static int netkit_xsk(struct net_device *dev, struct netdev_bpf *xdp) ret = -EOPNOTSUPP; goto out; } - if (!create || !dev_get_min_mp_channel_count(phys)) + if (!create || !dev_mp_blocks_xdp(phys)) ret = phys->netdev_ops->ndo_bpf(phys, &xdp_lower); out: netdev_unlock(phys); diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 694b6d29f680..9e542d793df7 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4459,6 +4459,7 @@ u8 dev_xdp_sb_prog_count(struct net_device *dev); u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode); u32 dev_get_min_mp_channel_count(const struct net_device *dev); +bool dev_mp_blocks_xdp(const struct net_device *dev); int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb); int dev_forward_skb(struct net_device *dev, struct sk_buff *skb); diff --git a/include/net/netdev_queues.h b/include/net/netdev_queues.h index c5335e935b7d..813388778797 100644 --- a/include/net/netdev_queues.h +++ b/include/net/netdev_queues.h @@ -235,6 +235,7 @@ void netdev_queue_config(struct net_device *dev, int rxq, struct netdev_queue_config *qcfg); bool netif_rxq_has_unreadable_mp(struct net_device *dev, unsigned int rxq_idx); +bool netif_rxq_has_xdp_only_mp(struct net_device *dev, unsigned int rxq_idx); /** * DOC: Lockless queue stopping / waking helpers. diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 28635ce9454e..e3cca0a8efa1 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -513,7 +513,9 @@ static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid) * kernel. This will only be the case if user space bound a memory provider (mp) * which returns unreadable memory to the queue served by the page pool. * If %PP_FLAG_ALLOW_UNREADABLE_NETMEM was set but there is no mp bound - * this helper will return false. See also netif_rxq_has_unreadable_mp(). + * this helper will return false. An XDP-only mp is unreadable here too, + * though netif_rxq_has_unreadable_mp() leaves it out, as its queue needs + * no header split. * * Return: true if memory allocated by the page pool may be unreadable */ diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h index bceb5f7740e2..ae300f9504d0 100644 --- a/include/net/page_pool/memory_provider.h +++ b/include/net/page_pool/memory_provider.h @@ -19,6 +19,24 @@ struct sk_buff; * Per-provider custom logic must be delegated to memory_provider_ops rather * than handled directly in page_pool core code. */ + +/** + * enum mp_flags - how a memory provider differs from the default + * @MP_XDP_ONLY: Only XDP consumes the buffers: they never reach the stack. + * They back the RX page pools of the queue that set + * %PP_FLAG_ALLOW_XDP_ONLY_NETMEM, so header split is not needed, and + * native XDP may run next to them. + * XDP may read them, but userspace may write them at any time, + * so the kernel must keep its own data out of them. + * The core finds the &net_iov_area of such a provider at the start + * of &page_pool.mp_priv, which must point to a struct that begins + * with one. The driver uses the buffers of the queue from one + * context at a time, see %PP_FLAG_ALLOW_XDP_ONLY_NETMEM. + */ +enum mp_flags { + MP_XDP_ONLY = BIT(0), +}; + struct memory_provider_ops { netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp); bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem); @@ -27,6 +45,7 @@ struct memory_provider_ops { int (*nl_fill)(void *mp_priv, struct sk_buff *rsp, struct netdev_rx_queue *rxq); void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq); + u32 flags; }; bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr); diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index 5306e34105eb..c9b9b738e8ba 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -31,8 +31,27 @@ */ #define PP_FLAG_ALLOW_UNREADABLE_NETMEM BIT(3) +/* + * Allow an XDP-only memory provider of the queue (%MP_XDP_ONLY) to back the + * pool. The driver registers the pool as the memory model of the RX queue, + * sets up XDP buffers with xdp_prepare_buff() at xdp_netmem_address() of + * their head, and puts heads back by netmem, not by address. + * + * Such a provider takes no lock, so the driver also lets one context at a + * time use the buffers of the queue: its NAPI, or an operation that runs + * only while that NAPI cannot use the rings of the queue, as a queue + * restart or an error recovery. It fills and drains the rings only then, + * runs the NAPI once after the queue starts, so that its refill can ask + * for a wakeup, and lets the buffers leave the driver only to the AF_XDP + * socket of the queue, as the core turns XDP_PASS and XDP_TX of them into + * drops. + */ +#define PP_FLAG_ALLOW_XDP_ONLY_NETMEM BIT(4) + #define PP_FLAG_ALL (PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV | \ - PP_FLAG_SYSTEM_POOL | PP_FLAG_ALLOW_UNREADABLE_NETMEM) + PP_FLAG_SYSTEM_POOL | \ + PP_FLAG_ALLOW_UNREADABLE_NETMEM | \ + PP_FLAG_ALLOW_XDP_ONLY_NETMEM) /* Index limit to stay within PP_DMA_INDEX_BITS for DMA indices */ #define PP_DMA_INDEX_LIMIT XA_LIMIT(1, BIT(PP_DMA_INDEX_BITS) - 1) @@ -84,7 +103,7 @@ struct pp_alloc_cache { * @netdev: netdev this pool will serve (leave as NULL if none or multiple) * @queue_idx: queue idx this page_pool is being created for. * @flags: PP_FLAG_DMA_MAP, PP_FLAG_DMA_SYNC_DEV, PP_FLAG_SYSTEM_POOL, - * PP_FLAG_ALLOW_UNREADABLE_NETMEM. + * PP_FLAG_ALLOW_UNREADABLE_NETMEM, PP_FLAG_ALLOW_XDP_ONLY_NETMEM. */ struct page_pool_params { struct_group_tagged(page_pool_params_fast, fast, diff --git a/net/core/dev.c b/net/core/dev.c index b7757f91fdf9..9ca2bfedcab5 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10666,7 +10666,7 @@ int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf) return -EBUSY; } - if (dev_get_min_mp_channel_count(dev)) { + if (dev_mp_blocks_xdp(dev)) { NL_SET_ERR_MSG(bpf->extack, "unable to propagate XDP to device using memory provider"); return -EBUSY; @@ -10747,7 +10747,7 @@ static int dev_xdp_install(struct net_device *dev, enum bpf_xdp_mode mode, "unable to install XDP to device using tcp-data-split"); return -EBUSY; } - if (dev_get_min_mp_channel_count(dev)) { + if (dev_mp_blocks_xdp(dev)) { NL_SET_ERR_MSG(extack, "unable to install XDP to device using memory provider"); return -EBUSY; @@ -11173,6 +11173,23 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, return err; } +/* Native XDP runs next to XDP-only providers only, see %MP_XDP_ONLY */ +bool dev_mp_blocks_xdp(const struct net_device *dev) +{ + const struct memory_provider_ops *ops; + unsigned int i; + + netdev_assert_locked_ops_compat(dev); + + for (i = 0; i < dev->real_num_rx_queues; i++) { + ops = dev->_rx[i].mp_params.mp_ops; + if (ops && !(ops->flags & MP_XDP_ONLY)) + return true; + } + + return false; +} + u32 dev_get_min_mp_channel_count(const struct net_device *dev) { int i; diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c index a7261fedd5e7..212f1b9415b3 100644 --- a/net/core/netdev_rx_queue.c +++ b/net/core/netdev_rx_queue.c @@ -79,15 +79,46 @@ __netif_get_rx_queue_lease(struct net_device **dev, unsigned int *rxq_idx, return rxq; } -/* See also page_pool_is_unreadable() */ +/* See also page_pool_is_unreadable(). An XDP-only provider backs the headers + * too, so its queue needs no header split, see %MP_XDP_ONLY. + */ bool netif_rxq_has_unreadable_mp(struct net_device *dev, unsigned int rxq_idx) { - if (rxq_idx < dev->real_num_rx_queues) - return __netif_get_rx_queue(dev, rxq_idx)->mp_params.mp_ops; - return false; + const struct memory_provider_ops *ops; + + if (rxq_idx >= dev->real_num_rx_queues) + return false; + + ops = __netif_get_rx_queue(dev, rxq_idx)->mp_params.mp_ops; + return ops && !(ops->flags & MP_XDP_ONLY); } EXPORT_SYMBOL(netif_rxq_has_unreadable_mp); +/** + * netif_rxq_has_xdp_only_mp() - whether an XDP-only provider backs an RX queue + * @dev: device of the queue + * @rxq_idx: RX queue of @dev itself, not of a lease + * + * The page pools of the queue that allow it take the provider, see + * %PP_FLAG_ALLOW_XDP_ONLY_NETMEM. They are created under the instance lock, + * which the caller holds, so they agree with the answer. + * + * Return: true if the queue has a provider with %MP_XDP_ONLY. + */ +bool netif_rxq_has_xdp_only_mp(struct net_device *dev, unsigned int rxq_idx) +{ + const struct memory_provider_ops *ops; + + netdev_assert_locked(dev); + + if (rxq_idx >= dev->real_num_rx_queues) + return false; + + ops = __netif_get_rx_queue(dev, rxq_idx)->mp_params.mp_ops; + return ops && ops->flags & MP_XDP_ONLY; +} +EXPORT_SYMBOL(netif_rxq_has_xdp_only_mp); + bool netif_rxq_has_mp(struct net_device *dev, unsigned int rxq_idx) { if (rxq_idx < dev->real_num_rx_queues) @@ -189,6 +220,7 @@ static int __netif_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, struct netlink_ext_ack *extack) { const struct netdev_queue_mgmt_ops *qops = dev->queue_mgmt_ops; + bool xdp_only = p->mp_ops->flags & MP_XDP_ONLY; struct netdev_queue_config qcfg[2]; struct netdev_rx_queue *rxq; int ret; @@ -196,15 +228,17 @@ static int __netif_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, if (!qops) return -EOPNOTSUPP; - if (dev->cfg->hds_config != ETHTOOL_TCP_DATA_SPLIT_ENABLED) { + /* An XDP-only provider backs headers too, and runs next to XDP */ + if (!xdp_only && + dev->cfg->hds_config != ETHTOOL_TCP_DATA_SPLIT_ENABLED) { NL_SET_ERR_MSG(extack, "tcp-data-split is disabled"); return -EINVAL; } - if (dev->cfg->hds_thresh) { + if (!xdp_only && dev->cfg->hds_thresh) { NL_SET_ERR_MSG(extack, "hds-thresh is not zero"); return -EINVAL; } - if (dev_xdp_prog_count(dev)) { + if (!xdp_only && dev_xdp_prog_count(dev)) { NL_SET_ERR_MSG(extack, "unable to custom memory provider to device with XDP program attached"); return -EEXIST; } @@ -219,7 +253,8 @@ static int __netif_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, return -EEXIST; } #ifdef CONFIG_XDP_SOCKETS - if (rxq->pool) { + /* Only the AF_XDP socket of the queue installs an XDP-only provider */ + if (rxq->pool && !xdp_only) { NL_SET_ERR_MSG(extack, "designated queue already in use by AF_XDP"); return -EBUSY; } diff --git a/net/core/page_pool.c b/net/core/page_pool.c index d7c88c0b67e5..8a1ea21ccdcd 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -272,12 +272,22 @@ static int page_pool_init(struct page_pool *pool, xa_init_flags(&pool->dma_mapped, XA_FLAGS_ALLOC1); - if (pool->slow.flags & PP_FLAG_ALLOW_UNREADABLE_NETMEM) { + if (pool->slow.flags & (PP_FLAG_ALLOW_UNREADABLE_NETMEM | + PP_FLAG_ALLOW_XDP_ONLY_NETMEM)) { + const struct memory_provider_ops *ops; + u32 allow; + netdev_assert_locked(pool->slow.netdev); rxq = __netif_get_rx_queue(pool->slow.netdev, pool->slow.queue_idx); - pool->mp_priv = rxq->mp_params.mp_priv; - pool->mp_ops = rxq->mp_params.mp_ops; + ops = rxq->mp_params.mp_ops; + allow = ops && ops->flags & MP_XDP_ONLY ? + PP_FLAG_ALLOW_XDP_ONLY_NETMEM : + PP_FLAG_ALLOW_UNREADABLE_NETMEM; + if (pool->slow.flags & allow) { + pool->mp_priv = rxq->mp_params.mp_priv; + pool->mp_ops = ops; + } } if (pool->mp_ops) { diff --git a/net/ethtool/rings.c b/net/ethtool/rings.c index e3810c0320e3..84ba17412a40 100644 --- a/net/ethtool/rings.c +++ b/net/ethtool/rings.c @@ -258,7 +258,10 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) return -EINVAL; } - if (dev_get_min_mp_channel_count(dev)) { + /* Providers that take the payload need header split. XDP-only + * providers back whole packets: they neither need it nor block XDP. + */ + if (dev_mp_blocks_xdp(dev)) { if (kernel_ringparam.tcp_data_split != ETHTOOL_TCP_DATA_SPLIT_ENABLED) { NL_SET_ERR_MSG(info->extack, diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index 28bdc63551bf..d707fb308001 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -244,7 +244,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, goto err_unreg_pool; } - if (dev_get_min_mp_channel_count(netdev)) { + if (dev_mp_blocks_xdp(netdev)) { err = -EBUSY; goto err_unreg_pool; } -- 2.56.1