Skip to content

Commit c875503

Browse files
Jijie Shaokuba-moo
authored andcommitted
net: hibmcge: fix rtnl deadlock issue
Currently, the hibmcge netdev acquires the rtnl_lock in pci_error_handlers.reset_prepare() and releases it in pci_error_handlers.reset_done(). However, in the PCI framework: pci_reset_bus - __pci_reset_slot - pci_slot_save_and_disable_locked - pci_dev_save_and_disable - err_handler->reset_prepare(dev); In pci_slot_save_and_disable_locked(): list_for_each_entry(dev, &slot->bus->devices, bus_list) { if (!dev->slot || dev->slot!= slot) continue; pci_dev_save_and_disable(dev); if (dev->subordinate) pci_bus_save_and_disable_locked(dev->subordinate); } This will iterate through all devices under the current bus and execute err_handler->reset_prepare(), causing two devices of the hibmcge driver to sequentially request the rtnl_lock, leading to a deadlock. Since the driver now executes netif_device_detach() before the reset process, it will not concurrently with other netdev APIs, so there is no need to hold the rtnl_lock now. Therefore, this patch removes the rtnl_lock during the reset process and adjusts the position of HBG_NIC_STATE_RESETTING to ensure that multiple resets are not executed concurrently. Fixes: 3f5a61f ("net: hibmcge: Add reset supported in this module") Signed-off-by: Jijie Shao <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f6a2a31 commit c875503

File tree

1 file changed

+5
-9
lines changed
  • drivers/net/ethernet/hisilicon/hibmcge

1 file changed

+5
-9
lines changed

drivers/net/ethernet/hisilicon/hibmcge/hbg_err.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ static int hbg_reset_prepare(struct hbg_priv *priv, enum hbg_reset_type type)
5353
{
5454
int ret;
5555

56-
ASSERT_RTNL();
56+
if (test_and_set_bit(HBG_NIC_STATE_RESETTING, &priv->state))
57+
return -EBUSY;
5758

5859
if (netif_running(priv->netdev)) {
60+
clear_bit(HBG_NIC_STATE_RESETTING, &priv->state);
5961
dev_warn(&priv->pdev->dev,
6062
"failed to reset because port is up\n");
6163
return -EBUSY;
@@ -64,7 +66,6 @@ static int hbg_reset_prepare(struct hbg_priv *priv, enum hbg_reset_type type)
6466
netif_device_detach(priv->netdev);
6567

6668
priv->reset_type = type;
67-
set_bit(HBG_NIC_STATE_RESETTING, &priv->state);
6869
clear_bit(HBG_NIC_STATE_RESET_FAIL, &priv->state);
6970
ret = hbg_hw_event_notify(priv, HBG_HW_EVENT_RESET);
7071
if (ret) {
@@ -84,29 +85,26 @@ static int hbg_reset_done(struct hbg_priv *priv, enum hbg_reset_type type)
8485
type != priv->reset_type)
8586
return 0;
8687

87-
ASSERT_RTNL();
88-
89-
clear_bit(HBG_NIC_STATE_RESETTING, &priv->state);
9088
ret = hbg_rebuild(priv);
9189
if (ret) {
9290
priv->stats.reset_fail_cnt++;
9391
set_bit(HBG_NIC_STATE_RESET_FAIL, &priv->state);
92+
clear_bit(HBG_NIC_STATE_RESETTING, &priv->state);
9493
dev_err(&priv->pdev->dev, "failed to rebuild after reset\n");
9594
return ret;
9695
}
9796

9897
netif_device_attach(priv->netdev);
98+
clear_bit(HBG_NIC_STATE_RESETTING, &priv->state);
9999

100100
dev_info(&priv->pdev->dev, "reset done\n");
101101
return ret;
102102
}
103103

104-
/* must be protected by rtnl lock */
105104
int hbg_reset(struct hbg_priv *priv)
106105
{
107106
int ret;
108107

109-
ASSERT_RTNL();
110108
ret = hbg_reset_prepare(priv, HBG_RESET_TYPE_FUNCTION);
111109
if (ret)
112110
return ret;
@@ -171,7 +169,6 @@ static void hbg_pci_err_reset_prepare(struct pci_dev *pdev)
171169
struct net_device *netdev = pci_get_drvdata(pdev);
172170
struct hbg_priv *priv = netdev_priv(netdev);
173171

174-
rtnl_lock();
175172
hbg_reset_prepare(priv, HBG_RESET_TYPE_FLR);
176173
}
177174

@@ -181,7 +178,6 @@ static void hbg_pci_err_reset_done(struct pci_dev *pdev)
181178
struct hbg_priv *priv = netdev_priv(netdev);
182179

183180
hbg_reset_done(priv, HBG_RESET_TYPE_FLR);
184-
rtnl_unlock();
185181
}
186182

187183
static const struct pci_error_handlers hbg_pci_err_handler = {

0 commit comments

Comments
 (0)