From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796350899; b=wgp1rdfMIfiMqYKLpOGVqGYlKUFrjA7Vi4EOtY/LPknyGIICjXQjK4Xdx4sYXYOPwcqP YI97oz6CnznqNBkV/Gyh7Bi9+HvYHSIzhRiccVlqBG+616VrwdXKCPHZ5xdaYqZSeKK0i qiP494ClYxFqlgVQHtWCjg4stQU6Knk1BVElRKcomJl+4tTezpYEmQJ8Rae74h6ZFNTJV 06R0xA1fWFEQhG24MnJ7tr2jn/s2j+FbFO3dowvVq1ab9iupwuJMOc+9pSdNFKXODzvg/ tfF41q+YA8HMC4eICU5iZ3/yjzKtlYD/4wJmZ+V+y2ayTkDXr1dyirhUzIRCxmGgQOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796350899; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc: Subject:Message-ID:Mail-Followup-To:References:MIME-Version: Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To; bh=ZsbYpcoSqYN0iFW4ol3c4nNg1SKjc6dSPHYns6RxtUg=; b=mAGb4MVtUh0L0cJlcNcQ/cdr34K+VzayCwMae1LXbxWP1XDDM6CSRI90ZHXyZPr1QGLR iHYkDfLwqvWU77/4UTj8GZIFCiay4yrwCE8EZ2V8W83Uv6qNLlJlATDqtyHz6u7Gu/F6s Tk9GvowGvE+uMqFZf3VpEtSYUoBDwVfErROoTd+zQWVs2BZJRqnWTk5fHlNgJP8XAJ9+r cmERld9wDVlOjfSMgPOE6XtmZzn+UaZWxoatxbJ0ddULHDlPTZPPSflmBYIwnq290EQL+ GEnTlsnPHO2SLNvcxCqjvIwiGvcQNGDdkqJHfQ4QcXcOGyhoYLwC872pSMfv31RuACg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=dama.to; spf=none smtp.mailfrom=dama.to; dkim=pass header.d=dama-to.20260707.gappssmtp.com header.i=@dama-to.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=kuDq7Bgx; arc=none smtp.remote-ip=209.85.216.45 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B04BA606A322 for ; Fri, 4 Dec 2026 02:21:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B04BA606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dama.to Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=dama.to Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dama-to.20260707.gappssmtp.com header.i=@dama-to.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=kuDq7Bgx Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-3b54096b2d0so324241a91.1 for ; Thu, 03 Dec 2026 18:21:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dama-to.20260707.gappssmtp.com; s=20260707; t=1796350898; x=1796955698; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:mail-followup-to:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZsbYpcoSqYN0iFW4ol3c4nNg1SKjc6dSPHYns6RxtUg=; b=kuDq7BgxwoGYOmGRRnXP8ck5PAok1YnqFiF4Yqr/gqx+DvK82iA2j/7nI5iOcCGnWX d81Qn5ghIm2c7Il+rLXL0RFBU/egteLFq+lockk47Yb5Pn7PGyEIwDhdUqCAywW+YHEu c//g6EOyONZlOYej0ZR69SntwDyeA78O2RxAVeluRUSvtN8jnOvWtgk4ojLPqMxhsvFw 8alhkJKNk4pMJj8RAXnkuKKrBV+iWTAgc9VKz5/vCbXJEFzOtaA4seHMAa6+Q6RY9OD+ GOP+8Gx5VXRSJJNLPHdQWTnpWcvb729WgsHz5SU+5KcwHs3d5YTSGK0ShvQHZEIM0Jfa pNlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796350898; x=1796955698; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:mail-followup-to:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=ZsbYpcoSqYN0iFW4ol3c4nNg1SKjc6dSPHYns6RxtUg=; b=w7+Zo73WCifyrsfPT9669f/E41ecGmHjY4LXXGj5oP3zm05b32mDfCoA9+2KjQYfrq WLT60Ecw2Ce0lZpbmcWIMopY7SUh4fOnBr1rYnJulmes771cHFHgzrqJ4hCgKhWx+Xd+ nGZReR+JmjybN3wp/zItClhTR0Nk0k6xSWLjoLTYXoA3bqw1Gmt6WOPC6Gadc4kcmWw7 FZ4Z0LQlHCAjvAXhsw6rXV7z3Tlq/9cCsqD0HBw6rC2GwG9Bye/2nALB37c9pIm/zIhJ V90kE127zDqN0rXAVF+r8kSolBQ9kW59oNObrkcUUhral3vhpIBprEDOaufMZ5POzyj4 tbNQ== X-Gm-Message-State: APuU4Z/fmUkFg/O1WwLpJ8yunf1RgdqIWO3A/3Fc+cWJfu0IB/TPiFtI qg9O9etNuZ8cVsSfs9DIH0hA3gY/Ib99WnBI/OBoie8YwwpicW051ePcbP03hAHi1Cc= X-Gm-Gg: AZFdTZdbW1w5DMumbJVHmdOxwndAaEiHjrUE6CdnU9n7pEZhYvBltbvnRrrMHl1sV7q +gIK/gaAPi710q0g7FDn4BBCZn3EjnLfhnjjPMwiHPP7oUUC36TvTb+tihMpF1j+4c06BGEeHg5 EAEUvvR2gyhcgq3pHaD82EaHIUeNNMjgmgmRb31mZa9kL0XLHTaLAzv7PFHC7Dx3rMhLbkBxBlH ppCs5PERaIey13R3K3yVAYwa6LMrYSmIU2tgcQAvjf0L2F8KrWMjfLRKrBRq161GVMlzljxq2OO oSAYSKxs1jFXjkEADzQ4YaRIeQKGw97QUI4eTMj2mxwIWbFD5V44z9ewSUOnq/fgPR0t+NBHeOh rcnfsGSIzXw9oryuwjzybm8gLrPD4sfXXIkFz58ZClQjvp3S3Vfz4KlCfOETRdRoUhYq/+dM8k6 O26rBuBggFMUb/JGRRmas78xgMlbqShuSZ4ybcP2aQtNhKsHBH8Hws5NfH/VCIi+TkAlP3MSZA/ +2pOlwFjxHXtvH+C7dlgYxSeDTYtis6LrHhElqBAPDZ9k/B0dkErE2N5wS+5IDPjWvEL7JhgdRi p64aMJCQV8kgTM0J2og9Ko5DjvMtkTVmlfDmCVxL X-Received: by 2002:a17:90b:4b8f:b0:3b4:1714:5bfc with SMTP id 98e67ed59e1d1-3b5e06aae54mr428658a91.61.1796350897787; Thu, 03 Dec 2026 18:21:37 -0800 (PST) Received: from localhost ([2a03:2880:2ff:2::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c73287eesm7011392a91.0.2026.12.03.18.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 18:21:37 -0800 (PST) Date: Thu, 3 Dec 2026 18:21:36 -0800 From: Joe Damato 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 Message-ID: Mail-Followup-To: Joe Damato , netdev-bot+sashiko@kernel.org, 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 References: <20261202185628.847699-4-joe@dama.to> <179632543268.3146.6290940877356562929@kernel.org> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 (?).