🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25540

[PATCH net v7 6/7] igb: resume the device before changing XDP or XSK settings

#25540
From: Antonio Quartulli
Date: Wed, 02 Dec 2026 00:23
133 lines
15349 bytes
igb_xdp() can run while the device is runtime suspended or resuming,
and __igb_resume() rebuilds the queue counts and the rings without
RTNL. igb_xdp_setup() and igb_xsk_pool_setup() can then see a queue
count whose rings don't exist yet (NULL dereference), or a NAPI that
isn't enabled yet (napi_disable() never returns). Changing the XDP
program of a runtime suspended device also opened it twice.

Resume the device for the duration of igb_xdp(), as ethtool does. If
resuming fails, the rings don't exist, or have no resources and their
NAPIs were never enabled: don't touch them when disabling an XSK pool,
and refuse to enable one. igb_close() doesn't close the device then, as
it's detached (as during PCI error recovery, where changing the program
also opened it twice): only update the software state when changing the
XDP program. Only check the Rx buffer size when adding or replacing a
program, as rings allocated by a resume don't know it until they are
configured, which made removing a program fail.

Tested with the 82576 emulated by QEMU by closing a zero-copy AF_XDP
socket and attaching an XDP program while the device is runtime
suspended; the latter no longer warns in __netif_napi_del_locked()
because of the double open. Also, with a test hook making the open fail
on resume, by closing a socket and changing the XDP program after a
failed resume, and by removing a program that needs 3K buffers while the
interface is down and runtime suspended. The races themselves weren't
reproduced.

Fixes: 9cbc948b5a20 ("igb: add XDP support")
Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
Cc: stable@vger.kernel.org
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v7: igb_xdp_setup(): only update the software state on a detached device
(failed resume, PCI error recovery), and only check the Rx buffer size
when adding or replacing a program (Sashiko)
v6: handle a failed resume: skip rings without resources, refuse to
enable a pool or add an XDP program, and only update the software state
when removing or replacing one (Sashiko); dropped Janis's Reviewed-by
v5: new patch (Sashiko)

 drivers/net/ethernet/intel/igb/igb_main.c | 34 +++++++++++++++++++----
 drivers/net/ethernet/intel/igb/igb_xsk.c  |  8 ++++--
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 55352df..d7a4b41 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -2896,8 +2896,17 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
 	bool running = netif_running(dev);
 	bool need_reset;
 
-	/* verify igb ring attributes are sufficient for XDP */
-	for (i = 0; i < adapter->num_rx_queues; i++) {
+	/* igb_close() doesn't close a detached device (after a failed resume,
+	 * or during PCI error recovery): only update the software state
+	 */
+	if (!netif_device_present(dev))
+		running = false;
+
+	/* verify igb ring attributes are sufficient for XDP, only when adding
+	 * or replacing a program: rings allocated by a resume don't know their
+	 * buffer size until they are configured
+	 */
+	for (i = 0; prog && i < adapter->num_rx_queues; i++) {
 		struct igb_ring *ring = adapter->rx_ring[i];
 
 		if (frame_size > igb_rx_bufsz(ring)) {
@@ -2943,16 +2952,29 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
 static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
 	struct igb_adapter *adapter = netdev_priv(dev);
+	int err;
+
+	/* The rings only exist while the device is resumed, and resuming
+	 * rebuilds them without RTNL. If resuming fails, igb_xdp_setup() and
+	 * igb_xsk_pool_setup() find the device down.
+	 */
+	pm_runtime_get_sync(&adapter->pdev->dev);
 
 	switch (xdp->command) {
 	case XDP_SETUP_PROG:
-		return igb_xdp_setup(dev, xdp);
+		err = igb_xdp_setup(dev, xdp);
+		break;
 	case XDP_SETUP_XSK_POOL:
-		return igb_xsk_pool_setup(adapter, xdp->xsk.pool,
-					  xdp->xsk.queue_id);
+		err = igb_xsk_pool_setup(adapter, xdp->xsk.pool,
+					 xdp->xsk.queue_id);
+		break;
 	default:
-		return -EINVAL;
+		err = -EINVAL;
 	}
+
+	pm_runtime_put(&adapter->pdev->dev);
+
+	return err;
 }
 
 int igb_xdp_xmit_back(struct igb_adapter *adapter, struct xdp_buff *xdp)
diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
index b6234e3..e70f818 100644
--- a/drivers/net/ethernet/intel/igb/igb_xsk.c
+++ b/drivers/net/ethernet/intel/igb/igb_xsk.c
@@ -120,6 +120,10 @@ static int igb_xsk_pool_enable(struct igb_adapter *adapter,
 	    qid >= netdev->real_num_tx_queues)
 		return -EINVAL;
 
+	/* After a failed resume the rings have no resources */
+	if (netif_running(netdev) && !adapter->rx_ring[qid]->desc)
+		return -ENODEV;
+
 	err = xsk_pool_dma_map(pool, &adapter->pdev->dev, IGB_RX_DMA_ATTR);
 	if (err)
 		return err;
@@ -160,11 +164,11 @@ static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid)
 	rx_ring = adapter->rx_ring[qid];
 	/* The stack can know more queues than the device has, e.g. while
 	 * runtime suspended, which frees the rings: skip the rings it
-	 * doesn't have.
+	 * doesn't have, or that have no resources after a failed resume.
 	 */
 	if_running = netif_running(adapter->netdev) &&
 		     igb_xdp_is_enabled(adapter) &&
-		     qid < adapter->num_rx_queues;
+		     qid < adapter->num_rx_queues && rx_ring->desc;
 	if (if_running)
 		igb_txrx_ring_disable(adapter, qid);
 
-- 
2.56.1
Technical Details
Message-ID: <20261202002317.3140591-7-antonio@mandelbit.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375452-linux-kernel-netdev=dewy.ru
References: <20261202002317.3140591-1-antonio@mandelbit.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375452-linux-kernel-netdev=dewy.ru
From: antonio@mandelbit.com (Antonio Quartulli)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v7 6/7] igb: resume the device before changing XDP or XSK settings
Date: Wed,  2 Dec 2026 01:23:14 +0100
Organization: Usenet Network
Message-ID: <20261202002317.3140591-7-antonio@mandelbit.com>
References: <20261202002317.3140591-1-antonio@mandelbit.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1850839"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:RLxMEJRZRKFWZT2SYYdAFAffRE4= sha256:fLZR5q8lChGqvOl0heF0H8bOzz9+1KWCOgeXmQEzV8Q=
	sha1:qPvt1skag9ixuzmS9T2GR2zPjx4= sha256:7h4dOYk8XGJyrpdyfGa0ZnZApXMkBZHiVR2epNRIJnU=
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 188051174FE; Wed,  2 Dec 2026 03:23:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=mandelbit.com
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 Kvw4DT12upum;
	Wed,  2 Dec 2026 03:23:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-375452-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=mandelbit.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 3AFB01174F9; Wed,  2 Dec 2026 03:23:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 9400760312A; Wed,  2 Dec 2026 00:23:41 +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=1796171012;
	b=Q+ay0/FnBULtpURW5c26/XeCOl5LaewqOvO2dpkzVmU0IpBKSH0XVVUFKDyq3zmUSCvm
	 JcJNAAUHU4QhQOfsk8QF5Xmr8c1T5sjOB1Tvmcw/ZWgH4rwV3ZjphIDsAKmTmCheE3eZC
	 AyINdNfioFnu65fCKxBMk+v7dUrq7aa5zNEdKZ96PcEIz134a2KYi2lPmnl1Kkg9fCsyI
	 LvRS8txiM0o2BgBPQzsx3dfsA/lwvLWQ2CQFrtqX/nWrlRDzbO8W29r0kEABN/GYxEgYW
	 YSEtnRf4d7Rz65DsZS+bjels+aRm7TCV3onxY+57g4RKA+ro8pKbeWEIdJgeO/4vW2w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796171012;
	h=X-Original-To:Received:DMARC-Filter: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-Transfer-Encoding:X-Rspamd-Queue-Id;
	bh=XuxEl4+yZMep1QCEkis9j2/nOcU6LNAovoQn92Gmr3s=;
	b=II5cZmJbJZcaG4JRupnD1WXCSAhkODCNp02YZcmy3L8PChWkrWJlyjqILl1AegIZ0bzK
	 zsgiDi8wvd2ieXO2deN02ORNtzMyK7JnNZHc2mP/iW1iWSpjERdj3zU9Uuwx1bcDl9U+E
	 sqhcgUSz52ilV56DX5tEomVk/mZ7Wh4et6VHmGPf0hO/JjYiwXZ/iGRoxJo8cxCcBuVhT
	 0awgUMekKzfbqP+riIuMCpy7Ks53YJWj+w50xta0pwhGLIX+ILJ/g6dOuZnea/D50dxG6
	 An7bKyZvBFIjAOTNWhDKO4+RsoFSWYWUCytciriU4qQkAvfDMEZI0HccBl7j8hKVeTQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=1TJuKhGT;
	dmarc=none header.from=mandelbit.com;
	spf=pass smtp.mailfrom=mandelbit.com;
	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 B9ED8606A6A1;
	Wed,  2 Dec 2026 00:23:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=1TJuKhGT
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.50
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796171011;
	b=ngaXqJbBCTWwYnVxFi+aDik8jnvFSmcOQTLtvbGfEkUsLeUF6MuHFr00Er/uYu3lFIBV
	 GzyI92hSNUFzKRcEk6YuInAFAM0qmLYPM/jYyDusmuWENFOOb9wES6SeHnNboUbrmHj6v
	 GCq+yNS8PhxKUrgv2/F+G4HVRfjIgCTtX4fiZZxCz50Le8h6z8Op3glb5YcAZ/BhcscwK
	 CWmzU0bUm6hD1ZvZMN6ltanychbeturf+p736okDVMcxana1n2uxoSX4Zr5/tahMqWL3X
	 mueUZ7YXpPvyXxDx2nQBMR9Uba6RBFA5DJta3rMUCS3CljxOhOYlZFeUjHoYSmRwkOw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796171011;
	h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-Rspamd-Queue-Id;
	bh=XuxEl4+yZMep1QCEkis9j2/nOcU6LNAovoQn92Gmr3s=;
	b=rzJK6Lb47bUBXYH7OybeUeXNP6k5MOBhYTVoyL3DxHM6jbygWJKyvTOVdkxVYWhWYoyj
	 zZ7wA+wm5eatW7V4zKTCMmQChwyJxKPbQkyeHbh+2JK9qyu8NSeklnxeqAWnYSAPLDoos
	 hRW9uyCbEsGER6unV2GNNIUQIuQSZnFznlpJKCjN9419GYgllXGZ7E2hTzGRWB0AwuTf9
	 q9blSa7csgB9giRF4yq4q2PAXC4zxTAygrOmKWmf2xL/x8ymBJCyz8hwiAaLAE2vCtVo6
	 vx22Z0QkX/VMiyCSrB0z6HTFJlIfzADk/9T762t0W0UFmkl2ZDZ/ZP/zfvqikOMDFVg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=mandelbit.com;
	spf=pass smtp.mailfrom=mandelbit.com;
	dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=1TJuKhGT;
	arc=none smtp.remote-ip=195.10.208.50
X-Received: from mout-b-105.mailbox.org (mout-b-105.mailbox.org [195.10.208.50])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 597FE606A337;
	Wed,  2 Dec 2026 00:23:31 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 597FE606A337
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mandelbit.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mandelbit.com
X-Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mout-b-105.mailbox.org (Postfix) with ESMTPS id 4jfJQ82jrRz9tgK;
	Wed, 02 Dec 2026 01:23:28 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com;
	s=MBO0001; t=1796171008;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=XuxEl4+yZMep1QCEkis9j2/nOcU6LNAovoQn92Gmr3s=;
	b=1TJuKhGTxtaPMK2/2T86viHt3MeGpA+6ewT957abjUIJf8Kyhf5Vx+eJPmz1I7JN6lfFPd
	ZnqUn/qHF/8/Bvgc1B9392LoexHJhNat8IeNu5BwiIQVZlUoZ5kmckUG3QcVdcHasRxVvO
	5CZ9gkw51CN01rtllVq9d3NiKRqTaHww2MwTai89KgxbuS4W1A8SWS3Uy9VuqrxOBAhekW
	hzZcQ1oTJRAhneUa5KudEj74dnEn2/8o2J/fvFWL15Vlg9w8Ym9kT4ZW1emnLS/BPEAO73
	6Q1vjAL0HGCaJuKzcKM5m1H9Tqm1+9SGSwUdxD2f9GU07ZvYIejf8gmlEXZz0w==
X-Authentication-Results: outgoing_mbo_mout;
	dkim=none;
	spf=pass (outgoing_mbo_mout: domain of antonio@mandelbit.com designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=antonio@mandelbit.com
X-Cc: Antonio Quartulli <antonio@mandelbit.com>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Janis Edvarts Lacis <janislacis06@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>,
	Kurt Kanzenbach <kurt@linutronix.de>,
	Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Joe Damato <joe@dama.to>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Sven Auhagen <sven.auhagen@voleatech.de>,
	netdev@vger.kernel.org,
	linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org,
	stable@vger.kernel.org
X-Mailer: git-send-email 2.56.1
X-In-Reply-To: <20261202002317.3140591-1-antonio@mandelbit.com>
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
X-Rspamd-Queue-Id: 4jfJQ82jrRz9tgK