Skip to content

Commit 9870257

Browse files
shimodaykuba-moo
authored andcommitted
ravb: Fix races between ravb_tx_timeout_work() and net related ops
Fix races between ravb_tx_timeout_work() and functions of net_device_ops and ethtool_ops by using rtnl_trylock() and rtnl_unlock(). Note that since ravb_close() is under the rtnl lock and calls cancel_work_sync(), ravb_tx_timeout_work() should calls rtnl_trylock(). Otherwise, a deadlock may happen in ravb_tx_timeout_work() like below: CPU0 CPU1 ravb_tx_timeout() schedule_work() ... __dev_close_many() // Under rtnl lock ravb_close() cancel_work_sync() // Waiting ravb_tx_timeout_work() rtnl_lock() // This is possible to cause a deadlock If rtnl_trylock() fails, rescheduling the work with sleep for 1 msec. Fixes: c156633 ("Renesas Ethernet AVB driver proper") Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru> Link: https://lore.kernel.org/r/20231127122420.3706751-1-yoshihiro.shimoda.uh@renesas.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 91d3d14 commit 9870257

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,12 @@ static void ravb_tx_timeout_work(struct work_struct *work)
18741874
struct net_device *ndev = priv->ndev;
18751875
int error;
18761876

1877+
if (!rtnl_trylock()) {
1878+
usleep_range(1000, 2000);
1879+
schedule_work(&priv->work);
1880+
return;
1881+
}
1882+
18771883
netif_tx_stop_all_queues(ndev);
18781884

18791885
/* Stop PTP Clock driver */
@@ -1907,7 +1913,7 @@ static void ravb_tx_timeout_work(struct work_struct *work)
19071913
*/
19081914
netdev_err(ndev, "%s: ravb_dmac_init() failed, error %d\n",
19091915
__func__, error);
1910-
return;
1916+
goto out_unlock;
19111917
}
19121918
ravb_emac_init(ndev);
19131919

@@ -1917,6 +1923,9 @@ static void ravb_tx_timeout_work(struct work_struct *work)
19171923
ravb_ptp_init(ndev, priv->pdev);
19181924

19191925
netif_tx_start_all_queues(ndev);
1926+
1927+
out_unlock:
1928+
rtnl_unlock();
19201929
}
19211930

19221931
/* Packet transmit function for Ethernet AVB */

0 commit comments

Comments
 (0)