__igb_open() links queues to NAPIs with netif_queue_set_napi(), which requires RTNL, but RTNL isn't held when resuming from runtime suspend: this triggers "RTNL: assertion failed". Link them in __igb_open() only when RTNL is held, and from the work item that sets the real queue counts on runtime resume. The links can't be kept across a suspend, because __igb_shutdown() frees the q_vectors. A suspend now cancels the work item before freeing them, so it only runs after the resume that scheduled it allocated them, and it checks __IGB_DOWN under RTNL for a close in the meantime. Tested with the 82576 emulated by QEMU. Fixes: b75a1dea500f ("igb: Link queues to NAPI instances") Cc: stable@vger.kernel.org # 6.16+ Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562 Signed-off-by: Antonio Quartulli --- v5: cancel the work item before a suspend (Sashiko) v4: no changes v3: link the NAPIs from the work item added by the previous patch, and in __igb_open() whenever RTNL is held (also on system sleep resume); dropped Joe's Reviewed-by, as the patch changed v2: no code changes; mention the tested hardware Note: igc has the same issue: __igc_open() also links queues to NAPIs (igc_set_queue_napi()) on the RTNL-less runtime resume path. A fix will follow separately once it has been tested on igc hardware. drivers/net/ethernet/intel/igb/igb_main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 6961646..acd9a33 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -4146,8 +4146,19 @@ static int igb_set_real_num_queues(struct igb_adapter *adapter) return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq); } +static void igb_link_queue_napis(struct igb_adapter *adapter) +{ + int i; + + for (i = 0; i < adapter->num_q_vectors; i++) + igb_set_queue_napi(adapter, i, &adapter->q_vector[i]->napi); +} + /* Some settings need RTNL, which isn't held when resuming from runtime - * suspend: apply them from here instead, if the device is still up. + * suspend: apply them from here instead, if the device is still up. A + * suspend cancels this work before freeing the q_vectors, so it only runs + * after the resume that scheduled it allocated them; checking __IGB_DOWN + * under RTNL covers a close in the meantime. */ static void igb_rtnl_resume_task(struct work_struct *work) { @@ -4160,6 +4171,7 @@ static void igb_rtnl_resume_task(struct work_struct *work) if (igb_set_real_num_queues(adapter)) netdev_err(adapter->netdev, "error setting real queue count\n"); + igb_link_queue_napis(adapter); } rtnl_unlock(); } @@ -4237,7 +4249,8 @@ static int __igb_open(struct net_device *netdev, bool resuming, for (i = 0; i < adapter->num_q_vectors; i++) { napi = &adapter->q_vector[i]->napi; napi_enable(napi); - igb_set_queue_napi(adapter, i, napi); + if (rtnl_held) + igb_set_queue_napi(adapter, i, napi); } /* Clear any pending interrupts. */ @@ -9548,6 +9561,11 @@ static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake, u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; bool wake; + /* Don't let a work item queued by an earlier resume run once the + * q_vectors are freed or reallocated + */ + cancel_work_sync(&adapter->rtnl_resume_task); + rtnl_lock(); netif_device_detach(netdev); -- 2.56.1