Netdev List
 help / color / mirror / Atom feed
From: Magnus Lindholm <linmag7@gmail.com>
To: netdev@vger.kernel.org
Cc: pavan.chebbi@broadcom.com, michael.chan@broadcom.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com,
	Magnus Lindholm <linmag7@gmail.com>,
	Prashant Sreedharan <prashant@broadcom.com>
Subject: [PATCH net 1/6] tg3: defer reset work when RTNL is busy
Date: Fri,  4 Dec 2026 19:54:45 +0100	[thread overview]
Message-ID: <20261204185640.2332668-2-linmag7@gmail.com> (raw)
In-Reply-To: <20261204185640.2332668-1-linmag7@gmail.com>

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 <prashant@broadcom.com>
Signed-off-by: Magnus Lindholm <linmag7@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


  reply	other threads:[~2026-12-04 18:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:54 [PATCH net 0/6] tg3: fix reset and NAPI ordering and reject empty RX rings Magnus Lindholm
2026-12-04 18:54 ` Magnus Lindholm [this message]
2026-12-04 18:54 ` [PATCH net 2/6] tg3: gate reset work across device teardown Magnus Lindholm
2026-12-04 18:54 ` [PATCH net 3/6] tg3: unregister the netdevice before releasing its resources Magnus Lindholm
2026-12-04 18:54 ` [PATCH net 4/6] tg3: honor NAPI completion before rearming interrupts Magnus Lindholm
2026-12-04 18:54 ` [PATCH net 5/6] tg3: wait for NAPI poll callbacks before resetting hardware Magnus Lindholm
2026-12-04 18:54 ` [PATCH net 6/6] tg3: reject an empty standard RX ring Magnus Lindholm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204185640.2332668-2-linmag7@gmail.com \
    --to=linmag7@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.com \
    --cc=prashant@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox