From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.40 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796074681; b=sEGxAyRn6ZyVfTsbxgJeT7ZoCVuOjPU+umBstXz/Gki5pwMhIv05pgnH/mQ7/S6z/92W p7LzymwMuj0dASkgCUEBc/1di0J22bHIpFYtDIQd52A6CuEakO76nGFl5WlfeOYlJuBxJ rN1jEuzvK7F30gHQ7zPmsoxRb0667OjkC1AvwK/FHDhFQJzfCGZrJWOw9b3laU7MO2bdG C9w7kZV7U4d/UKkV7fdDOmHIp2AoySyK43vDyi9NZWntnhU0jipWMm2gVG8C1MDHKyTYa 0oMlWdimp7uXxaXmiEHu6JNWX0eC96C9z9BIYNeQ3TIPRYfmLKni9gCfJwtcBgYmmlw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796074681; 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=7Rn7vka02jNZQnd+S7hgxazXKMuQDeL6X4IqZBDye1s=; b=KSUqcgI7vdtAZ+PX0KqQyVCDSnrXnZIGqJUllcJTsB+IN43Xup/+FD558nZyu19m/uEP uqt2znULCcvpGXBULh66rvpXZMVJ5NJVzucXjDAZrs1EmqJJ8AW+NPWofTDKxrxSL4Vl0 vTSljIyK5rK1HKvAtUc2dENwW9Gado6XjuIkc6AI02NiqGaUwiljEJ0sUKjrpBdpZ2lCY MpxmbAYyJqmUNgy9Xik+At23rqG1pyoTJOSOtqyytwN/ZlaZ2obXyfTWjjJf+QJvt0T4W K0gy68e8Un5uWcY1csGvQFV7Wdi0Bx9ym9JQZd+uZGrfebi9k3G/RoRLTMKCzV1jekA== 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=MRPXAima; arc=none smtp.remote-ip=195.10.208.40 Received: from mout-b-210.mailbox.org (mout-b-210.mailbox.org [195.10.208.40]) (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 B7990606A688; Mon, 30 Nov 2026 21:38:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7990606A688 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=MRPXAima Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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-210.mailbox.org (Postfix) with ESMTPS id 4jdcnf1zqXzFqs2; Mon, 30 Nov 2026 22:37:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1796074678; 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=7Rn7vka02jNZQnd+S7hgxazXKMuQDeL6X4IqZBDye1s=; b=MRPXAimaWdovUuRKCpxdCSCx7eHQbQFi3BkoaY2XKaI0nZbjtEGzLaDm6iOoJA9uei+lO6 f8YA28gbNq44A5U9eGgDhitny0g6TCWQg+REE0Moia7z6ZCAiUN+6K5wc24QNtlvNbikdW j0DbT6dxz65ubwqRdt2XORmhb+f2vi4jyzppwhHi6I3nENAzLwPsF/0UgopTjNAUFUEFII zlkGMxftvqUTAzahRK5nLWVhpZE3s1JyhuC6ojUp1OZbfBxProAhqcXQUtF13++UzM34T1 U6GByxmeZU1SdGPcyic75dXb31BegENPr2pXtTLv/U2kDhDF8HXnu9e+/Y53yg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of antonio@mandelbit.com designates 2001:67c:2050:b231:465::202 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 v6 6/7] igb: resume the device before changing XDP or XSK settings Date: Mon, 30 Nov 2026 22:37:36 +0100 Message-ID: <20261130213740.3323814-7-antonio@mandelbit.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130213740.3323814-1-antonio@mandelbit.com> References: <20261130213740.3323814-1-antonio@mandelbit.com> X-Mailing-List: linux-pm@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: 4jdcnf1zqXzFqs2 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, refuse to enable one or to add an XDP program, and only update the software state when removing or replacing one, as failing that would leak the program. 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. 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 --- 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 | 31 ++++++++++++++++++++--- drivers/net/ethernet/intel/igb/igb_xsk.c | 8 ++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 55352df..e5a2870 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -2909,6 +2909,16 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf) } } + /* After a failed resume the device is detached and its rings have no + * resources: only update the software state, and don't add a program + */ + if (running && !netif_device_present(dev) && + (!adapter->num_rx_queues || !adapter->rx_ring[0]->desc)) { + if (prog && !adapter->xdp_prog) + return -ENODEV; + running = false; + } + old_prog = xchg(&adapter->xdp_prog, prog); need_reset = (!!prog != !!old_prog); @@ -2943,16 +2953,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