Commit aa626da9 authored by Ivan Vecera's avatar Ivan Vecera Committed by Tony Nguyen

iavf: Detach device during reset task

iavf_reset_task() takes crit_lock at the beginning and holds
it during whole call. The function subsequently calls
iavf_init_interrupt_scheme() that grabs RTNL. Problem occurs
when userspace initiates during the reset task any ndo callback
that runs under RTNL like iavf_open() because some of that
functions tries to take crit_lock. This leads to classic A-B B-A
deadlock scenario.

To resolve this situation the device should be detached in
iavf_reset_task() prior taking crit_lock to avoid subsequent
ndos running under RTNL and reattach the device at the end.

Fixes: 62fe2a86 ("i40evf: add missing rtnl_lock() around i40evf_set_interrupt_capability")
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Patryk Piotrowski <patryk.piotrowski@intel.com>
Cc: SlawomirX Laba <slawomirx.laba@intel.com>
Tested-by: default avatarVitaly Grinberg <vgrinber@redhat.com>
Signed-off-by: default avatarIvan Vecera <ivecera@redhat.com>
Tested-by: default avatarKonrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent fb8396ae
...@@ -2877,6 +2877,11 @@ static void iavf_reset_task(struct work_struct *work) ...@@ -2877,6 +2877,11 @@ static void iavf_reset_task(struct work_struct *work)
int i = 0, err; int i = 0, err;
bool running; bool running;
/* Detach interface to avoid subsequent NDO callbacks */
rtnl_lock();
netif_device_detach(netdev);
rtnl_unlock();
/* When device is being removed it doesn't make sense to run the reset /* When device is being removed it doesn't make sense to run the reset
* task, just return in such a case. * task, just return in such a case.
*/ */
...@@ -2884,7 +2889,7 @@ static void iavf_reset_task(struct work_struct *work) ...@@ -2884,7 +2889,7 @@ static void iavf_reset_task(struct work_struct *work)
if (adapter->state != __IAVF_REMOVE) if (adapter->state != __IAVF_REMOVE)
queue_work(iavf_wq, &adapter->reset_task); queue_work(iavf_wq, &adapter->reset_task);
return; goto reset_finish;
} }
while (!mutex_trylock(&adapter->client_lock)) while (!mutex_trylock(&adapter->client_lock))
...@@ -2954,7 +2959,6 @@ static void iavf_reset_task(struct work_struct *work) ...@@ -2954,7 +2959,6 @@ static void iavf_reset_task(struct work_struct *work)
if (running) { if (running) {
netif_carrier_off(netdev); netif_carrier_off(netdev);
netif_tx_stop_all_queues(netdev);
adapter->link_up = false; adapter->link_up = false;
iavf_napi_disable_all(adapter); iavf_napi_disable_all(adapter);
} }
...@@ -3084,7 +3088,7 @@ static void iavf_reset_task(struct work_struct *work) ...@@ -3084,7 +3088,7 @@ static void iavf_reset_task(struct work_struct *work)
mutex_unlock(&adapter->client_lock); mutex_unlock(&adapter->client_lock);
mutex_unlock(&adapter->crit_lock); mutex_unlock(&adapter->crit_lock);
return; goto reset_finish;
reset_err: reset_err:
if (running) { if (running) {
set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
...@@ -3095,6 +3099,10 @@ static void iavf_reset_task(struct work_struct *work) ...@@ -3095,6 +3099,10 @@ static void iavf_reset_task(struct work_struct *work)
mutex_unlock(&adapter->client_lock); mutex_unlock(&adapter->client_lock);
mutex_unlock(&adapter->crit_lock); mutex_unlock(&adapter->crit_lock);
dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n"); dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
reset_finish:
rtnl_lock();
netif_device_attach(netdev);
rtnl_unlock();
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment