Skip to content

Commit 9745780

Browse files
SlawomirLabaanguy11
authored andcommitted
iavf: Add waiting so the port is initialized in remove
There exist races when port is being configured and remove is triggered. unregister_netdev is not and can't be called under crit_lock mutex since it is calling ndo_stop -> iavf_close which requires this lock. Depending on init state the netdev could be still unregistered so unregister_netdev never cleans up, when shortly after that the device could become registered. Make iavf_remove wait until port finishes initialization. All critical state changes are atomic (under crit_lock). Crashes that come from iavf_reset_interrupt_capability and iavf_free_traffic_irqs should now be solved in a graceful manner. Fixes: 605ca7c ("iavf: Fix kernel BUG in free_msi_irqs") Signed-off-by: Slawomir Laba <slawomirx.laba@intel.com> Signed-off-by: Phani Burra <phani.r.burra@intel.com> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Mateusz Palczewski <mateusz.palczewski@intel.com> Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent fc2e6b3 commit 9745780

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

drivers/net/ethernet/intel/iavf/iavf_main.c

+16-11
Original file line numberDiff line numberDiff line change
@@ -4558,7 +4558,6 @@ static int __maybe_unused iavf_resume(struct device *dev_d)
45584558
static void iavf_remove(struct pci_dev *pdev)
45594559
{
45604560
struct iavf_adapter *adapter = iavf_pdev_to_adapter(pdev);
4561-
enum iavf_state_t prev_state = adapter->last_state;
45624561
struct net_device *netdev = adapter->netdev;
45634562
struct iavf_fdir_fltr *fdir, *fdirtmp;
45644563
struct iavf_vlan_filter *vlf, *vlftmp;
@@ -4568,6 +4567,22 @@ static void iavf_remove(struct pci_dev *pdev)
45684567
struct iavf_hw *hw = &adapter->hw;
45694568
int err;
45704569

4570+
/* Wait until port initialization is complete.
4571+
* There are flows where register/unregister netdev may race.
4572+
*/
4573+
while (1) {
4574+
mutex_lock(&adapter->crit_lock);
4575+
if (adapter->state == __IAVF_RUNNING ||
4576+
adapter->state == __IAVF_DOWN) {
4577+
mutex_unlock(&adapter->crit_lock);
4578+
break;
4579+
}
4580+
4581+
mutex_unlock(&adapter->crit_lock);
4582+
usleep_range(500, 1000);
4583+
}
4584+
cancel_delayed_work_sync(&adapter->watchdog_task);
4585+
45714586
if (adapter->netdev_registered) {
45724587
unregister_netdev(netdev);
45734588
adapter->netdev_registered = false;
@@ -4605,16 +4620,6 @@ static void iavf_remove(struct pci_dev *pdev)
46054620
iavf_free_all_rx_resources(adapter);
46064621
iavf_free_misc_irq(adapter);
46074622

4608-
/* In case we enter iavf_remove from erroneous state, free traffic irqs
4609-
* here, so as to not cause a kernel crash, when calling
4610-
* iavf_reset_interrupt_capability.
4611-
*/
4612-
if ((adapter->last_state == __IAVF_RESETTING &&
4613-
prev_state != __IAVF_DOWN) ||
4614-
(adapter->last_state == __IAVF_RUNNING &&
4615-
!(netdev->flags & IFF_UP)))
4616-
iavf_free_traffic_irqs(adapter);
4617-
46184623
iavf_reset_interrupt_capability(adapter);
46194624
iavf_free_q_vectors(adapter);
46204625

0 commit comments

Comments
 (0)