Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: joe@dama.to
Cc: netdev@vger.kernel.org, michael.chan@broadcom.com,
	pavan.chebbi@broadcom.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, prashant@broadcom.com,
	selvin.xavier@broadcom.com, kalesh-anakkur.purayil@broadcom.com,
	edumazet@google.com, horms@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free
Date: Thu, 03 Dec 2026 19:17:12 +0000	[thread overview]
Message-ID: <179632543268.3146.6290940877356562929@kernel.org> (raw)
In-Reply-To: <20261202185628.847699-4-joe@dama.to>

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

  reply	other threads:[~2026-12-03 19:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=179632543268.3146.6290940877356562929@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=joe@dama.to \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.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 \
    --cc=selvin.xavier@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