Skip to content

Commit 911a940

Browse files
Erni Sri Satya Vennelagregkh
authored andcommitted
net: mana: Fix potential deadlocks in mana napi ops
[ Upstream commit d5c8f0e ] When net_shaper_ops are enabled for MANA, netdev_ops_lock becomes active. MANA VF setup/teardown by netvsc follows this call chain: netvsc_vf_setup() dev_change_flags() ... __dev_open() OR __dev_close() dev_change_flags() holds the netdev mutex via netdev_lock_ops. Meanwhile, mana_create_txq() and mana_create_rxq() in mana_open() path call NAPI APIs (netif_napi_add_tx(), netif_napi_add_weight(), napi_enable()), which also try to acquire the same lock, risking deadlock. Similarly in the teardown path (mana_close()), netif_napi_disable() and netif_napi_del(), contend for the same lock. Switch to the _locked variants of these APIs to avoid deadlocks when the netdev_ops_lock is held. Fixes: d4c22ec ("net: hold netdev instance lock during ndo_open/ndo_stop") Signed-off-by: Erni Sri Satya Vennela <[email protected]> Reviewed-by: Haiyang Zhang <[email protected]> Reviewed-by: Shradha Gupta <[email protected]> Reviewed-by: Saurabh Singh Sengar <[email protected]> Reviewed-by: Long Li <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent cc476c6 commit 911a940

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

drivers/net/ethernet/microsoft/mana/mana_en.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,8 +1912,10 @@ static void mana_destroy_txq(struct mana_port_context *apc)
19121912
napi = &apc->tx_qp[i].tx_cq.napi;
19131913
if (apc->tx_qp[i].txq.napi_initialized) {
19141914
napi_synchronize(napi);
1915-
napi_disable(napi);
1916-
netif_napi_del(napi);
1915+
netdev_lock_ops_to_full(napi->dev);
1916+
napi_disable_locked(napi);
1917+
netif_napi_del_locked(napi);
1918+
netdev_unlock_full_to_ops(napi->dev);
19171919
apc->tx_qp[i].txq.napi_initialized = false;
19181920
}
19191921
mana_destroy_wq_obj(apc, GDMA_SQ, apc->tx_qp[i].tx_object);
@@ -2065,8 +2067,11 @@ static int mana_create_txq(struct mana_port_context *apc,
20652067

20662068
mana_create_txq_debugfs(apc, i);
20672069

2068-
netif_napi_add_tx(net, &cq->napi, mana_poll);
2069-
napi_enable(&cq->napi);
2070+
set_bit(NAPI_STATE_NO_BUSY_POLL, &cq->napi.state);
2071+
netdev_lock_ops_to_full(net);
2072+
netif_napi_add_locked(net, &cq->napi, mana_poll);
2073+
napi_enable_locked(&cq->napi);
2074+
netdev_unlock_full_to_ops(net);
20702075
txq->napi_initialized = true;
20712076

20722077
mana_gd_ring_cq(cq->gdma_cq, SET_ARM_BIT);
@@ -2102,9 +2107,10 @@ static void mana_destroy_rxq(struct mana_port_context *apc,
21022107
if (napi_initialized) {
21032108
napi_synchronize(napi);
21042109

2105-
napi_disable(napi);
2106-
2107-
netif_napi_del(napi);
2110+
netdev_lock_ops_to_full(napi->dev);
2111+
napi_disable_locked(napi);
2112+
netif_napi_del_locked(napi);
2113+
netdev_unlock_full_to_ops(napi->dev);
21082114
}
21092115
xdp_rxq_info_unreg(&rxq->xdp_rxq);
21102116

@@ -2355,14 +2361,18 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
23552361

23562362
gc->cq_table[cq->gdma_id] = cq->gdma_cq;
23572363

2358-
netif_napi_add_weight(ndev, &cq->napi, mana_poll, 1);
2364+
netdev_lock_ops_to_full(ndev);
2365+
netif_napi_add_weight_locked(ndev, &cq->napi, mana_poll, 1);
2366+
netdev_unlock_full_to_ops(ndev);
23592367

23602368
WARN_ON(xdp_rxq_info_reg(&rxq->xdp_rxq, ndev, rxq_idx,
23612369
cq->napi.napi_id));
23622370
WARN_ON(xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq, MEM_TYPE_PAGE_POOL,
23632371
rxq->page_pool));
23642372

2365-
napi_enable(&cq->napi);
2373+
netdev_lock_ops_to_full(ndev);
2374+
napi_enable_locked(&cq->napi);
2375+
netdev_unlock_full_to_ops(ndev);
23662376

23672377
mana_gd_ring_cq(cq->gdma_cq, SET_ARM_BIT);
23682378
out:

0 commit comments

Comments
 (0)