Close and suspend cancel reset work under RTNL. If the worker waits for RTNL, the caller cannot finish canceling it. Use delayed work and retry one jiffy later when rtnl_trylock() fails. A driver audit with Codex identified the lock cycle. The reproducer queued the worker under RTNL and canceled it before releasing RTNL. On a BCM5718 the worker deferred and cancellation finished in ten trials. In a separate trial, releasing RTNL let the worker reset the port. The deadlock in the original code was inferred from the locking order. With all six patches on a BCM5718, ring_reconfig.py passed channels and skipped reconfig_tx_stall (no combined channels). Changing ring sizes resets the PHY on this 5717-class ASIC. The ringparam traffic check timed out at 1 RX / 31 TX with a nominal five-second startup window. Peer reachability took 8.7 seconds at that depth in a separate run. TCP then passed in both directions. Fixes: db84bf43ef23 ("tg3: tg3_reset_task() needs to use rtnl_lock to synchronize") Cc: Prashant Sreedharan <pras…@broadcom.com> Signed-off-by: Magnus Lindholm <linm…@gmail.com> --- drivers/net/ethernet/broadcom/tg3.c | 16 ++++++++++------ drivers/net/ethernet/broadcom/tg3.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index 95827df4cf6a..86ef8e438988 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -7238,13 +7238,13 @@ static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) static inline void tg3_reset_task_schedule(struct tg3 *tp) { if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) - schedule_work(&tp->reset_task); + schedule_delayed_work(&tp->reset_task, 0); } static inline void tg3_reset_task_cancel(struct tg3 *tp) { if (test_and_clear_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) - cancel_work_sync(&tp->reset_task); + cancel_delayed_work_sync(&tp->reset_task); tg3_flag_clear(tp, TX_RECOVERY_PENDING); } @@ -11262,10 +11262,14 @@ static int tg3_restart_hw(struct tg3 *tp, bool reset_phy) static void tg3_reset_task(struct work_struct *work) { - struct tg3 *tp = container_of(work, struct tg3, reset_task); + struct tg3 *tp = container_of(work, struct tg3, reset_task.work); int err; - rtnl_lock(); + /* Close and suspend can cancel this work while holding RTNL. */ + if (!rtnl_trylock()) { + schedule_delayed_work(&tp->reset_task, 1); + return; + } tg3_full_lock(tp, 0); if (tp->pcierr_recovery || !netif_running(tp->dev) || @@ -11299,7 +11303,7 @@ static void tg3_reset_task(struct work_struct *work) tp->irq_sync = 0; tg3_napi_enable(tp); /* Clear this flag so that tg3_reset_task_cancel() will not - * call cancel_work_sync() and wait forever. + * call cancel_delayed_work_sync() and wait forever. */ tg3_flag_clear(tp, RESET_TASK_PENDING); netdev_unlock(tp->dev); @@ -17829,7 +17833,7 @@ static int tg3_init_one(struct pci_dev *pdev, #endif spin_lock_init(&tp->lock); spin_lock_init(&tp->indirect_lock); - INIT_WORK(&tp->reset_task, tg3_reset_task); + INIT_DELAYED_WORK(&tp->reset_task, tg3_reset_task); tp->regs = pci_ioremap_bar(pdev, BAR_0); if (!tp->regs) { diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h index a9e7f88fa26d..e5716a969e00 100644 --- a/drivers/net/ethernet/broadcom/tg3.h +++ b/drivers/net/ethernet/broadcom/tg3.h @@ -3372,7 +3372,7 @@ struct tg3 { struct tg3_hw_stats *hw_stats; dma_addr_t stats_mapping; - struct work_struct reset_task; + struct delayed_work reset_task; struct sk_buff *tx_tstamp_skb; u64 pre_tx_ts;
-- 2.43.0