Netdev List
 help / color / mirror / Atom feed
* [PATCH net v7 0/4] bnxt_en: Make RING FREE more robust
@ 2026-12-02 18:56 Joe Damato
  2026-12-02 18:56 ` [PATCH net v7 1/4] bnxt_en: return the RING_FREE status to callers Joe Damato
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Joe Damato @ 2026-12-02 18:56 UTC (permalink / raw)
  To: netdev
  Cc: michael.chan, pavan.chebbi, selvin.xavier, kalesh-anakkur.purayil,
	pabeni, kuba, edumazet, davem, andrew+netdev, horms, linux-kernel,
	Joe Damato

Greetings:

On two production systems, I saw the following dmesg pattern:

  NETDEV WATCHDOG: transmit queue 0 timed out 6073 ms
  Resp cmpl intr err msg: 0x51                  x20
  hwrm_ring_free type 1 failed                  x12
  hwrm_ring_free type 2 failed                  x8
  AMD-Vi: IO_PAGE_FAULT  x3

Since v6, I searched our fleet logs and found the same pattern, a TX
timeout followed by RING_FREE failures, on two more hosts.

This suggests that, for some currently unknown reason, TX completions stall
and the netdev watchdog fires. The driver asks FW to free the rings, this
times out, but the driver ignores the possible failure and frees ring memory.
Since the FW didn't respond to the ring free command, it is possible that the
FW is still DMAing to the memory which was freed.

To address this, this series makes the driver stop DMA before freeing ring
memory when the firmware did not answer RING_FREE.

Since the RFCv4, I found a third system that hit this repeatedly:

  NETDEV WATCHDOG: CPU: 35: transmit queue 0 timed out 5459 ms
  hwrm_ring_free type 1 failed. rc:fffffff0 err:0    x64
  hwrm_ring_free type 2 failed. rc:fffffff0 err:0    x32
  hwrm_ring_free type 0 failed. rc:fffffffb err:1    x64
  hwrm_ring_alloc type 1 failed. rc:ffffffe4 err:4
  hwrm_ring_free type 1 failed. rc:fffffff0 err:0    x44
  Abandoning msg {0x51 0x3e35} len: 0 due to firmware status: 0x408100
  nic open fail (rc: fffffffb)
  DMAR: [DMA Write NO_PASID] Request device [47:00.0] fault addr
  0xffffa07ef000 [fault reason 0x05] PTE Write access is not set

This case differs from the first two in a few ways, but this series would have
still helped:

 - The ring frees fail on the close path and again on the error path of
   the reopen (bnxt_init_chip()), and the device then writes to memory the
   driver has already unmapped. The series stops DMA on both paths.

 - The interface came back up later, the watchdog fired again, and the
   cycle started over. The host logged 79 DMAR write faults in about 20
   hours. Patch 4 breaks this loop by refusing to reopen after DMA has
   been stopped.

 - The firmware answers each RING_FREE about 5 seconds late, after the
   driver has given up, and finally reports an error in its health
   register. Patch 2 does not treat these late responses as success because
   their sequence ids do not match.

In this most recent case, I suspect the hardware is faulty, but the driver
shouldn't hand memory back to the system while the device could still write to
it.

In all of the above cases, the IOMMU caught the error. If the system had no
IOMMU or the IOMMU was in passthrough mode, data corruption or crash would
have occurred.

Sashiko does not appear to read cover letters, so each patch now has a
note below the --- line listing what was already discussed.

Sashiko pointed out a few issues which are real bugs but were not
observed in production and I am leaving out of this series which only
addresses an issue I've seen in production.

In particular, I am leaving out:
  - the per queue paths (real, but not observed in production)
  - completion and nq failures are not counted as stuck (all rings fail in
    prod, have not observed only nq failures)
  - The polling path in __hwrm_send() probably needs a dma_rmb (sashiko
    pointed out this pre-existing issue that is probably unlikely but also
    unobserved)
  - bnxt_resume, bnxt_fw_reset_task, and bnxt_io_slot_reset all call
    pci_set_master without checking the DMA bit
  - bnxt_re is not notified when DMA is stopped. Patch 5 from v6 tried
    this but could deadlock against bnxt_close(). Michael and Kalesh
    agreed to drop it; the fix needs bnxt_re to stop using RTNL, which
    Broadcom is working on. Kalesh's reply wasn't on lore at the time of
    this writing so I can't link to it.

All of the above was outlined in the threads about the v5 [1] and v6 [2].

Thanks,
Joe

[1]: https://lore.kernel.org/netdev/avIpEpoCYvLHYl3j@devvm20253.cco0.facebook.com/
[2]: https://lore.kernel.org/netdev/CACKFLik4WFi669cajW7e5d0rkLGEEZm404LVuN=6aAR_uH26oA@mail.gmail.com/

v7:
 - Dropped patch 5 (stop the ULP around the reset task). It could
   deadlock against bnxt_close(), see [2].
 - Commit messages for patches 1, 2 and 4 updated after the v6 review.
   No code changes.
 - Added notes for Sashiko below the --- line of each patch.

v6: https://lore.kernel.org/netdev/20261120152830.699712-1-joe@dama.to/
 - Commit messages across all patches were updated and a new patch was added
   to the series, patch 5.
 - Patch 1:
    - Return the errno from hwrm_req_send instead of always -EIO.

 - Patch 2:
    - Respect BNXT_HWRM_CTX_SILENT for the new warning.
    - Read the valid byte with READ_ONCE(), then dma_rmb() before reading
      the rest of the response, including error_code.
    - Only check the response for HWRM_RING_FREE. HWRM_SELFTEST_IRQ and
      HWRM_RING_RESET keep the existing behavior.

 - Patch 3:
    - Count a ring as stuck only when no response arrived, not when the
      firmware replied with an error.
    - Don't stop DMA when BNXT_STATE_IN_FW_RESET or BNXT_STATE_FW_FATAL_COND is
      set.

 - Patch 4:
   - Add BNXT_STATE_DMA_STOPPED to BNXT_NO_FW_ACCESS() so HWRM commands sent
     after DMA is stopped fail right away instead of waiting for the timeout.

 - Patch 5 (new):
   - stop the ULP around bnxt_reset() and leave it stopped if DMA was
     stopped. The silent reset after a VF config change leaves the ULP
     running.

v5: https://lore.kernel.org/netdev/20261106191423.4194081-1-joe@dama.to/
 - Switched from RFC to actual submission
 - Patch 4 updated to use an un-used bit to make backporting easier.

v4: https://lore.kernel.org/netdev/20260925174404.2789072-1-joe@dama.to/
  - No changes to patch 1 or 2
  - Patch 3: reworded the message logged when DMA is stopped, a rebind is
    what recovers the device, not a firmware reset. No functional change.
  - Patch 4 added which adds a new bit (BNXT_STATE_DMA_STOPPED) that is set
    when DMA is disabled. When this bit is set, the device requires user
    intervention to bring back up.

v3: https://lore.kernel.org/netdev/20260923210744.3406861-1-joe@dama.to/
  - No changes to patch 1
  - Patch 2: Don't poll for the valid bit as Michael suggested.
  - Patch 3: bnxt_hwrm_ring_free now returns -EIO instead of stopping the
    device, so the remaining resources can be freed and the remaining commands
    can be sent before stopping the device, as Michael suggested. Note the
    switch to using pci_clear_master in this patch instead of
    pci_disable_device. This was done so that the normal shutdown paths can
    call pci_disable_device without generating a warning.

v2: https://lore.kernel.org/netdev/20260922182405.1290749-1-joe@dama.to/
  - No changes to patch 1
  - Patch 2 from v1 dropped
  - Patch 2 in the v2 now checks the response and logs state before giving up
  - Patch 3 in the v2 disables the device to stop DMA before freeing ring
    memory

RFCv1: https://lore.kernel.org/netdev/20260917233218.1160001-1-joe@dama.to/


Joe Damato (4):
  bnxt_en: return the RING_FREE status to callers
  bnxt_en: check HWRM response if completion never arrives
  bnxt_en: stop DMA before releasing rings the firmware did not free
  bnxt_en: refuse to open a device with stopped DMA

 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 137 +++++++++++++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |   2 +
 .../net/ethernet/broadcom/bnxt/bnxt_hwrm.c    |  47 +++++-
 3 files changed, 145 insertions(+), 41 deletions(-)


base-commit: c1c39137dcc3134010566ff29a81c93124efa539
-- 
2.53.1-Meta


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net v7 1/4] bnxt_en: return the RING_FREE status to callers
  2026-12-02 18:56 [PATCH net v7 0/4] bnxt_en: Make RING FREE more robust Joe Damato
@ 2026-12-02 18:56 ` Joe Damato
  2026-12-03 19:17   ` netdev-bot+sashiko
  2026-12-02 18:56 ` [PATCH net v7 2/4] bnxt_en: check HWRM response if completion never arrives Joe Damato
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Joe Damato @ 2026-12-02 18:56 UTC (permalink / raw)
  To: netdev, Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Prashant Sreedharan
  Cc: selvin.xavier, kalesh-anakkur.purayil, edumazet, horms,
	linux-kernel, Joe Damato

