Re: [PATCH net v7 4/4] bnxt_en: refuse to open a device with stopped DMA
From: Joe Damato
Date: Thu Dec 03 2026 - 21:26:58 EST
On Thu, Dec 03, 2026 at 07:17:14PM +0000, netdev-bot+sashiko@xxxxxxxxxx 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_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.
idk. I don't think this patch makes it worse.
HWRM_VER_GET and HWRM_FUNC_RESET are exempt from BNXT_NO_FW_ACCESS(), so in
bnxt_resume() the function is reset before bnxt_hwrm_func_qcaps() fails.
After that the firmware no longer holds the old rings. bnxt_fw_reset_task()
and bnxt_io_slot_reset() only get there after a firmware or slot reset.
The window between pci_set_master() and HWRM_FUNC_RESET, and the error
exits after VER_GET or FUNC_RESET fail, exist without this patch.
> [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?
Same as my reply to patch 3: this is the early return listed in the
notes. These paths need a firmware reset to overlap a RING_FREE timeout
during close, and they behave the same as before the series. The
ordering in bnxt_fw_reset_close() is not changed by this series.
> > 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?
See my reply to patch 3. bnxt_remove_one() now skips
bnxt_hwrm_func_drv_unrgtr() right away, but the outcome is the same as
before this patch: with DMA off its response can't arrive, so it used to
fail after the timeout instead.