If Admin Queue initialization fails during a VF reset, iavf_disable_vf() frees the queues and lets the watchdog retry initialization. The registered netdev can retain IFF_UP while the adapter reaches __IAVF_DOWN. The finish-config worker updates the queue counts but does not allocate and enable the data queues, leaving the interface without traffic until a manual down/up. Share the queue-start sequence with ndo_open and run it from iavf_finish_config() for an already registered, administratively up VF. Keep RTNL before the netdev lock and skip detached devices, removal, pending resets and outstanding Admin Queue operations. Reconcile the current primary and UC/MC filters on the registered recovery path before allocating queue resources. Take the address-list lock before the private filter-list lock and reset UC/MC synchronization state there, keeping the new address-lock access out of early probe failure paths. Classify existing filters against the complete current address set before any allocation can fail. Preserve pending deletes for acknowledged filters, cancel stale unsent additions and rearm the pending AQ requests. Replay current additions even if an earlier ADD failed before reaching the PF. Check primary and UC/MC preparation errors and leave the adapter DOWN for retry instead of starting queues with an incomplete address set. Use the existing watchdog to retry an idle DOWN interface which retains IFF_UP. This also covers a restart skipped before resume attaches the netdev. Mark the resume reset pending under RTNL and the netdev lock before releasing them, so finish-config cannot start queues ahead of it. The IRQ request helper already unwinds on failure. Skip unused vectors in that unwind and do not free the IRQs again in the shared queue-start caller. This lets that caller retry without freeing unrequested IRQs. Remove the unreachable RUNNING check while extracting the open sequence; the preceding DOWN check already returns -EBUSY for RUNNING adapters. The revert in the Fixes tag removed dev_close() from reset failures while leaving IFF_UP set. That close previously required an administrative up to restart traffic. This change adds automatic queue restart after successful reinitialization while the interface remains administratively up. The failure was observed on a running SR-IOV guest. Reproduce the recovery failure with a lab-only hook which returns IAVF_ERR_ADMIN_QUEUE_ERROR once from post-reset iavf_init_adminq(), then request a reset by changing the RX descriptor count with ethtool -G. The matching Ubuntu backport recovered traffic with IFF_UP intact; the baseline stayed without carrier for the 30-second observation window. The original PF reset trigger is unknown. Developed with AI assistance (Codex). Fixes: d916d273041b ("Revert "iavf: Do not restart Tx queues after reset task failure"") Signed-off-by: Alexander Lopintsev --- Changes in v2: - Keep MAC reconciliation and address locking on the registered recovery path. Preserve pending DEL, cancel stale unsent ADD and rearm current ADD. - Check primary/UC/MC preparation before allocating queue resources and retry an idle DOWN/UP interface through the existing watchdog. - Serialize resume reset intent with finish-config. - Unwind partial traffic IRQ requests once, skipping unused vectors. - Clarify the history and keep restoration limited to queues and UC/MC. Testing the final v2: - 39 source-extracted C checks pass on the current-net source and matching Ubuntu backport, with AddressSanitizer and UndefinedBehaviorSanitizer. These exercise pending DEL, stale ADD, local ADD-send failure, MAC allocation errors, queue-resource unwind and watchdog/attach/resume paths. - The prior ten finish-config checks pass; the original base fails three. - Current-net iavf builds pass with x86 allmodconfig and allyesconfig, W=1, GCC 13.4.0 and -Werror for iavf_main.c, with no driver warnings. Global WERROR/DRM_WERROR remain disabled for baseline diagnostics; allyesconfig retains KASAN_OUTLINE. These are driver builds. - The matching Ubuntu 7.0.0-38-generic clean and lab modules build with GCC 15.2.0. Vermagic and all imported symbol CRCs match the running kernel. - Strict checkpatch and git-am on the exact baseline-file fixture pass. - Hardware A/B on an Intel X722 VF passes: the final v2 backport recovers carrier and three IPv6 replies after one injected post-reset Admin Queue -53, with IFF_UP intact. The same baseline remains without carrier for the 30-second observation window. Normal ring-resize resets pass for both. - The clean corrected backport then stayed running for 14h52m under normal traffic: another 21.82 GB RX and 46.77 GB TX, zero errors/drops, no new iavf or kernel warning messages, and no reboot. The C tests use kernel API, PF and allocator stubs. They do not prove real locking, PM scheduling, DMA or hardware allocation-failure behavior. The hardware A/B covers the injected AQ error on the Ubuntu backport; pending DEL and MAC allocation errors were exercised by the C tests. The current net kernel was not booted. Kernel networking selftests and lockdep were not run. The original PF reset trigger remains unknown. Test sources and lab-only hook: https://github.com/alopintsev/iavf-recovery v1: https://lore.kernel.org/netdev/20261203083936.79920-1-cldlss@gmail.com/ drivers/net/ethernet/intel/iavf/iavf_main.c | 198 +++++++++++++++----- 1 file changed, 150 insertions(+), 48 deletions(-) diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c index 4de3ea8525b3..47be929c019f 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -14,6 +14,7 @@ #define CREATE_TRACE_POINTS #include "iavf_trace.h" +static int iavf_start_queues(struct iavf_adapter *adapter, bool reinit); static int iavf_setup_all_tx_resources(struct iavf_adapter *adapter); static int iavf_setup_all_rx_resources(struct iavf_adapter *adapter); static int iavf_close(struct net_device *netdev); @@ -558,6 +559,9 @@ iavf_request_traffic_irqs(struct iavf_adapter *adapter, char *basename) free_queue_irqs: while (vector) { vector--; + if (!adapter->q_vectors[vector].tx.ring && + !adapter->q_vectors[vector].rx.ring) + continue; irq_num = adapter->msix_entries[vector + NONQ_VECS].vector; free_irq(irq_num, &adapter->q_vectors[vector]); } @@ -1311,6 +1315,74 @@ static void iavf_clear_mac_filters(struct iavf_adapter *adapter) spin_unlock_bh(&adapter->mac_vlan_list_lock); } +/* Reconcile the current address set without losing pending PF updates. */ +static int iavf_reinit_mac_filters(struct iavf_adapter *adapter) +{ + struct net_device *netdev = adapter->netdev; + struct iavf_mac_filter *f, *ftmp; + struct netdev_hw_addr *ha; + int err; + + netdev_assert_locked(netdev); + + netif_addr_lock_bh(netdev); + spin_lock_bh(&adapter->mac_vlan_list_lock); + __dev_uc_unsync(netdev, NULL); + __dev_mc_unsync(netdev, NULL); + + /* Classify existing entries before any allocation can fail. */ + list_for_each_entry(f, &adapter->mac_filter_list, list) + f->remove = !ether_addr_equal(f->macaddr, adapter->hw.mac.addr); + netdev_for_each_uc_addr(ha, netdev) { + f = iavf_find_filter(adapter, ha->addr); + if (f) + f->remove = false; + } + netdev_for_each_mc_addr(ha, netdev) { + f = iavf_find_filter(adapter, ha->addr); + if (f) + f->remove = false; + } + list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { + if (!f->remove) { + /* A previous ADD may have failed before reaching the PF. */ + f->add = true; + f->add_handled = false; + } else if (f->add && f->is_new_mac && !f->add_handled) { + /* This stale address was never submitted to the PF. */ + list_del(&f->list); + kfree(f); + } else { + /* Keep the DEL record, but do not replay a stale ADD. */ + f->add = false; + } + } + + if (!iavf_add_filter(adapter, adapter->hw.mac.addr)) { + err = -ENOMEM; + goto out; + } + err = __hw_addr_sync_dev(&netdev->uc, netdev, iavf_addr_sync, + iavf_addr_unsync); + if (err) + goto out; + err = __hw_addr_sync_dev(&netdev->mc, netdev, iavf_addr_sync, + iavf_addr_unsync); + +out: + /* Communication failure may have cleared the pending AQ requests. */ + list_for_each_entry(f, &adapter->mac_filter_list, list) { + if (f->add) + adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER; + if (f->remove) + adapter->aq_required |= IAVF_FLAG_AQ_DEL_MAC_FILTER; + } + spin_unlock_bh(&adapter->mac_vlan_list_lock); + netif_addr_unlock_bh(netdev); + + return err; +} + /** * iavf_clear_cloud_filters - Remove cloud filters not sent to PF yet and * mark other to be removed. @@ -2003,21 +2075,23 @@ err: static void iavf_finish_config(struct work_struct *work) { struct iavf_adapter *adapter; + struct net_device *netdev; bool netdev_released = false; int pairs, err; adapter = container_of(work, struct iavf_adapter, finish_config); + netdev = adapter->netdev; /* Always take RTNL first to prevent circular lock dependency; * the dev->lock (== netdev lock) is needed to update the queue number. */ rtnl_lock(); - netdev_lock(adapter->netdev); + netdev_lock(netdev); if ((adapter->flags & IAVF_FLAG_SETUP_NETDEV_FEATURES) && - adapter->netdev->reg_state == NETREG_REGISTERED && + netdev->reg_state == NETREG_REGISTERED && !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) { - netdev_update_features(adapter->netdev); + netdev_update_features(netdev); adapter->flags &= ~IAVF_FLAG_SETUP_NETDEV_FEATURES; } @@ -2027,33 +2101,45 @@ static void iavf_finish_config(struct work_struct *work) * state == __IAVF_DOWN */ pairs = adapter->num_active_queues; - netif_set_real_num_rx_queues(adapter->netdev, pairs); - netif_set_real_num_tx_queues(adapter->netdev, pairs); + netif_set_real_num_rx_queues(netdev, pairs); + netif_set_real_num_tx_queues(netdev, pairs); - if (adapter->netdev->reg_state != NETREG_REGISTERED) { - netdev_unlock(adapter->netdev); + if (netdev->reg_state != NETREG_REGISTERED) { + netdev_unlock(netdev); netdev_released = true; - err = register_netdevice(adapter->netdev); + err = register_netdevice(netdev); if (err) { dev_err(&adapter->pdev->dev, "Unable to register netdev (%d)\n", err); /* go back and try again.*/ - netdev_lock(adapter->netdev); + netdev_lock(netdev); iavf_free_rss(adapter); iavf_free_misc_irq(adapter); iavf_reset_interrupt_capability(adapter); iavf_change_state(adapter, __IAVF_INIT_CONFIG_ADAPTER); - netdev_unlock(adapter->netdev); + netdev_unlock(netdev); goto out; } + } else if ((netdev->flags & IFF_UP) && netif_device_present(netdev) && + adapter->current_op == VIRTCHNL_OP_UNKNOWN && + !(adapter->flags & (IAVF_FLAG_PF_COMMS_FAILED | + IAVF_FLAG_RESET_PENDING | + IAVF_FLAG_RESET_NEEDED)) && + !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) { + /* The netdev kept IFF_UP while the VF was down. */ + adapter->flags |= IAVF_FLAG_QUEUES_DISABLED; + err = iavf_start_queues(adapter, true); + if (err) + netdev_err(netdev, "Failed to restart queues after VF reinitialization: %d\n", + err); } break; case __IAVF_RUNNING: pairs = adapter->num_active_queues; - netif_set_real_num_rx_queues(adapter->netdev, pairs); - netif_set_real_num_tx_queues(adapter->netdev, pairs); + netif_set_real_num_rx_queues(netdev, pairs); + netif_set_real_num_tx_queues(netdev, pairs); break; default: @@ -2062,7 +2148,7 @@ static void iavf_finish_config(struct work_struct *work) out: if (!netdev_released) - netdev_unlock(adapter->netdev); + netdev_unlock(netdev); rtnl_unlock(); } @@ -2974,6 +3060,11 @@ static int iavf_watchdog_step(struct iavf_adapter *adapter) case __IAVF_RESETTING: return 2000; case __IAVF_DOWN: + /* Retry recovery, including a restart skipped before resume attach. */ + if (netif_running(adapter->netdev) && !adapter->current_op && + !adapter->aq_required) + iavf_schedule_finish_config(adapter); + fallthrough; case __IAVF_DOWN_PENDING: case __IAVF_TESTING: case __IAVF_RUNNING: @@ -4472,37 +4563,17 @@ static void iavf_restore_fdir_filters(struct iavf_adapter *adapter) spin_unlock_bh(&adapter->fdir_fltr_lock); } -/** - * iavf_open - Called when a network interface is made active - * @netdev: network interface device structure - * - * Returns 0 on success, negative value on failure - * - * The open entry point is called when a network interface is made - * active by the system (IFF_UP). At this point all resources needed - * for transmit and receive operations are allocated, the interrupt - * handler is registered with the OS, the watchdog is started, - * and the stack is notified that the interface is ready. - **/ -static int iavf_open(struct net_device *netdev) +static int iavf_start_queues(struct iavf_adapter *adapter, bool reinit) { - struct iavf_adapter *adapter = netdev_priv(netdev); + struct net_device *netdev = adapter->netdev; int err; netdev_assert_locked(netdev); - if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) { - dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n"); - return -EIO; - } - - if (adapter->state != __IAVF_DOWN) - return -EBUSY; - - if (adapter->state == __IAVF_RUNNING && - !test_bit(__IAVF_VSI_DOWN, adapter->vsi.state)) { - dev_dbg(&adapter->pdev->dev, "VF is already open.\n"); - return 0; + if (reinit) { + err = iavf_reinit_mac_filters(adapter); + if (err) + return err; } /* allocate transmit descriptors */ @@ -4518,7 +4589,7 @@ static int iavf_open(struct net_device *netdev) /* clear any pending interrupts, may auto mask */ err = iavf_request_traffic_irqs(adapter, netdev->name); if (err) - goto err_req_irq; + goto err_setup_rx; spin_lock_bh(&adapter->mac_vlan_list_lock); iavf_add_filter(adapter, adapter->hw.mac.addr); @@ -4534,9 +4605,6 @@ static int iavf_open(struct net_device *netdev) return 0; -err_req_irq: - iavf_down(adapter); - iavf_free_traffic_irqs(adapter); err_setup_rx: iavf_free_all_rx_resources(adapter); err_setup_tx: @@ -4545,6 +4613,35 @@ err_setup_tx: return err; } +/** + * iavf_open - Called when a network interface is made active + * @netdev: network interface device structure + * + * Returns 0 on success, negative value on failure + * + * The open entry point is called when a network interface is made + * active by the system (IFF_UP). At this point all resources needed + * for transmit and receive operations are allocated, the interrupt + * handler is registered with the OS, the watchdog is started, + * and the stack is notified that the interface is ready. + **/ +static int iavf_open(struct net_device *netdev) +{ + struct iavf_adapter *adapter = netdev_priv(netdev); + + netdev_assert_locked(netdev); + + if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) { + dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n"); + return -EIO; + } + + if (adapter->state != __IAVF_DOWN) + return -EBUSY; + + return iavf_start_queues(adapter, false); +} + /** * iavf_close - Disables a network interface * @netdev: network interface device structure @@ -5518,22 +5615,27 @@ static int iavf_resume(struct device *dev_d) pci_set_master(pdev); rtnl_lock(); + netdev_lock(adapter->netdev); err = iavf_set_interrupt_capability(adapter); if (err) { - rtnl_unlock(); dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n"); - return err; + goto out; } err = iavf_request_misc_irq(adapter); - rtnl_unlock(); if (err) { dev_err(&pdev->dev, "Cannot get interrupt vector.\n"); - return err; + goto out; } + /* Block finish_config until the resume reset has completed. */ + adapter->flags |= IAVF_FLAG_RESET_PENDING; queue_work(adapter->wq, &adapter->reset_task); - netif_device_attach(adapter->netdev); +out: + netdev_unlock(adapter->netdev); + rtnl_unlock(); + if (!err) + netif_device_attach(adapter->netdev); return err; } base-commit: 0d39bf81267861742b80d5f1c52e8a63e9ca0ca1 -- 2.50.1 (Apple Git-155)