dpaa2-eth: do not hold rtnl_lock on phylink_create() or _destroy()
authorIoana Ciornei <ioana.ciornei@nxp.com>
Thu, 21 Nov 2019 19:15:25 +0000 (21:15 +0200)
committerIoana Ciornei <ciorneiioana@gmail.com>
Mon, 26 Apr 2021 09:22:47 +0000 (12:22 +0300)
The rtnl_lock should not be held when calling phylink_create() or
phylink_destroy() since it leads to the deadlock listed below:

[   18.656576]  rtnl_lock+0x18/0x20
[   18.659798]  sfp_bus_add_upstream+0x28/0x90
[   18.663974]  phylink_create+0x2cc/0x828
[   18.667803]  dpaa2_mac_connect+0x14c/0x2a8
[   18.671890]  dpaa2_eth_connect_mac+0x94/0xd8

Fix this by moving the _lock() and _unlock() calls just outside of
phylink_of_phy_connect() and phylink_disconnect_phy().

Fixes: 719479230893 ("dpaa2-eth: add MAC/PHY support through phylink")
Reported-by: Russell King <linux@armlinux.org.uk>
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c

index 7a91ffa..f80ecee 100644 (file)
@@ -4151,12 +4151,10 @@ static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg)
                dpaa2_eth_set_mac_addr(netdev_priv(net_dev));
                dpaa2_eth_update_tx_fqids(priv);
 
-               rtnl_lock();
                if (dpaa2_eth_has_mac(priv))
                        dpaa2_eth_disconnect_mac(priv);
                else
                        dpaa2_eth_connect_mac(priv);
-               rtnl_unlock();
        }
 
        return IRQ_HANDLED;
@@ -4446,9 +4444,7 @@ static int dpaa2_eth_remove(struct fsl_mc_device *ls_dev)
 #ifdef CONFIG_DEBUG_FS
        dpaa2_dbg_remove(priv);
 #endif
-       rtnl_lock();
        dpaa2_eth_disconnect_mac(priv);
-       rtnl_unlock();
 
        unregister_netdev(net_dev);
 
index c2a889a..0172cc3 100644 (file)
@@ -343,7 +343,9 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
        if (mac->pcs)
                phylink_set_pcs(mac->phylink, &mac->pcs->pcs);
 
+       rtnl_lock();
        err = phylink_of_phy_connect(mac->phylink, dpmac_node, 0);
+       rtnl_unlock();
        if (err) {
                netdev_err(net_dev, "phylink_of_phy_connect() = %d\n", err);
                goto err_phylink_destroy;
@@ -368,7 +370,9 @@ void dpaa2_mac_disconnect(struct dpaa2_mac *mac)
        if (!mac->phylink)
                return;
 
+       rtnl_lock();
        phylink_disconnect_phy(mac->phylink);
+       rtnl_unlock();
        phylink_destroy(mac->phylink);
        dpaa2_pcs_destroy(mac);
 }