Skip to content

Commit aa626da

Browse files
Ivan Veceraanguy11
authored andcommitted
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: 62fe2a8 ("i40evf: add missing rtnl_lock() around i40evf_set_interrupt_capability") Cc: Jacob Keller <[email protected]> Cc: Patryk Piotrowski <[email protected]> Cc: SlawomirX Laba <[email protected]> Tested-by: Vitaly Grinberg <[email protected]> Signed-off-by: Ivan Vecera <[email protected]> Tested-by: Konrad Jankowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent fb8396a commit aa626da

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,14 +2877,19 @@ static void iavf_reset_task(struct work_struct *work)
28772877
int i = 0, err;
28782878
bool running;
28792879

2880+
/* Detach interface to avoid subsequent NDO callbacks */
2881+
rtnl_lock();
2882+
netif_device_detach(netdev);
2883+
rtnl_unlock();
2884+
28802885
/* When device is being removed it doesn't make sense to run the reset
28812886
* task, just return in such a case.
28822887
*/
28832888
if (!mutex_trylock(&adapter->crit_lock)) {
28842889
if (adapter->state != __IAVF_REMOVE)
28852890
queue_work(iavf_wq, &adapter->reset_task);
28862891

2887-
return;
2892+
goto reset_finish;
28882893
}
28892894

28902895
while (!mutex_trylock(&adapter->client_lock))
@@ -2954,7 +2959,6 @@ static void iavf_reset_task(struct work_struct *work)
29542959

29552960
if (running) {
29562961
netif_carrier_off(netdev);
2957-
netif_tx_stop_all_queues(netdev);
29582962
adapter->link_up = false;
29592963
iavf_napi_disable_all(adapter);
29602964
}
@@ -3084,7 +3088,7 @@ static void iavf_reset_task(struct work_struct *work)
30843088
mutex_unlock(&adapter->client_lock);
30853089
mutex_unlock(&adapter->crit_lock);
30863090

3087-
return;
3091+
goto reset_finish;
30883092
reset_err:
30893093
if (running) {
30903094
set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
@@ -3095,6 +3099,10 @@ static void iavf_reset_task(struct work_struct *work)
30953099
mutex_unlock(&adapter->client_lock);
30963100
mutex_unlock(&adapter->crit_lock);
30973101
dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
3102+
reset_finish:
3103+
rtnl_lock();
3104+
netif_device_attach(netdev);
3105+
rtnl_unlock();
30983106
}
30993107

31003108
/**

0 commit comments

Comments
 (0)