🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17992

[PATCH net-next 3/7] net: Admit native XDP on provider queues

#17992
From: Björn Töpel
Date: Tue, 17 Nov 2026 16:46
165 lines
14965 bytes
XDP and memory providers are currently rejected on the same device.
Header-split RX keeps headers in normal memory, so a program can
filter packets without reading the provider payload.

Keep this restriction unless the driver declares xdp_unreadable
support. Admit native XDP in either attach order on these drivers.
Existing header-split checks require frags-aware programs.

The driver must mark provider fragments and reject XDP_TX while those
fragments remain. The core rejects helper access and frame redirects.

Keep generic and hardware-offloaded XDP rejected. Generic XDP builds
an xdp_buff from an skb without carrying the unreadable flag. Its
transmit and redirect paths also bypass the native driver guard.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 Documentation/networking/netmem.rst |  8 ++++++++
 include/net/netdev_queues.h         |  6 ++++++
 include/net/xdp.h                   |  5 ++---
 net/core/dev.c                      | 28 ++++++++++++++++++++++++++--
 net/core/dev.h                      |  1 +
 net/core/netdev_rx_queue.c          |  2 +-
 6 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/Documentation/networking/netmem.rst b/Documentation/networking/netmem.rst
index 6871dcdd700c..1ac94fc9d667 100644
--- a/Documentation/networking/netmem.rst
+++ b/Documentation/networking/netmem.rst
@@ -131,6 +131,14 @@ Driver RX Requirements
    circulation times, such as when userspace holds a reference in zerocopy
    scenarios.
 
+8. XDP programs run next to unreadable memory providers only if the driver
+   sets netdev_queue_mgmt_ops.xdp_unreadable, and only in native mode. The
+   programs see the headers in the linear part, and helpers that reach
+   unreadable fragments fail. Attach payload fragments with
+   xdp_buff_add_frag(), which marks unreadable ones, and drop XDP_TX of a
+   buffer for which xdp_buff_is_frag_unreadable() is true: the payload is
+   mapped for receive only. Redirects of such a buffer fail in the core.
+
 Driver TX Requirements
 ======================
 
diff --git a/include/net/netdev_queues.h b/include/net/netdev_queues.h
index c5335e935b7d..4f6702b284b4 100644
--- a/include/net/netdev_queues.h
+++ b/include/net/netdev_queues.h
@@ -199,6 +199,11 @@ enum {
  *
  * @supported_params:	Bitmask of supported parameters, see QCFG_*.
  *
+ * @xdp_unreadable:	Native XDP programs may run on queues with unreadable
+ *			memory providers. The driver builds XDP buffers with
+ *			xdp_buff_add_frag(), and drops XDP_TX of a buffer for
+ *			which xdp_buff_is_frag_unreadable() is true.
+ *
  * Note that @ndo_queue_mem_alloc and @ndo_queue_mem_free may be called while
  * the interface is closed. @ndo_queue_start and @ndo_queue_stop will only
  * be called for an interface which is open.
@@ -229,6 +234,7 @@ struct netdev_queue_mgmt_ops {
 				    struct netlink_ext_ack *extack);
 
 	unsigned int supported_params;
+	bool xdp_unreadable;
 };
 
 void netdev_queue_config(struct net_device *dev, int rxq,
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 20d173fe163c..167f733a0bb0 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -76,9 +76,8 @@ enum xdp_buff_flags {
 	XDP_FLAGS_FRAGS_PF_MEMALLOC	= BIT(1), /* xdp paged memory is under
 						   * pressure
 						   */
-	/* frags have unreadable mem, this can't be true for real XDP packets,
-	 * but drivers may use XDP helpers to construct Rx pkt state even when
-	 * XDP program is not attached.
+	/* frags have unreadable mem: XDP programs reach only the linear part,
+	 * and the buffer cannot become an xdp_frame
 	 */
 	XDP_FLAGS_FRAGS_UNREADABLE	= BIT(2),
 };
diff --git a/net/core/dev.c b/net/core/dev.c
index a230ecce9327..f0c3d56d5b83 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10575,6 +10575,27 @@ u8 dev_xdp_sb_prog_count(struct net_device *dev)
 	return count;
 }
 
+/* Only native programs run next to unreadable memory providers. Drivers must
+ * mark unreadable fragments and reject XDP_TX while they remain attached.
+ * Tcp-data-split, which these providers need, also needs frags support.
+ */
+static bool netif_xdp_mp_mode_ok(const struct net_device *dev,
+				 enum bpf_xdp_mode mode)
+{
+	return mode == XDP_MODE_DRV && dev->queue_mgmt_ops->xdp_unreadable;
+}
+
+/* Can the XDP programs of @dev run next to a new memory provider? */
+bool netif_xdp_mp_ok(struct net_device *dev)
+{
+	int i;
+
+	for (i = 0; i < __MAX_XDP_MODE; i++)
+		if (dev_xdp_prog(dev, i) && !netif_xdp_mp_mode_ok(dev, i))
+			return false;
+	return true;
+}
+
 int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf)
 {
 	if (!dev->netdev_ops->ndo_bpf)
@@ -10588,7 +10609,9 @@ int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf)
 		return -EBUSY;
 	}
 
