mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Damato <joe@dama.to>
To: netdev-bot+sashiko@kernel.org
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, 3 Dec 2026 18:21:36 -0800	[thread overview]
Message-ID: <axIjsMtWTUfIg4ts@devvm20253.cco0.facebook.com> (raw)
In-Reply-To: <179632543268.3146.6290940877356562929@kernel.org>

On Thu, Dec 03, 2026 at 07:17:12PM +0000, netdev-bot+sashiko@kernel.org wrote:
> 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?

These are the cases the early return gives up, which is why it is in the
notes. I answered the same point on v6; all three need a FW reset or a fatal
event to overlap a RING_FREE timeout during close.

I haven't seen that and in each case the ring memory is freed with DMA on,
which is what happens today without this code, so I think this makes it better
even if there is still a small race window.

In the non-fatal case the reset task calls pci_set_master again even when
bnxt_reset_all fails. In the aborted cases nothing turns DMA back on so the
next open would run with it off.

Fixing that means changing the reset task, which I think is net-next material
and not part of this series, IMHO (but Broadcom can feel free to correct me on
this).

> [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.

Same answer as on v6: not completely. Probe turns DMA on before
HWRM_FUNC_RESET, which is in the notes. On unbind, DMA is already off and
bnxt_cleanup_pci() disables the device before bnxt_free_ctx_mem(), so the
firmware can't reach that memory then.

An FLR in bnxt_remove_one() when DMA was stopped looks like a reasonable
way to close the probe window, but it's not clear to me if that's a net or
net-next thing. It feels like a net-next followup, IMHO.

> [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.

This is in the notes on patch 1 and was discussed on v6. As you say, these
allocations only fail under OOM, and I haven't seen it in production.

I think this is also part of the net-next followup to improve this all (?).

  reply	other threads:[~2026-12-04  2:21 UTC|newest]

Thread overview: 12+ 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-04  2:14     ` 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 ` [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-04  2:21     ` Joe Damato [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
2026-12-04  2:26     ` Joe Damato
2026-12-04  2:34 ` [PATCH net v7 0/4] bnxt_en: Make RING FREE more robust Joe Damato

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

all inboxes | Powered by JetHome®