Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.50 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== 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== 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 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) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 597FE606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mandelbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mandelbit.com 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 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) 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== 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 From: Antonio Quartulli To: intel-wired-lan@lists.osuosl.org Cc: Antonio Quartulli , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Janis Edvarts Lacis , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Sriram Yagnaraman , Kurt Kanzenbach , Maciej Fijalkowski , Heiner Kallweit , Joe Damato , "Rafael J. Wysocki" , Sven Auhagen , 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 Message-ID: <20261202002317.3140591-7-antonio@mandelbit.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202002317.3140591-1-antonio@mandelbit.com> References: <20261202002317.3140591-1-antonio@mandelbit.com> X-Mailing-List: bpf@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 X-Rspamd-Queue-Id: 4jfJQ82jrRz9tgK 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 --- 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