-	if (dev_get_min_mp_channel_count(dev)) {
+	if (dev_get_min_mp_channel_count(dev) &&
+	    (bpf->command != XDP_SETUP_PROG ||
+	     !netif_xdp_mp_mode_ok(dev, XDP_MODE_DRV))) {
 		NL_SET_ERR_MSG(bpf->extack, "unable to propagate XDP to device using memory provider");
 		return -EBUSY;
 	}
@@ -10664,7 +10687,8 @@ static int dev_xdp_install(struct net_device *dev, enum bpf_xdp_mode mode,
 		return -EBUSY;
 	}
 
-	if (dev_get_min_mp_channel_count(dev)) {
+	if (dev_get_min_mp_channel_count(dev) &&
+	    !netif_xdp_mp_mode_ok(dev, mode)) {
 		NL_SET_ERR_MSG(extack, "unable to install XDP to device using memory provider");
 		return -EBUSY;
 	}
diff --git a/net/core/dev.h b/net/core/dev.h
index 4e9e8cd15697..a7036302f120 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -118,6 +118,7 @@ int netdev_queue_config_revalidate(struct net_device *dev,
 bool netif_rxq_has_mp(struct net_device *dev, unsigned int rxq_idx);
 bool netif_rxq_is_leased(struct net_device *dev, unsigned int rxq_idx);
 bool netif_is_queue_leasee(const struct net_device *dev);
+bool netif_xdp_mp_ok(struct net_device *dev);
 
 void __netif_mp_uninstall_rxq(struct netdev_rx_queue *rxq,
 			      const struct pp_memory_provider_params *p);
diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c
index a7261fedd5e7..dab5107e31f8 100644
--- a/net/core/netdev_rx_queue.c
+++ b/net/core/netdev_rx_queue.c
@@ -204,7 +204,7 @@ static int __netif_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx,
 		NL_SET_ERR_MSG(extack, "hds-thresh is not zero");
 		return -EINVAL;
 	}
-	if (dev_xdp_prog_count(dev)) {
+	if (!netif_xdp_mp_ok(dev)) {
 		NL_SET_ERR_MSG(extack, "unable to custom memory provider to device with XDP program attached");
 		return -EEXIST;
 	}
-- 
2.56.1
Technical Details
Message-ID: <20261117164700.2157816-4-bjorn@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365451-linux-kernel-netdev=dewy.ru
References: <20261117164700.2157816-1-bjorn@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365451-linux-kernel-netdev=dewy.ru
From: bjorn@kernel.org (Björn Töpel)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 3/7] net: Admit native XDP on provider queues
Date: Tue, 17 Nov 2026 17:46:54 +0100
Organization: Usenet Network
Message-ID: <20261117164700.2157816-4-bjorn@kernel.org>
References: <20261117164700.2157816-1-bjorn@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2380052"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KDWzTpi+iCNpevpKoMySpj0/P9Y= sha256:pKMkrE0CjeOzaTBBSsYVq5RzhnFPKwWRzusm4/WgJrg=
	sha1:9FVooujZoty1erQaH4jxnx8IVL0= sha256:oFM7fOuIol0d/G//28Ixz4ZpTX+YALbYry2odbZLND0=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 3B8F0114FEA; Tue, 17 Nov 2026 19:48:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Mm6WtW07vY0z;
	Tue, 17 Nov 2026 19:48:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-365451-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id F014A114FFB; Tue, 17 Nov 2026 19:47:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 8EA1330911; Tue, 17 Nov 2026 16:47:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794934067;
	b=uNJycMiH+RmJSWWmxy0+IyfChWUt5hD6S5ayo8Cw6L8Axe8nC306LnzlBrbCJSCGm9GS
	 CgXMwa1fhhEL/eMt3C03k5BP93z8f/8uyh4Qvh7MMit1H/S6DDvTmB1YrFksue+wB2Ky9
	 er9hFSlPbYlL5J95jvuRH+0722lCzdt6E0kvjPkfSnsiB/xO/f9Qme9s6TI1sm6CRVSKe
	 boeJYajty4LzbsPfZkGDb9sIuDMqX3FLz/Mzq6cnN5g4I7re9PcxCV80WRiFx53fQDIuz
	 IFzbFFMfjQNa6Xb+a9H7HiJKMODhkIJIiwcpUtzBV/YDIiCW7laaZURTuhmhURZqMmw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794934067;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=RnwfFk6AHPB5f1u9wr05tM7Qbndh69kpJh8fYIlFxE4=;
	b=SPbR+MmijHkwzgrI1tDR33zEJVcrknvZv7EhjqWa0wjUZXrlN9/uKvZpIYxA8DR04wRc
	 ZnNjlogB504EqA2tqD0DhItmh7nIg1IEtq3SsG0fEESdpOVl6XNvnA1igBi/Of4PliKmp
	 BSR9d4MUcF8lFMQh0oxLMSZEDQ5XnDKCeGHSfPcNw1c6y9PfLtIx2W3T0A3d1W2F8p4HE
	 j0cXi1itVeQ9+LJ4jZwThgGHaHXijS5HaPM5V7Wgfj1luVHpmp7o8fv/abT8WhOYaCInQ
	 +Dei2lRDrwchfpr9B2jgCodveeFsNbEcEKckaXOKH+JWuZMr/LA4W4PboZYn7VK6o3g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CuFs7obK;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FBF1606A335;
	Tue, 17 Nov 2026 16:47:47 +0000 (UTC)
X-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=CuFs7obK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794934061;
	b=LcKKspHy64FoWxKyii+TiOK2pS2wnF/xNW3vlLHDCORdP6j5OCQ+04POgJdE8uEHPIik
	 9Da1TGUpa8BlFcg9It/VWUTcHgbE1DyRxeV4OGUyo6duh7SFev8TUze8/jA4kCElC/NRc
	 qLr9O+KSwmTErcByCieC1Gjoq55XqR8ALEPMNaKV7Ti4tIety6+AerFSj6g4kA8ZMdguY
	 ROYzdj8cm/a5V4Gt4gy0ZuAKFu69SuevkcrZuQNjNMNv4CDa4pbyA61Dt5/xgoCf7jk+8
	 n+OkpwRi3ZTt8meXgev3lgKCgrFG9ZdK075SSqP1q6I9ydB/MQODOY24ffHdgS6aw/g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794934061;
	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=RnwfFk6AHPB5f1u9wr05tM7Qbndh69kpJh8fYIlFxE4=;
	b=NN38M0f+B2qE2EpQ3IVD8gJ8oFHQWpq+TLCdP243+9mWJIcSDTSK3sl+GqzHxp6L7XZS
	 Shgap5lJpBdVNoqQwe+HGfi90cCyWCJOrSkllkHPbPrOF7l+XbGP/VHKpdiwQcUGECqjF
	 O2lEaF1z8Zg8dRrfxMfN014oJmgJdqqWjtQWh39T14jEEQsbPrqw08LJNyb0gSaQ1Vo/M
	 rYnaH0oMDXNaJiJFad/PDtl7hgnCe+6W0QWSG4EFqK8dlH31eb7Y+ewWXUlIQ0ow7L6Db
	 A462rv22a9t6NkljEsw3glUJKjyXu9Lc0LJVe3amHOXmSp65JkIYJew/xWVAymSAONw==
X-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=CuFs7obK;
	arc=none smtp.remote-ip=100.103.45.18
X-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 6C72F606A339;
	Tue, 17 Nov 2026 16:47:41 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EF3F1F000C5;
	Tue, 17 Nov 2026 16:47:33 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794934061;
	bh=RnwfFk6AHPB5f1u9wr05tM7Qbndh69kpJh8fYIlFxE4=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=CuFs7obKrjhpxlkV1g+UAHgLi7+qD/gerhXYffCz5RKPItq2+v2ZJ47Ngc1g5fyak
	 ZslFFZa4EWAK3kf0Zz5VJIeJaTlUay+1zjnGkUI2vJ8jfRqb7I5DtAeZ+chDnlkm1u
	 astry4UjSCAuSPY5CnkSroutapdscRk4/PslRpoNsD0YWagqr/CDc4GXikn4Vz4IK2
	 U+SP2owqoIDRSiUd35E8g8m4tBh79GMV7xnLt2/5hRg+R7N7YdRl82g60Y59QB9BQl
	 rXABnTqs98/SlzNt3lmPask43Gj2fofXyBGwfIo4otymvJ5CxxfmfzbT1fDLJ19XHg
	 SjkcrsMcZxxMA==
X-Cc: Björn Töpel <bjorn@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	kernel-team@meta.com,
	John Fastabend <john.fastabend@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Weiming Shi <bestswngs@gmail.com>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	David Wei <dw@davidwei.uk>,
	Bobby Eshleman <bobbyeshleman@meta.com>,
	linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	io-uring@vger.kernel.org,
	Mina Almasry <almasrymina@google.com>
X-Mailer: git-send-email 2.56.1
X-In-Reply-To: <20261117164700.2157816-1-bjorn@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list