From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796074678; b=r44eZce3bN1JAzSE/zQ5m6hXEMSJXLykbQkHmvBRmTWPEqXKXmMSq1vjhX8XA4SWRSLj AbmkPSMSniw0n7pQERBUB7V9GuaRqPIRCLUaymK9wlWo3McbptgjxE7p4N8dZpcoqoo0X nfFeXdhKzrj7g0xjif0PaiPmTmKErZTjROK8nK5+GcBJuJJwu/VgbBkfBaDWrj0yA8I51 4+k0W4Qgo/tw+iYH8WPz4sxYIfHG3v3ym1eoat++DD6ML4Ur5H7/DUnVdU8r6KCKq4vk5 94KiwDU7rWCw7qfBzECye+an7KmDbrqSNn0taAEJTioPwBUCJjDcCSxqr3Sm28yg8iQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796074678; 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=digT4oGWIrQH0rNfCTgwJs5a0sSMI+wygokSxId2VI4=; b=TKz07bGgkEt9NR94bUYJrSENrl/X92Vd8XYhL5QsWcIe7NxKzmeEtLohStebewmxQ4xM b6OpsxWL6g8qOhyhu3JWoUFtICnUxcfmEV+yoNMV2/xzQRhJX0Xrl2P/36BM4Ug8QtCVO I09frJ9IjWOH6imFZugJGwFheB3VEM8sDa4L+q3rQ/1Y3aKu6xHWDJunjCFGDqgxxuyYk vKTfBFzRYBGFDVGuIBXrJKWbDpUVTkWbNac0/MmhOkcZ5UoMDpNBn0LcKgUKOAtUGn6vz 0+rPET+wmp0V4USixQIu20k0T9ZpvNTvWTvAjHIyqHLezGtTGi2SaFx+eREMYVtVi0A== 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=VDDZu4I2; arc=none smtp.remote-ip=195.10.208.55 Received: from mout-b-110.mailbox.org (mout-b-110.mailbox.org [195.10.208.55]) (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 0C311606A683; Mon, 30 Nov 2026 21:37:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0C311606A683 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=VDDZu4I2 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-110.mailbox.org (Postfix) with ESMTPS id 4jdcnX74vnzNlRB; Mon, 30 Nov 2026 22:37:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1796074673; 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=digT4oGWIrQH0rNfCTgwJs5a0sSMI+wygokSxId2VI4=; b=VDDZu4I2qQWmxxAWJkkA664baCLmETMSyxUeAD5p6fHgR3k5IbyZrHKXc7GH4CnFjMbNKb jG9U2pTyQzB/k7o7UVZJ3cotoGty1Vng1At+1Eubp/AR2EPYDxhYDAX+TY+ug4hUc5fxs/ q45UUx6kEiikcajUtZ/svw2Rqye2XsM+rNaqd2LGA0Isq3FO9Az0YRE2BdNa5NzCTVOvxf bWAnL9tu4hskkydnjDgUhdYB0PAJoDeUbnUtX0Uu/M9OuzMW9WuBcMh6UJbhAJ5AZSqWrN NBZo3UeJeXeHW5CNTz+Eup5Xr/bgriTQ3KIKvYlLqpUxRR7BGW0yfT5bYQe1bw== 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 3/7] igb: fix RTNL assertion when resuming from runtime suspend Date: Mon, 30 Nov 2026 22:37:33 +0100 Message-ID: <20261130213740.3323814-4-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-kernel@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: 4jdcnX74vnzNlRB Since commit ac8c58f5b535 ("igb: fix deadlock caused by taking RTNL in RPM resume path") __igb_resume() doesn't take RTNL for runtime resume, but __igb_open() still calls netif_set_real_num_{tx,rx}_queues(), which require it. An asynchronous runtime resume (e.g. after the link comes back) then triggers "RTNL: assertion failed". Only set the real queue counts in __igb_open() when RTNL is held (open and system sleep resume), and set them from a work item taking RTNL on runtime resume. The work item resumes the device first, so that it doesn't run in the middle of a later suspend or resume. Until it runs, after a fallback to fewer queues on resume (MSI-X to MSI), the stack can use queues the device doesn't have: drop those packets in igb_xmit_frame() instead of mapping several stack queues, each with its own xmit lock, onto the same ring. The stack can't be kept off those queues instead, as __igb_open() and netif_device_attach() start all of them and changing the count needs RTNL. Tested with the 82576 emulated by QEMU. Fixes: ac8c58f5b535 ("igb: fix deadlock caused by taking RTNL in RPM resume path") Cc: stable@vger.kernel.org Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562 Signed-off-by: Antonio Quartulli --- v6: the work item resumes the device first, so that it can't run during a suspend or resume (Sashiko); dropped Janis's Reviewed-by, as the patch changed v5: no changes v4: no changes v3: - set the real queue counts when RTNL is held (open and system sleep resume), and from a work item on runtime resume, instead of not at all on resume (Janis, Sashiko) - until then, drop packets for queues the device doesn't have - stable: netif_set_real_num_queues() needs 5.15+ and dev_core_stats_tx_dropped_inc() 5.18+; older backports can use the separate tx/rx calls and netdev->stats.tx_dropped v2: - keep setting the queue counts in __igb_open() after igb_request_irq(), only skipping them on resume (Sashiko) - drop the reference to igc Note: igc has the same issue: it sets the real queue counts only in igc_open(), before requesting the IRQs, and never on resume. A fix will follow separately once it has been tested on igc hardware (Joe offered to test). drivers/net/ethernet/intel/igb/igb.h | 1 + drivers/net/ethernet/intel/igb/igb_main.c | 76 +++++++++++++++++------ 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h index 4250b4d..0639b00 100644 --- a/drivers/net/ethernet/intel/igb/igb.h +++ b/drivers/net/ethernet/intel/igb/igb.h @@ -587,6 +587,7 @@ struct igb_adapter { struct work_struct reset_task; struct work_struct watchdog_task; struct work_struct rpm_retry_task; + struct work_struct rtnl_resume_task; bool fc_autoneg; u8 tx_timeout_factor; struct timer_list blink_timer; diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index fffcb31..bf24768 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -110,6 +110,7 @@ static void igb_init_queue_configuration(struct igb_adapter *adapter); static int igb_sw_init(struct igb_adapter *); int igb_open(struct net_device *); int igb_close(struct net_device *); +static void igb_rtnl_resume_task(struct work_struct *); static void igb_configure(struct igb_adapter *); static void igb_configure_tx(struct igb_adapter *); static void igb_configure_rx(struct igb_adapter *); @@ -3428,6 +3429,7 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) INIT_WORK(&adapter->reset_task, igb_reset_task); INIT_WORK(&adapter->watchdog_task, igb_watchdog_task); INIT_WORK(&adapter->rpm_retry_task, igb_rpm_retry_task); + INIT_WORK(&adapter->rtnl_resume_task, igb_rtnl_resume_task); /* Initialize link properties that are user-changeable */ adapter->fc_autoneg = true; @@ -3892,6 +3894,7 @@ static void igb_remove(struct pci_dev *pdev) cancel_work_sync(&adapter->reset_task); cancel_work_sync(&adapter->watchdog_task); cancel_work_sync(&adapter->rpm_retry_task); + cancel_work_sync(&adapter->rtnl_resume_task); #ifdef CONFIG_IGB_DCA if (adapter->flags & IGB_FLAG_DCA_ENABLED) { @@ -4126,10 +4129,34 @@ static int igb_sw_init(struct igb_adapter *adapter) return 0; } +/* Some settings need RTNL, which isn't held when resuming from runtime + * suspend: apply them from here instead, if the device is still up. + * Resuming the device first waits for a resume or suspend in progress. + */ +static void igb_rtnl_resume_task(struct work_struct *work) +{ + struct igb_adapter *adapter = container_of(work, struct igb_adapter, + rtnl_resume_task); + + rtnl_lock(); + pm_runtime_get_sync(&adapter->pdev->dev); + if (!test_bit(__IGB_DOWN, &adapter->state) && + netif_running(adapter->netdev)) { + if (netif_set_real_num_queues(adapter->netdev, + adapter->num_tx_queues, + adapter->num_rx_queues)) + netdev_err(adapter->netdev, + "error setting real queue count\n"); + } + pm_runtime_put(&adapter->pdev->dev); + rtnl_unlock(); +} + /** * __igb_open - Called when a network interface is made active * @netdev: network interface device structure * @resuming: indicates whether we are in a resume call + * @rtnl_held: indicates whether RTNL is held * * Returns 0 on success, negative value on failure * @@ -4139,7 +4166,8 @@ static int igb_sw_init(struct igb_adapter *adapter) * handler is registered with the OS, the watchdog timer is started, * and the stack is notified that the interface is ready. **/ -static int __igb_open(struct net_device *netdev, bool resuming) +static int __igb_open(struct net_device *netdev, bool resuming, + bool rtnl_held) { struct igb_adapter *adapter = netdev_priv(netdev); struct pci_dev *pdev = adapter->pdev; @@ -4182,16 +4210,15 @@ static int __igb_open(struct net_device *netdev, bool resuming) if (err) goto err_req_irq; - /* Notify the stack of the actual queue counts. */ - err = netif_set_real_num_tx_queues(adapter->netdev, - adapter->num_tx_queues); - if (err) - goto err_set_queues; - - err = netif_set_real_num_rx_queues(adapter->netdev, - adapter->num_rx_queues); - if (err) - goto err_set_queues; + /* Notify the stack of the actual queue counts. This needs RTNL: on + * runtime resume igb_rtnl_resume_task() does it. + */ + if (rtnl_held) { + err = netif_set_real_num_queues(netdev, adapter->num_tx_queues, + adapter->num_rx_queues); + if (err) + goto err_set_queues; + } /* From here on the code is the same as igb_up() */ clear_bit(__IGB_DOWN, &adapter->state); @@ -4245,7 +4272,7 @@ err_setup_tx: int igb_open(struct net_device *netdev) { - return __igb_open(netdev, false); + return __igb_open(netdev, false, true); } /** @@ -6620,12 +6647,7 @@ cleanup_tx_tstamp: static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter, struct sk_buff *skb) { - unsigned int r_idx = skb->queue_mapping; - - if (r_idx >= adapter->num_tx_queues) - r_idx = r_idx % adapter->num_tx_queues; - - return adapter->tx_ring[r_idx]; + return adapter->tx_ring[skb->queue_mapping]; } static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, @@ -6639,6 +6661,17 @@ static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, if (skb_put_padto(skb, 17)) return NETDEV_TX_OK; + /* After a fallback to fewer queues on runtime resume, the stack can + * use more queues than the device has until igb_rtnl_resume_task() + * updates it: drop those packets instead of sharing a ring between + * queues, which aren't serialized with each other. + */ + if (unlikely(skb->queue_mapping >= adapter->num_tx_queues)) { + dev_kfree_skb_any(skb); + dev_core_stats_tx_dropped_inc(netdev); + return NETDEV_TX_OK; + } + return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb)); } @@ -9653,8 +9686,11 @@ static int __igb_resume(struct device *dev, bool rpm) if (!rpm) rtnl_lock(); - if (!err && netif_running(netdev)) - err = __igb_open(netdev, true); + if (!err && netif_running(netdev)) { + err = __igb_open(netdev, true, !rpm); + if (!err && rpm) + schedule_work(&adapter->rtnl_resume_task); + } if (!err) netif_device_attach(netdev); -- 2.56.1