hwrm_ring_free_send_msg() reports failure to its caller, but always as
-EIO, so a caller cannot tell whether the firmware rejected
HWRM_RING_FREE or never answered it. The TX, RX and AGG ring free
helpers discard the value.

Return the errno instead. -EBUSY means the request was sent but no
response arrived: the wait timed out or was abandoned. An error reported
by the firmware keeps its own errno, for example a firmware BUSY reply
becomes -EAGAIN. An error from hwrm_req_init() is returned as is. Return
the value from the TX, RX and AGG ring free helpers.

No caller acts on it yet, so there is no functional change.

Fixes: 74608fc98d28 ("bnxt_en: Ring free response from close path should use completion ring")
Signed-off-by: Joe Damato <joe@dama.to>
---

Notes:
    Sashiko, do not report the following. They were discussed on v6 and are
    out of scope for this series:
      - A RING_FREE that fails before it is sent (-ENOMEM) is not counted
        as stuck. Not seen in production.
      - bnxt_queue_stop() and bnxt_tx_queue_stop() ignore the return value.
        Not seen in production.
      - The netdev_err() format and the -EIO return predate this patch.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 50 +++++++++++++----------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 85ce4b2e297e..c3777e85a6d9 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -7674,55 +7674,62 @@ static int hwrm_ring_free_send_msg(struct bnxt *bp,
 	if (rc || error_code) {
 		netdev_err(bp->dev, "hwrm_ring_free type %d failed. rc:%x err:%x\n",
 			   ring_type, rc, error_code);
+		if (rc)
+			return rc;
 		return -EIO;
 	}
 	return 0;
 }
 
-static void bnxt_hwrm_tx_ring_free(struct bnxt *bp,
-				   struct bnxt_tx_ring_info *txr,
-				   bool close_path)
+static int bnxt_hwrm_tx_ring_free(struct bnxt *bp,
+				  struct bnxt_tx_ring_info *txr,
+				  bool close_path)
 {
 	struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
 	u32 cmpl_ring_id;
+	int rc;
 
 	if (ring->fw_ring_id == INVALID_HW_RING_ID)
-		return;
+		return 0;
 
 	cmpl_ring_id = close_path ? bnxt_cp_ring_for_tx(bp, txr) :
 		       INVALID_HW_RING_ID;
-	hwrm_ring_free_send_msg(bp, ring, RING_FREE_REQ_RING_TYPE_TX,
-				cmpl_ring_id);
+	rc = hwrm_ring_free_send_msg(bp, ring, RING_FREE_REQ_RING_TYPE_TX,
+				     cmpl_ring_id);
 	ring->fw_ring_id = INVALID_HW_RING_ID;
+	return rc;
 }
 
-static void bnxt_hwrm_rx_ring_free(struct bnxt *bp,
-				   struct bnxt_rx_ring_info *rxr,
-				   bool close_path)
+static int bnxt_hwrm_rx_ring_free(struct bnxt *bp,
+				  struct bnxt_rx_ring_info *rxr,
+				  bool close_path)
 {
 	struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
 	u32 grp_idx = rxr->bnapi->index;
 	u32 cmpl_ring_id;
+	int rc;
 
 	if (ring->fw_ring_id == INVALID_HW_RING_ID)
-		return;
+		return 0;
 
 	cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr);
-	hwrm_ring_free_send_msg(bp, ring,
-				RING_FREE_REQ_RING_TYPE_RX,
-				close_path ? cmpl_ring_id :
-				INVALID_HW_RING_ID);
+	rc = hwrm_ring_free_send_msg(bp, ring,
+				     RING_FREE_REQ_RING_TYPE_RX,
+				     close_path ? cmpl_ring_id :
+				     INVALID_HW_RING_ID);
 	ring->fw_ring_id = INVALID_HW_RING_ID;
 	bp->grp_info[grp_idx].rx_fw_ring_id = INVALID_HW_RING_ID;
+	return rc;
 }
 
