All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@mandelbit.com>
To: intel-wired-lan@lists.osuosl.org
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
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	[thread overview]
Message-ID: <20261202002317.3140591-7-antonio@mandelbit.com> (raw)
In-Reply-To: <20261202002317.3140591-1-antonio@mandelbit.com>

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


  parent reply	other threads:[~2026-12-02  0:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:23 [PATCH net v7 0/7] igb: fix runtime PM resume issues Antonio Quartulli
2026-12-02  0:23 ` [PATCH net v7 1/7] igb: don't wait for RTNL when runtime suspending Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 2/7] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 3/7] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 4/7] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 5/7] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
2026-12-02  0:23 ` Antonio Quartulli [this message]
2026-12-03  0:23   ` [PATCH net v7 6/7] igb: resume the device before changing XDP or XSK settings sashiko-bot
2026-12-03  1:04   ` netdev-bot+sashiko
2026-12-02  0:23 ` [PATCH net v7 7/7] igb: only allow runtime PM if the device can wake up Antonio Quartulli

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=20261202002317.3140591-7-antonio@mandelbit.com \
    --to=antonio@mandelbit.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=janislacis06@gmail.com \
    --cc=joe@dama.to \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kurt@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=rafael@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=sriram.yagnaraman@ericsson.com \
    --cc=stable@vger.kernel.org \
    --cc=sven.auhagen@voleatech.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.