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>,
Matt Carlson <mcarlson@broadcom.com>
Subject: [PATCH net 2/6] tg3: gate reset work across device teardown
Date: Fri, 4 Dec 2026 19:54:46 +0100 [thread overview]
Message-ID: <20261204185640.2332668-3-linmag7@gmail.com> (raw)
In-Reply-To: <20261204185640.2332668-1-linmag7@gmail.com>
Reset producers can queue work after teardown has canceled it. The
worker can then access suspended hardware or run after free_netdev().
Close the scheduling gate before draining the work. Reopen it after a
successful start or resume, and disable it permanently on removal and
shutdown. A boolean accommodates repeated stops and failed starts. Skip
self-cancellation on reset failure.
A driver audit with Codex found the race. A modified BCM5718 kernel
delayed watchdog work for three seconds. Close and PCI unbind each
canceled a pending reset. An earlier diagnostic injected -EIO during
reinitialization and exercised the worker's own close. The suspend and
post-free outcomes are inferred.
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: db2199737990 ("tg3: Schedule at most one tg3_reset_task run")
Cc: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
drivers/net/ethernet/broadcom/tg3.c | 70 ++++++++++++++++++++++-------
drivers/net/ethernet/broadcom/tg3.h | 3 ++
2 files changed, 57 insertions(+), 16 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 86ef8e438988..1cd7fc92aa96 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -7237,17 +7237,52 @@ 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))
+ guard(spinlock_irqsave)(&tp->reset_lock);
+ if (tp->reset_enabled &&
+ !test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags))
schedule_delayed_work(&tp->reset_task, 0);
}
-static inline void tg3_reset_task_cancel(struct tg3 *tp)
+static void tg3_reset_task_retry(struct tg3 *tp)
{
- if (test_and_clear_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags))
+ guard(spinlock_irqsave)(&tp->reset_lock);
+ if (tp->reset_enabled)
+ schedule_delayed_work(&tp->reset_task, 1);
+}
+
+static void tg3_reset_task_cancel(struct tg3 *tp)
+{
+ ASSERT_RTNL();
+ scoped_guard(spinlock_irqsave, &tp->reset_lock)
+ tp->reset_enabled = false;
+
+ /* A failed reset closes the device from its own callback. */
+ if (current_work() == &tp->reset_task.work)
+ cancel_delayed_work(&tp->reset_task);
+ else
cancel_delayed_work_sync(&tp->reset_task);
+
+ guard(spinlock_irqsave)(&tp->reset_lock);
+ tg3_flag_clear(tp, RESET_TASK_PENDING);
tg3_flag_clear(tp, TX_RECOVERY_PENDING);
}
+static void tg3_reset_task_enable(struct tg3 *tp)
+{
+ ASSERT_RTNL();
+ guard(spinlock_irqsave)(&tp->reset_lock);
+ if (!tp->reset_stopping)
+ tp->reset_enabled = true;
+}
+
+static void tg3_reset_task_stop(struct tg3 *tp)
+{
+ ASSERT_RTNL();
+ scoped_guard(spinlock_irqsave, &tp->reset_lock)
+ tp->reset_stopping = true;
+ tg3_reset_task_cancel(tp);
+}
+
static int tg3_poll_msix(struct napi_struct *napi, int budget)
{
struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi);
@@ -11267,12 +11302,13 @@ static void tg3_reset_task(struct work_struct *work)
/* Close and suspend can cancel this work while holding RTNL. */
if (!rtnl_trylock()) {
- schedule_delayed_work(&tp->reset_task, 1);
+ tg3_reset_task_retry(tp);
return;
}
tg3_full_lock(tp, 0);
- if (tp->pcierr_recovery || !netif_running(tp->dev) ||
+ if (!tp->reset_enabled || tp->pcierr_recovery ||
+ !netif_running(tp->dev) ||
tp->pdev->error_state != pci_channel_io_normal) {
tg3_flag_clear(tp, RESET_TASK_PENDING);
tg3_full_unlock(tp);
@@ -11302,10 +11338,6 @@ static void tg3_reset_task(struct work_struct *work)
tg3_full_unlock(tp);
tp->irq_sync = 0;
tg3_napi_enable(tp);
- /* Clear this flag so that tg3_reset_task_cancel() will not
- * call cancel_delayed_work_sync() and wait forever.
- */
- tg3_flag_clear(tp, RESET_TASK_PENDING);
netdev_unlock(tp->dev);
dev_close(tp->dev);
goto out;
@@ -11727,6 +11759,8 @@ static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq,
}
}
+ tg3_reset_task_enable(tp);
+
tg3_phy_start(tp);
tg3_hwmon_open(tp);
@@ -17833,6 +17867,7 @@ static int tg3_init_one(struct pci_dev *pdev,
#endif
spin_lock_init(&tp->lock);
spin_lock_init(&tp->indirect_lock);
+ spin_lock_init(&tp->reset_lock);
INIT_DELAYED_WORK(&tp->reset_task, tg3_reset_task);
tp->regs = pci_ioremap_bar(pdev, BAR_0);
@@ -18156,12 +18191,14 @@ static void tg3_remove_one(struct pci_dev *pdev)
if (dev) {
struct tg3 *tp = netdev_priv(dev);
+ rtnl_lock();
+ tg3_reset_task_stop(tp);
+ rtnl_unlock();
+
tg3_ptp_fini(tp);
release_firmware(tp->fw);
- tg3_reset_task_cancel(tp);
-
if (tg3_flag(tp, USE_PHYLIB)) {
tg3_phy_fini(tp);
tg3_mdio_fini(tp);
@@ -18241,6 +18278,8 @@ static int tg3_resume(struct device *device)
if (err)
goto out;
+ tg3_reset_task_enable(tp);
+
tg3_timer_start(tp);
tg3_netif_start(tp);
@@ -18285,9 +18324,8 @@ static void tg3_shutdown(struct pci_dev *pdev)
struct net_device *dev = pci_get_drvdata(pdev);
struct tg3 *tp = netdev_priv(dev);
- tg3_reset_task_cancel(tp);
-
rtnl_lock();
+ tg3_reset_task_stop(tp);
netif_device_detach(dev);
@@ -18336,10 +18374,8 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
netdev_info(netdev, "PCI I/O error detected\n");
- /* Want to make sure that the reset task doesn't run */
- tg3_reset_task_cancel(tp);
-
rtnl_lock();
+ tg3_reset_task_cancel(tp);
/* Could be second call or maybe we don't have netdev yet */
if (!netdev || tp->pcierr_recovery || !netif_running(netdev))
@@ -18462,6 +18498,8 @@ static void tg3_io_resume(struct pci_dev *pdev)
netif_device_attach(netdev);
+ tg3_reset_task_enable(tp);
+
tg3_timer_start(tp);
tg3_netif_start(tp);
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index e5716a969e00..c0f2cbab1b53 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -3373,6 +3373,9 @@ struct tg3 {
struct tg3_hw_stats *hw_stats;
dma_addr_t stats_mapping;
struct delayed_work reset_task;
+ /* Serialize reset publication against gate transitions. */
+ spinlock_t reset_lock;
+ bool reset_enabled, reset_stopping;
struct sk_buff *tx_tstamp_skb;
u64 pre_tx_ts;
--
2.43.0
next prev parent reply other threads:[~2026-12-04 18:57 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 ` [PATCH net 1/6] tg3: defer reset work when RTNL is busy Magnus Lindholm
2026-12-04 18:54 ` Magnus Lindholm [this message]
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-3-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=mcarlson@broadcom.com \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@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