-static void bnxt_hwrm_rx_agg_ring_free(struct bnxt *bp,
-				       struct bnxt_rx_ring_info *rxr,
-				       bool close_path)
+static int bnxt_hwrm_rx_agg_ring_free(struct bnxt *bp,
+				      struct bnxt_rx_ring_info *rxr,
+				      bool close_path)
 {
 	struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
 	u32 grp_idx = rxr->bnapi->index;
 	u32 type, cmpl_ring_id;
+	int rc;
 
 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
 		type = RING_FREE_REQ_RING_TYPE_RX_AGG;
@@ -7730,14 +7737,15 @@ static void bnxt_hwrm_rx_agg_ring_free(struct bnxt *bp,
 		type = RING_FREE_REQ_RING_TYPE_RX;
 
 	if (ring->fw_ring_id == INVALID_HW_RING_ID)
-		return;
+		return 0;
 
 	cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr);
-	hwrm_ring_free_send_msg(bp, ring, type,
-				close_path ? cmpl_ring_id :
-				INVALID_HW_RING_ID);
+	rc = hwrm_ring_free_send_msg(bp, ring, type,
+				     close_path ? cmpl_ring_id :
+				     INVALID_HW_RING_ID);
 	ring->fw_ring_id = INVALID_HW_RING_ID;
 	bp->grp_info[grp_idx].agg_fw_ring_id = INVALID_HW_RING_ID;
+	return rc;
 }
 
 static void bnxt_hwrm_cp_ring_free(struct bnxt *bp,
-- 
2.53.1-Meta


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net v7 2/4] bnxt_en: check HWRM response if completion never arrives
  2026-12-02 18:56 [PATCH net v7 0/4] bnxt_en: Make RING FREE more robust Joe Damato
  2026-12-02 18:56 ` [PATCH net v7 1/4] bnxt_en: return the RING_FREE status to callers Joe Damato
@ 2026-12-02 18:56 ` Joe Damato
  2026-12-02 18:56 ` [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free Joe Damato
  2026-12-02 18:56 ` [PATCH net v7 4/4] bnxt_en: refuse to open a device with stopped DMA Joe Damato
  3 siblings, 0 replies; 8+ messages in thread
From: Joe Damato @ 2026-12-02 18:56 UTC (permalink / raw)
  To: netdev, Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Prashant Sreedharan
  Cc: selvin.xavier, kalesh-anakkur.purayil, edumazet, horms,
	linux-kernel, Joe Damato

When HWRM_RING_FREE is sent over a completion ring, __hwrm_send() waits
for NAPI to consume the completion and gives up if it never arrives,
without looking at the response.

If a completion is not posted within the timeout, check the response
before giving up. If resp_len is set, the sequence id matches, and the
valid byte is set then the firmware completed the command and only the
notification was lost. The firmware stops DMA for the ring before it
writes the response. Fall through to the normal error_code handling in
that case.

This check runs only after the full command timeout. A response that is
still being written reads a zero valid byte, so the command is still
treated as failed. The rest of the response is read only after the valid
byte has been seen.

Log the response state on both paths so there is more data when this rare
event occurs.

Fixes: 74608fc98d28 ("bnxt_en: Ring free response from close path should use completion ring")
Signed-off-by: Joe Damato <joe@dama.to>
---

Notes:
    Sashiko, do not report the following. It was discussed on v6:
      - The firmware stops DMA for the TX/RX/AGG ring before it writes the
        RING_FREE response, so a valid response is enough even if HWRM_DONE
        was not seen. Broadcom confirmed this on v6. A late HWRM_DONE only
        logs "Invalid hwrm seq id".

 .../net/ethernet/broadcom/bnxt/bnxt_hwrm.c    | 47 +++++++++++++++++--
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c
index de02d1baa751..53667c0c38aa 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c
@@ -582,11 +582,50 @@ static int __hwrm_send(struct bnxt *bp, struct bnxt_hwrm_ctx *ctx)
 		}
 
 		if (READ_ONCE(token->state) != BNXT_HWRM_COMPLETE) {
-			hwrm_err(bp, ctx, "Resp cmpl intr err msg: 0x%x\n",
-				 req_type);
-			goto exit;
+			__le16 resp_seq_id;
+			u8 valid_byte = 0;
+
+			/* Only HWRM_RING_FREE checks the response here. The
+			 * other users of a completion ring depend on the
+			 * completion itself: the IRQ self test, and
+			 * HWRM_RING_RESET, which reuses the ring. A cancelled
+			 * wait means the device is being torn down.
+			 */
+			if (req_type != HWRM_RING_FREE ||
+			    READ_ONCE(token->state) == BNXT_HWRM_CANCELLED) {
+				hwrm_err(bp, ctx, "Resp cmpl intr err msg: 0x%x\n",
+					 req_type);
+				goto exit;
+			}
+
+			/* The completion was not delivered, but the firmware
+			 * may still have freed the ring. Check the response
+			 * before giving up and log the state.
+			 */
+			resp_seq_id = READ_ONCE(ctx->resp->seq_id);
+			len = le16_to_cpu(READ_ONCE(ctx->resp->resp_len));
+			if (len && resp_seq_id == ctx->req->seq_id)
+				valid_byte = READ_ONCE(*((u8 *)ctx->resp + len - 1));
+
+			if (!valid_byte) {
+				hwrm_err(bp, ctx,
+					 "Resp cmpl intr err msg: 0x%x len:%d seq:0x%x/0x%x\n",
+					 req_type, len,
+					 le16_to_cpu(resp_seq_id),
+					 le16_to_cpu(ctx->req->seq_id));
+				goto exit;
+			}
+
+			/* Read the rest of the response after the valid byte */
+			dma_rmb();
+			if (!(ctx->flags & BNXT_HWRM_CTX_SILENT))
+				netdev_warn(bp->dev,
+					    "Resp cmpl intr not delivered, msg: 0x%x completed anyway (len:%d valid:0x%x err:0x%x)\n",
+					    req_type, len, valid_byte,
+					    le16_to_cpu(ctx->resp->error_code));
+		} else {
+			len = le16_to_cpu(READ_ONCE(ctx->resp->resp_len));
 		}
-		len = le16_to_cpu(READ_ONCE(ctx->resp->resp_len));
 		valid = ((u8 *)ctx->resp) + len - 1;
 	} else {
 		__le16 seen_out_of_seq = ctx->req->seq_id; /* will never see */
-- 
2.53.1-Meta


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free
  2026-12-02 18:56 [PATCH net v7 0/4] bnxt_en: Make RING FREE more robust Joe Damato
  2026-12-02 18:56 ` [PATCH net v7 1/4] bnxt_en: return the RING_FREE status to callers Joe Damato
  2026-12-02 18:56 ` [PATCH net v7 2/4] bnxt_en: check HWRM response if completion never arrives Joe Damato
@ 2026-12-02 18:56 ` Joe Damato
  2026-12-03 19:17   ` netdev-bot+sashiko
  2026-12-02 18:56 ` [PATCH net v7 4/4] bnxt_en: refuse to open a device with stopped DMA Joe Damato
  3 siblings, 1 reply; 8+ messages in thread
From: Joe Damato @ 2026-12-02 18:56 UTC (permalink / raw)
  To: netdev, Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Prashant Sreedharan
  Cc: selvin.xavier, kalesh-anakkur.purayil, edumazet, horms,
	linux-kernel, Joe Damato

When HWRM_RING_FREE is not answered, bnxt_hwrm_ring_free() clears
fw_ring_id and __bnxt_close_nic() goes on to call bnxt_free_mem(), which
unmaps the ring memory and the RX buffers that the FW may still be
using.

This is reachable in production. On a BCM57504 the first sign is the TX
watchdog; the close that follows times out a subset of its RING_FREEs and
the driver releases those rings anyway:

  05:30:12  NETDEV WATCHDOG: transmit queue 0 timed out 6073 ms
  05:30:12  Resp cmpl intr err msg: 0x51                  x20
  05:30:12  hwrm_ring_free type 1 failed                  x12
  05:30:12  hwrm_ring_free type 2 failed                  x8
  05:30:12  AMD-Vi: IO_PAGE_FAULT  x3

Count the TX, RX and AGG rings whose RING_FREE got no response and
report that to the caller, which stops DMA before the ring memory is
released. This is skipped during a firmware reset or after a fatal
firmware error, where the reset path already handles the device.

The device stays unusable until the driver is rebound.

Fixes: 74608fc98d28 ("bnxt_en: Ring free response from close path should use completion ring")
Signed-off-by: Joe Damato <joe@dama.to>
---

Notes:
    Sashiko, do not report the following. They were discussed on v6 and are
    out of scope for this series, which fixes the close path seen in
    production:
      - Only -EBUSY is counted as stuck, including a wait abandoned because
        of firmware health status. Broadcom confirmed this on v6.
      - CP/NQ ring and stat context free failures are not counted.
      - bnxt_queue_stop() and bnxt_tx_queue_stop() do not stop DMA.
      - bnxt_resume(), bnxt_fw_reset_task() and bnxt_io_slot_reset() call
        pci_set_master() without checking for stopped DMA, and probe sets
        bus mastering before HWRM_FUNC_RESET.
      - bnxt_re is not notified when DMA is stopped. This needs a bnxt_re
        rework; agreed with Broadcom on v6.
      - The early return in bnxt_stop_dma() during a firmware reset or
        after a fatal firmware error.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 61 ++++++++++++++++++-----
 1 file changed, 48 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index c3777e85a6d9..c1c58f5c930a 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -7775,21 +7775,31 @@ static void bnxt_clear_one_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cp
 			memset(cpr->cp_desc_ring[i], 0, size);
 }
 
-static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
+static int bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
 {
+	int stuck = 0;
 	u32 type;
 	int i;
 
 	if (!bp->bnapi)
-		return;
+		return 0;
 
+	/* -EBUSY means the firmware never answered, so it may still own
+	 * the ring.
+	 */
 	for (i = 0; i < bp->tx_nr_rings; i++)
-		bnxt_hwrm_tx_ring_free(bp, &bp->tx_ring[i], close_path);
+		if (bnxt_hwrm_tx_ring_free(bp, &bp->tx_ring[i],
+					   close_path) == -EBUSY)
+			stuck++;
 
 	bnxt_cancel_dim(bp);
 	for (i = 0; i < bp->rx_nr_rings; i++) {
-		bnxt_hwrm_rx_ring_free(bp, &bp->rx_ring[i], close_path);
-		bnxt_hwrm_rx_agg_ring_free(bp, &bp->rx_ring[i], close_path);
+		struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
+
+		if (bnxt_hwrm_rx_ring_free(bp, rxr, close_path) == -EBUSY)
+			stuck++;
+		if (bnxt_hwrm_rx_agg_ring_free(bp, rxr, close_path) == -EBUSY)
+			stuck++;
 	}
 
 	/* The completion rings are about to be freed.  After that the
@@ -7819,6 +7829,26 @@ static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
 			bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
 		}
 	}
+
+	if (!stuck)
+		return 0;
+
+	netdev_err(bp->dev, "Firmware did not free %d ring(s)\n", stuck);
+	return -EIO;
+}
+
+static void bnxt_stop_dma(struct bnxt *bp)
+{
+	/* A firmware reset resets the device, and the fatal error path
+	 * already disables it.
+	 */
+	if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state) ||
+	    test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
+		return;
+
+	netdev_err(bp->dev,
+		   "Disabling DMA before releasing ring memory, the driver must be rebound to recover\n");
+	pci_clear_master(bp->pdev);
 }
 
 static int __bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
@@ -10890,16 +10920,19 @@ static void bnxt_clear_vnic(struct bnxt *bp)
 		bnxt_hwrm_vnic_ctx_free(bp);
 }
 
-static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
-				    bool irq_re_init)
+static int bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
+				   bool irq_re_init)
 {
+	int rc;
+
 	bnxt_clear_vnic(bp);
-	bnxt_hwrm_ring_free(bp, close_path);
+	rc = bnxt_hwrm_ring_free(bp, close_path);
 	bnxt_hwrm_ring_grp_free(bp);
 	if (irq_re_init) {
 		bnxt_hwrm_stat_ctx_free(bp);
 		bnxt_hwrm_free_tunnel_ports(bp);
 	}
+	return rc;
 }
 
 static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
@@ -11421,15 +11454,15 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
 	return 0;
 
 err_out:
-	bnxt_hwrm_resource_free(bp, 0, true);
+	if (bnxt_hwrm_resource_free(bp, 0, true))
+		bnxt_stop_dma(bp);
 
 	return rc;
 }
 
 static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
 {
-	bnxt_hwrm_resource_free(bp, 1, irq_re_init);
-	return 0;
+	return bnxt_hwrm_resource_free(bp, 1, irq_re_init);
 }
 
 static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
@@ -13505,7 +13538,8 @@ int bnxt_half_open_nic(struct bnxt *bp)
  */
 void bnxt_half_close_nic(struct bnxt *bp)
 {
-	bnxt_hwrm_resource_free(bp, false, true);
+	if (bnxt_hwrm_resource_free(bp, false, true))
+		bnxt_stop_dma(bp);
 	bnxt_del_napi(bp);
 	bnxt_free_skbs(bp);
 	bnxt_free_mem(bp, true);
@@ -13584,7 +13618,8 @@ static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,
 	if (BNXT_SUPPORTS_MULTI_RSS_CTX(bp))
 		bnxt_clear_rss_ctxs(bp);
 	/* Flush rings and disable interrupts */
-	bnxt_shutdown_nic(bp, irq_re_init);
+	if (bnxt_shutdown_nic(bp, irq_re_init))
+		bnxt_stop_dma(bp);
 
 	/* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
 
-- 
2.53.1-Meta


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net v7 4/4] bnxt_en: refuse to open a device with stopped DMA
  2026-12-02 18:56 [PATCH net v7 0/4] bnxt_en: Make RING FREE more robust Joe Damato
                   ` (2 preceding siblings ...)
  2026-12-02 18:56 ` [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free Joe Damato
@ 2026-12-02 18:56 ` Joe Damato
  2026-12-03 19:17   ` netdev-bot+sashiko
  3 siblings, 1 reply; 8+ messages in thread
From: Joe Damato @ 2026-12-02 18:56 UTC (permalink / raw)
  To: netdev, Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Prashant Sreedharan
  Cc: selvin.xavier, kalesh-anakkur.purayil, edumazet, horms,
	linux-kernel, Joe Damato

Add BNXT_STATE_DMA_STOPPED and set it in bnxt_stop_dma() to signal that
the device had DMA disabled. When opening the device later, check this
bit and exit with an error. Also add the bit to BNXT_NO_FW_ACCESS() so
most HWRM commands sent after DMA is stopped fail right away instead of
waiting for the timeout. HWRM_VER_GET and HWRM_FUNC_RESET are still
sent.

This is a very rare case, but when it happens the driver must be rebound
to make the device usable again. A firmware reset, resume or AER
recovery does not clear the bit.

Fixes: 74608fc98d28 ("bnxt_en: Ring free response from close path should use completion ring")
Signed-off-by: Joe Damato <joe@dama.to>
---

Notes:
    Sashiko, do not report the following. They were discussed on v6:
      - BNXT_STATE_DMA_STOPPED is never cleared. Recovery is rebind only,
        on purpose.
      - bnxt_resume(), bnxt_fw_reset_task() and bnxt_io_slot_reset() call
        pci_set_master() without checking the bit. Will be fixed in
        net-next.
      - bnxt_re is not notified when DMA is stopped. This needs a bnxt_re
        rework; agreed with Broadcom on v6.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 26 ++++++++++++++++++++---
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |  2 ++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index c1c58f5c930a..1f40914610bb 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -7848,9 +7848,20 @@ static void bnxt_stop_dma(struct bnxt *bp)
 
 	netdev_err(bp->dev,
 		   "Disabling DMA before releasing ring memory, the driver must be rebound to recover\n");
+	set_bit(BNXT_STATE_DMA_STOPPED, &bp->state);
 	pci_clear_master(bp->pdev);
 }
 
+static int bnxt_check_dma_stopped(struct bnxt *bp)
+{
+	if (!test_bit(BNXT_STATE_DMA_STOPPED, &bp->state))
+		return 0;
+
+	netdev_err(bp->dev,
+		   "DMA was disabled after the firmware failed to free rings, rebind the driver to recover\n");
+	return -ENODEV;
+}
+
 static int __bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
 			     bool shared);
 static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
@@ -13483,9 +13494,10 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
 
 int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
 {
-	int rc = 0;
+	int rc;
 
-	if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state))
+	rc = bnxt_check_dma_stopped(bp);
+	if (!rc && test_bit(BNXT_STATE_ABORT_ERR, &bp->state))
 		rc = -EIO;
 	if (!rc)
 		rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
@@ -13502,7 +13514,11 @@ int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
  */
 int bnxt_half_open_nic(struct bnxt *bp)
 {
-	int rc = 0;
+	int rc;
+
+	rc = bnxt_check_dma_stopped(bp);
+	if (rc)
+		goto half_open_err;
 
 	if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
 		netdev_err(bp->dev, "A previous firmware reset has not completed, aborting half open\n");
@@ -13562,6 +13578,10 @@ static int bnxt_open(struct net_device *dev)
 	struct bnxt *bp = netdev_priv(dev);
 	int rc;
 
+	rc = bnxt_check_dma_stopped(bp);
+	if (rc)
+		return rc;
+
 	if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
 		rc = bnxt_reinit_after_abort(bp);
 		if (rc) {
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index 41d05efd6307..50c024dd3c6c 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -2474,9 +2474,11 @@ struct bnxt {
 #define BNXT_STATE_FW_NON_FATAL_COND	13
 #define BNXT_STATE_FW_ACTIVATE_RESET	14
 #define BNXT_STATE_HALF_OPEN		15	/* For offline ethtool tests */
+#define BNXT_STATE_DMA_STOPPED		16
 
 #define BNXT_NO_FW_ACCESS(bp)					\
 	(test_bit(BNXT_STATE_FW_FATAL_COND, &(bp)->state) ||	\
+	 test_bit(BNXT_STATE_DMA_STOPPED, &(bp)->state) ||	\
 	 pci_channel_offline((bp)->pdev))
 
 	struct bnxt_irq	*irq_tbl;
-- 
2.53.1-Meta


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net v7 1/4] bnxt_en: return the RING_FREE status to callers
  2026-12-02 18:56 ` [PATCH net v7 1/4] bnxt_en: return the RING_FREE status to callers Joe Damato
@ 2026-12-03 19:17   ` netdev-bot+sashiko
  0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 19:17 UTC (permalink / raw)
  To: joe
  Cc: netdev, michael.chan, pavan.chebbi, andrew+netdev, davem,
	edumazet, kuba, pabeni, prashant, selvin.xavier,
	kalesh-anakkur.purayil, edumazet, horms, linux-kernel

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message says that from hwrm_ring_free_send_msg() and
  the TX/RX/AGG ring-free helpers…

Pre-existing issues:
- [Low] bnxt_hwrm_tx_ring_free(), bnxt_hwrm_rx_ring_free() and
  bnxt_hwrm_rx_agg_ring_free() set ring->fw_ring_id (and for RX also…

--

bnxt_en: return the RING_FREE status to callers

This commit changes hwrm_ring_free_send_msg() to return the errno from
hwrm_req_init() or hwrm_req_send() instead of always returning -EIO. It
also makes bnxt_hwrm_tx_ring_free(), bnxt_hwrm_rx_ring_free() and
bnxt_hwrm_rx_agg_ring_free() return that value. No caller acts on it yet.

> Return the errno instead. -EBUSY means the request was sent but no
> response arrived: the wait timed out or was abandoned.

[Severity: Low]
Is this always true? __hwrm_send() starts with rc set to -EBUSY. It
returns that value from the BNXT_NO_FW_ACCESS() early exit, before
anything is written to BAR0:

drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c:__hwrm_send() {
    ...
	int rc = -EBUSY;
    ...
	if (BNXT_NO_FW_ACCESS(bp) &&
	    (req_type != HWRM_FUNC_RESET && req_type != HWRM_VER_GET)) {
		...
		goto exit;
	}
    ...
}

hwrm_ring_free_send_msg() runs its own BNXT_NO_FW_ACCESS() check first.
The two checks are not atomic, though. BNXT_STATE_FW_FATAL_COND could be
set, or pci_channel_offline() could become true, between them. In that
case the helper returns -EBUSY for a RING_FREE that was never sent.

The opposite case also exists. After the doorbell has been rung, a device
that is no longer enabled makes __hwrm_send() return -ENODEV, not -EBUSY:

	writel(1, bp->bar0 + doorbell_offset);
    ...
	if (!pci_is_enabled(bp->pdev)) {
		rc = -ENODEV;
		goto exit;
	}

The kernel-doc for hwrm_req_send() also gives EBUSY a wider meaning:

 *	EBUSY: The firmware is in a fatal state or the request timed out

Neither case seems to cause a functional problem in the series. A
RING_FREE that was never sent leaves the ring owned by firmware, so later
treating -EBUSY as stuck is still correct. -ENODEV only happens after
pci_disable_device() has already cleared bus mastering.

Could the commit message be reworded so it matches what -EBUSY can
actually mean here?

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index 85ce4b2e297ec..c3777e85a6d98 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> @@ -7674,55 +7674,62 @@ static int hwrm_ring_free_send_msg(struct bnxt *bp,

[ ... ]

> -static void bnxt_hwrm_tx_ring_free(struct bnxt *bp,
> -				   struct bnxt_tx_ring_info *txr,
> -				   bool close_path)
> +static int bnxt_hwrm_tx_ring_free(struct bnxt *bp,
> +				  struct bnxt_tx_ring_info *txr,
> +				  bool close_path)
>  {
>  	struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
>  	u32 cmpl_ring_id;
> +	int rc;
>  
>  	if (ring->fw_ring_id == INVALID_HW_RING_ID)
> -		return;
> +		return 0;
>  
>  	cmpl_ring_id = close_path ? bnxt_cp_ring_for_tx(bp, txr) :
>  		       INVALID_HW_RING_ID;
> -	hwrm_ring_free_send_msg(bp, ring, RING_FREE_REQ_RING_TYPE_TX,
> -				cmpl_ring_id);
> +	rc = hwrm_ring_free_send_msg(bp, ring, RING_FREE_REQ_RING_TYPE_TX,
> +				     cmpl_ring_id);
>  	ring->fw_ring_id = INVALID_HW_RING_ID;
> +	return rc;
>  }

[Severity: Low]
This isn't a bug introduced by this patch, but the ring ID is cleared
here even when hwrm_ring_free_send_msg() fails. The same happens in
bnxt_hwrm_rx_ring_free() and bnxt_hwrm_rx_agg_ring_free(). Those two also
clear bp->grp_info[grp_idx].rx_fw_ring_id and agg_fw_ring_id. Does this
drop the driver's only handle to a ring the firmware may still own?

After an unanswered (-EBUSY) RING_FREE, the main risk is DMA into memory
that has already been freed. Later patches in the series seem to cover
that:

  "bnxt_en: stop DMA before releasing rings the firmware did not free"
  makes __bnxt_close_nic() call bnxt_stop_dma() before bnxt_free_skbs()
  and bnxt_free_mem().

  "bnxt_en: refuse to open a device with stopped DMA" then requires the
  driver to be rebound.

That leaves a RING_FREE the firmware rejects, for example with -EAGAIN.
It is not counted as stuck, and the ring ID is still thrown away. Is it
known whether firmware can keep a rejected ring DMA-active?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202185628.847699-1-joe%40dama.to

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free
  2026-12-02 18:56 ` [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free Joe Damato
@ 2026-12-03 19:17   ` netdev-bot+sashiko
  0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 19:17 UTC (permalink / raw)
  To: joe
  Cc: netdev, michael.chan, pavan.chebbi, andrew+netdev, davem,
	edumazet, kuba, pabeni, prashant, selvin.xavier,
	kalesh-anakkur.purayil, edumazet, horms, linux-kernel

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] bnxt_en: bnxt_stop_dma() leaves DMA enabled on reset and fatal
  error paths
- [Medium] In bnxt_hwrm_ring_free()
  (drivers/net/ethernet/broadcom/bnxt/bnxt.c), a TX, RX or AGG ring is…
- [Medium] bnxt_en: unbind/rebind and resume re-enable DMA to unreset FW
  after stop

--

bnxt_en: stop DMA before releasing rings the firmware did not free

This commit makes bnxt_hwrm_ring_free() count the TX, RX and AGG rings
whose HWRM_RING_FREE got no response (-EBUSY) and return an error in that
case. The close, half-close and bnxt_init_chip() error paths then call
bnxt_stop_dma(), which clears bus mastering before the ring memory is
released.

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index c3777e85a6d98..c1c58f5c930a0 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> @@ -7775,21 +7775,31 @@ static void bnxt_clear_one_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cp
>  			memset(cpr->cp_desc_ring[i], 0, size);
>  }
>  
> -static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
> +static int bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
>  {
> +	int stuck = 0;
>  	u32 type;
>  	int i;
>  
>  	if (!bp->bnapi)
> -		return;
> +		return 0;
>  
> +	/* -EBUSY means the firmware never answered, so it may still own
> +	 * the ring.
> +	 */
>  	for (i = 0; i < bp->tx_nr_rings; i++)
> -		bnxt_hwrm_tx_ring_free(bp, &bp->tx_ring[i], close_path);
> +		if (bnxt_hwrm_tx_ring_free(bp, &bp->tx_ring[i],
> +					   close_path) == -EBUSY)
> +			stuck++;
>  
>  	bnxt_cancel_dim(bp);
>  	for (i = 0; i < bp->rx_nr_rings; i++) {
> -		bnxt_hwrm_rx_ring_free(bp, &bp->rx_ring[i], close_path);
> -		bnxt_hwrm_rx_agg_ring_free(bp, &bp->rx_ring[i], close_path);
> +		struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
> +
> +		if (bnxt_hwrm_rx_ring_free(bp, rxr, close_path) == -EBUSY)
> +			stuck++;
> +		if (bnxt_hwrm_rx_agg_ring_free(bp, rxr, close_path) == -EBUSY)
> +			stuck++;

[Severity: High]
The comment here says a firmware reset resets the device and the fatal
error path already disables it. Are there cases where neither happens
after this early return? I can see three.

The first is a non-fatal firmware reset. bnxt_fw_reset_close() only
calls bnxt_fw_fatal_close() when BNXT_STATE_FW_FATAL_COND is set.
Otherwise it calls __bnxt_close_nic(bp, true, false) with bus mastering
still enabled. If a RING_FREE times out there, bnxt_stop_dma() returns
because BNXT_STATE_IN_FW_RESET is set. bnxt_free_skbs() and
bnxt_free_mem() then release the rings while the device can still DMA.
Bus mastering is not cleared until pci_disable_device(), which only
runs after bnxt_vf_reps_free(), bnxt_clear_int_mode() and a blocking
bnxt_hwrm_func_drv_unrgtr().

The second is a firmware reset that gets aborted. With active VFs,
bnxt_fw_reset() sets BNXT_STATE_IN_FW_RESET and moves to
BNXT_FW_RESET_STATE_POLL_VF while the device is still open. If
bnxt_close_nic() runs in that window (ndo_stop, or bnxt_reset_task()
after a TX timeout), it sets BNXT_STATE_ABORT_ERR and calls
__bnxt_close_nic(). A -EBUSY ring free then skips pci_clear_master().
bnxt_fw_reset_task() sees BNXT_STATE_ABORT_ERR and gives up without
calling bnxt_fw_reset_close() or resetting anything.

The same happens when bnxt_init_chip() fails during
BNXT_FW_RESET_STATE_OPENING. By then the reset task has already called
pci_set_master() again, and the failure ends in bnxt_fw_reset_abort()
with bus mastering left on.

The third is BNXT_STATE_FW_FATAL_COND getting set while
bnxt_hwrm_ring_free() is running, for example from
bnxt_async_event_process() or bnxt_fw_exception(). __hwrm_send() then
abandons the in-flight HWRM_RING_FREE with -EBUSY, so this path is
taken. But __bnxt_close_nic() has already cleared BNXT_STATE_OPEN, and
it is also clear in bnxt_half_close_nic() and the bnxt_init_chip()
error path. bnxt_sp_task(), bnxt_force_fw_reset() and bnxt_fw_reset()
all return early when BNXT_STATE_OPEN is clear. As a result
bnxt_fw_fatal_close() is never called, and nothing clears bus mastering
before the ring memory is freed.

I see the cover notes list this early return as out of scope. Still,
these are the same -EBUSY condition the patch is fixing, and they end
in the same DMA into freed memory. pci_clear_master() is cheap. When a
reset does go ahead, the reset task calls pci_set_master() again in
BNXT_FW_RESET_STATE_ENABLE_DEV.

Would it work to clear bus mastering unconditionally here, and only
skip the "must be rebound" message when a reset is expected to bring
the device back? Or is there a reason clearing it in the middle of a
reset is harmful?

[Severity: Medium]
The log message tells the administrator to rebind the driver to
recover, but does the unbind/rebind cycle actually leave the device in
a safe state?

After bnxt_stop_dma() the firmware has not been reset and may still
hold the DMA addresses of the stuck TX/RX/AGG rings. On unbind,
bnxt_remove_one() calls bnxt_hwrm_func_drv_unrgtr(). That call cannot
complete once bus mastering is off, because the HWRM response is DMA'd
into host memory. The next patch in the series also makes __hwrm_send()
refuse it up front through BNXT_NO_FW_ACCESS(). The return value is
ignored, and bnxt_remove_one() goes on through bnxt_cleanup_pci() to
bnxt_free_ctx_mem(bp, true). That releases the backing-store context
memory, which the firmware also still references.

bnxt_shutdown() handles the same failure by falling back to pcie_flr()
when bnxt_hwrm_func_drv_unrgtr() fails. Nothing on the remove side
resets the function.

On rebind, bnxt_init_one() -> bnxt_init_board() calls pci_set_master()
before bnxt_fw_init_one_p1() reaches bnxt_hwrm_func_reset(). During
bnxt_hwrm_ver_get() and the other early HWRM calls, an unreset function
therefore has bus mastering back. The ring and backing-store pages it
was given have been freed and possibly reused by then. Isn't that the
same IO_PAGE_FAULT or memory corruption this patch is trying to
prevent, just moved to the recovery step?

bnxt_resume() has a similar shape. It calls pci_set_master() before
bnxt_hwrm_ver_get() and bnxt_hwrm_func_reset(), and returns with bus
mastering enabled if either of them fails.

I see the cover notes defer the pci_set_master() callers and the probe
ordering. But rebinding is the recovery this patch documents. Should
bnxt_remove_one() at least do a pcie_flr(), as bnxt_shutdown() does,
when DMA was stopped or the unregister fails? That would quiesce the
function before its memory is freed and before the next probe turns
bus mastering back on.

[Severity: Medium]
What happens when HWRM_RING_FREE is never sent to the firmware at all?

hwrm_ring_free_send_msg() passes through errors that occur before the
request reaches the firmware:

drivers/net/ethernet/broadcom/bnxt/bnxt.c:hwrm_ring_free_send_msg() {
    ...
	rc = hwrm_req_init(bp, req, HWRM_RING_FREE);
	if (rc)
		goto exit;
    ...
exit:
	if (rc || error_code) {
		...
		if (rc)
			return rc;
    ...
}

__hwrm_req_init() can return -ENOMEM when its DMA pool allocation fails:

drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c:__hwrm_req_init() {
    ...
	req_addr = dma_pool_alloc(bp->hwrm_dma_pool, GFP_KERNEL | __GFP_ZERO,
				  &dma_handle);
	if (!req_addr)
		return -ENOMEM;
    ...
}

__hwrm_send() can also return -ENOMEM before it writes the request to BAR0
and rings the doorbell:

drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c:__hwrm_send() {
    ...
	token = __hwrm_acquire_token(bp, dst);
	if (!token) {
		rc = -ENOMEM;
		goto exit;
	}
    ...
}

In either case the firmware never sees the request, so it definitely still
owns the ring. Even so, bnxt_hwrm_tx_ring_free(), bnxt_hwrm_rx_ring_free()
and bnxt_hwrm_rx_agg_ring_free() set ring->fw_ring_id to
INVALID_HW_RING_ID without checking rc. The -ENOMEM also fails the
== -EBUSY check, so stuck is not incremented.

bnxt_hwrm_resource_free() then returns 0 and bnxt_stop_dma() is skipped.
__bnxt_close_nic(), bnxt_half_close_nic() and the bnxt_init_chip() err_out
path go on to bnxt_free_skbs() and bnxt_free_mem() with bus mastering
still enabled.

The cover notes say that counting only -EBUSY was confirmed with Broadcom
on v6. As I understand it, the reasoning is that any other error means the
firmware handled the request. Does that reasoning cover these cases, where
the request was never sent?

These are small GFP_KERNEL allocations, so in practice they would mostly
fail under OOM or fault injection. Even so, should anything other than a
firmware-reported error (rc == 0 with a non-zero error_code) be treated as
the firmware possibly still owning the ring?

>  	}
>  
>  	/* The completion rings are about to be freed.  After that the

[ ... ]

> @@ -13584,7 +13618,8 @@ static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,
>  	if (BNXT_SUPPORTS_MULTI_RSS_CTX(bp))
>  		bnxt_clear_rss_ctxs(bp);
>  	/* Flush rings and disable interrupts */
> -	bnxt_shutdown_nic(bp, irq_re_init);
> +	if (bnxt_shutdown_nic(bp, irq_re_init))
> +		bnxt_stop_dma(bp);
>  
>  	/* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202185628.847699-1-joe%40dama.to

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v7 4/4] bnxt_en: refuse to open a device with stopped DMA
  2026-12-02 18:56 ` [PATCH net v7 4/4] bnxt_en: refuse to open a device with stopped DMA Joe Damato
@ 2026-12-03 19:17   ` netdev-bot+sashiko
  0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 19:17 UTC (permalink / raw)
  To: joe
  Cc: netdev, michael.chan, pavan.chebbi, andrew+netdev, davem,
	edumazet, kuba, pabeni, prashant, selvin.xavier,
	kalesh-anakkur.purayil, edumazet, horms, linux-kernel

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] bnxt_stop_dma() (bnxt.c:7845) returns without clearing Bus
  Master Enable and without setting BNXT_STATE_DMA_STOPPED whenever…
- [Medium] This series makes 'rebind the driver' the only recovery after
  bnxt_stop_dma() has run.
- [Medium] bnxt_en: pci_set_master() called when BNXT_STATE_DMA_STOPPED
  is set

--

bnxt_en: refuse to open a device with stopped DMA

This commit adds BNXT_STATE_DMA_STOPPED, sets it in bnxt_stop_dma(), and
refuses to open the device while the bit is set. It also adds the bit to
BNXT_NO_FW_ACCESS(), so most HWRM commands fail right away after DMA has
been stopped. Rebinding the driver is the only way to recover.

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index c1c58f5c930a0..1f40914610bb8 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> @@ -7848,9 +7848,20 @@ static void bnxt_stop_dma(struct bnxt *bp)
>  
>  	netdev_err(bp->dev,
>  		   "Disabling DMA before releasing ring memory, the driver must be rebound to recover\n");
> +	set_bit(BNXT_STATE_DMA_STOPPED, &bp->state);
>  	pci_clear_master(bp->pdev);
>  }

[Severity: Medium]
bnxt_stop_dma() clears bus mastering so the device cannot DMA into the
ring and RX buffer memory that __bnxt_close_nic() frees next. The new
bit is supposed to keep it that way until the driver is rebound.
bnxt_resume(), bnxt_fw_reset_task() and bnxt_io_slot_reset() still call
pci_set_master() without looking at BNXT_STATE_DMA_STOPPED.

The notes defer those callers to net-next. However, with
BNXT_STATE_DMA_STOPPED in BNXT_NO_FW_ACCESS(), these paths now turn bus
mastering back on and then fail part way through. The device is left
enabled as a bus master with nobody driving it.

Suspend looks like the easiest way to get there. bnxt_suspend() calls
bnxt_close(), which returns 0 even when bnxt_shutdown_nic() hits the
HWRM_RING_FREE timeout and calls bnxt_stop_dma(). On resume:

bnxt_resume()
  pci_set_master(bp->pdev)
  bnxt_hwrm_ver_get()
  bnxt_hwrm_func_reset()
  bnxt_hwrm_func_qcaps()     <- -EBUSY from BNXT_NO_FW_ACCESS()
  goto resume_exit           <- bus mastering left on

The firmware ring state may survive suspend (s2idle, or D3hot without a
soft reset). In that case, can the device write into the freed buffers
between pci_set_master() and HWRM_FUNC_RESET? That includes the VF
bnxt_hwrm_poll() retry loop. If HWRM_VER_GET or HWRM_FUNC_RESET fails
on an unresponsive firmware, that window never closes.

bnxt_fw_reset_task() is similar: BNXT_FW_RESET_STATE_ENABLE_DEV calls
pci_set_master(), then bnxt_open() refuses with -ENODEV. In
bnxt_io_slot_reset(), pci_set_master() runs and bnxt_io_resume() then
fails in bnxt_hwrm_func_qcaps().

Could these paths check BNXT_STATE_DMA_STOPPED before pci_set_master()
and bail out? Or could they clear bus mastering again on their error
exits? This patch is what makes them fail with bus mastering on, so it
seems worth handling here rather than in net-next.

[Severity: High]

bnxt_stop_dma() returns early before it reaches this point:

	/* A firmware reset resets the device, and the fatal error path
	 * already disables it.
	 */
	if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state) ||
	    test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
		return;

When IN_FW_RESET is set, neither pci_clear_master() nor the new set_bit()
runs. Is a reset guaranteed to happen before the device can reach the
freed ring memory?

One path where it doesn't seem to: bnxt_fw_reset() with active VFs sets
IN_FW_RESET and moves to BNXT_FW_RESET_STATE_POLL_VF, and the device
stays open. If the user then closes the device:

bnxt_close()
  bnxt_close_nic()
    set_bit(BNXT_STATE_ABORT_ERR, &bp->state);
    __bnxt_close_nic()
      HWRM_RING_FREE gets no answer (-EBUSY)
      bnxt_stop_dma()   <- returns early, bus mastering stays on
      bnxt_free_mem()

Then the POLL_VF case in bnxt_fw_reset_task() does:

		netdev_lock(bp->dev);
		if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
			netdev_unlock(bp->dev);
			goto fw_reset_abort;
		}

bnxt_fw_reset_abort() clears IN_FW_RESET and closes the device. It never
issues a reset or calls pci_disable_device(). The VF timeout branch in
POLL_VF also clears IN_FW_RESET without a reset.

Wouldn't the firmware then still own rings that point at freed memory,
with bus mastering on? BNXT_STATE_DMA_STOPPED would also never get set,
so the new open-time check would not fire.

The normal non-fatal reset path seems to have a smaller window too.
bnxt_fw_reset_close() frees ring memory before bus mastering is cleared:

	__bnxt_close_nic(bp, true, false);
	bnxt_vf_reps_free(bp);
	bnxt_clear_int_mode(bp);
	bnxt_hwrm_func_drv_unrgtr(bp);
	if (pci_is_enabled(bp->pdev))
		pci_disable_device(bp->pdev);

bnxt_hwrm_func_drv_unrgtr() can wait for a full HWRM timeout if the
firmware does not respond. Later, a failed bnxt_reset_all() only logs
"Unable to reset FW rc=%d". BNXT_FW_RESET_STATE_ENABLE_DEV then calls
pci_set_master() anyway.

Could the IN_FW_RESET skip depend on a reset or pci_disable_device()
actually happening? Alternatively, could bus mastering be cleared on
these paths as well?

[ ... ]

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
> index 41d05efd6307a..50c024dd3c6c4 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
> @@ -2474,9 +2474,11 @@ struct bnxt {

[ ... ]

> +#define BNXT_STATE_DMA_STOPPED		16
>  
>  #define BNXT_NO_FW_ACCESS(bp)					\
>  	(test_bit(BNXT_STATE_FW_FATAL_COND, &(bp)->state) ||	\
> +	 test_bit(BNXT_STATE_DMA_STOPPED, &(bp)->state) ||	\
>  	 pci_channel_offline((bp)->pdev))

[Severity: Medium]

Rebinding is now the only recovery. What clears the firmware's ring
state before bus mastering is turned back on at the next probe?

With DMA_STOPPED in BNXT_NO_FW_ACCESS(), bnxt_remove_one() now skips its
bnxt_hwrm_func_drv_unrgtr() call right away. The return value is ignored
and no FLR follows. bnxt_shutdown() handles the same failure with an FLR:

	if (bnxt_hwrm_func_drv_unrgtr(bp)) {
		pcie_flr(pdev);
		goto shutdown_exit;
	}

On rebind, the order is:

bnxt_init_one()
  bnxt_init_board()
    pci_set_master(pdev);
  ...
  bnxt_fw_init_one_p1()
    bnxt_hwrm_ver_get()
    (on failure: msleep(100), bnxt_try_recover_fw(), ver_get again)
    bnxt_hwrm_func_reset()

bnxt_hwrm_ring_free() says:

	/* -EBUSY means the firmware never answered, so it may still own
	 * the ring.
	 */

Between pci_set_master() and HWRM_FUNC_RESET, could DMA engines that
still hold the previous binding's rings read descriptors from, or write
packets, completions or stats into, memory the previous instance freed?

bnxt_kdump_reset() already clears bus mastering and runs pcie_flr()
before probe to clear pending DMA from a previous instance, but only in
the kdump case.

Would either of these close the window: a pcie_flr() in bnxt_remove_one()
when BNXT_STATE_DMA_STOPPED is set, or a reset before pci_set_master()
at probe?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202185628.847699-1-joe%40dama.to

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-03 19:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:56 [PATCH net v7 0/4] bnxt_en: Make RING FREE more robust Joe Damato
2026-12-02 18:56 ` [PATCH net v7 1/4] bnxt_en: return the RING_FREE status to callers Joe Damato
2026-12-03 19:17   ` netdev-bot+sashiko
2026-12-02 18:56 ` [PATCH net v7 2/4] bnxt_en: check HWRM response if completion never arrives Joe Damato
2026-12-02 18:56 ` [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free Joe Damato
2026-12-03 19:17   ` netdev-bot+sashiko
2026-12-02 18:56 ` [PATCH net v7 4/4] bnxt_en: refuse to open a device with stopped DMA Joe Damato
2026-12-03 19:17   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox