From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325434; b=vEQNrNo0aofbZmlzLWq+ezyAub9GYCGGh2/Fs45V/bhCMjiVWBtgwiJHDv4thne3agP6 FwCjkaOGaDNlnYQt53hJbvCeKpibiiYXJ0CnFcvOpRp0rC9IavrWe579vFXNB4Y55M7KS p9DpKAzlbuW9leNk1awu8ce8o8Xao357QUzx1O9esQ3FlTROynd+9TLkPdKVVa9kXAEJ5 Yed3j5UIZHsGhQcgVTzilpUmNYXgiVH9W0jIpPlc0B17cfRN/lwCtp82oKvqGkvItIDWc SnIp8+nfEEXw8qyocTwj6khRe8Gbh1ZUPLqAG2307DbD459rCY37wqFqfk/4am8It2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325434; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=Ln6BxW9evuO2JMccIo+SnR7Q3E/zAUnr0HPWQlZ2XlQ=; b=iqk+vgC6V7w5VpJy6A5/5DVgJ5KfU6OeTqWpkIWDCGzPcN/cl564FVSpnyC70YJ2qE30 +TRuvH7ziMVvoTF3gdhxkw6d+aVJlRNQGpXTCdmDvtlpz3JVLUF4b3qSkyS0wGmm6Vc+q chByVY9VIzbQX0f7KNA4KoINxOaOxoW8Q/oeJixFTj/H5eIDYmrA9xtqJqXMxkbDU68nl DVUtL6TG+bVw7AGr58YBI/Vipnuc7SdTmzvvkfD/1ardOBOkcOzssVyLg7Z9PAdFmoZ0F 5jszBkvs1hcepxphult3yeEpHqvdP++CDhIHyoTelcURSnQL2TIQT5318WQYaOiKf5w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mri19GcP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D326606A68C; Thu, 3 Dec 2026 19:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mri19GcP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2559C1F00935; Thu, 3 Dec 2026 19:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796325434; bh=Ln6BxW9evuO2JMccIo+SnR7Q3E/zAUnr0HPWQlZ2XlQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=mri19GcPru/hQMxTcxS0W3HLu4vqz+syzXfNbLiOnnng6yTVN/MEyZyXcf1t0FBxq P/RGonkn81mcH/tt/eTiDyWSipu17ujSTDCDaaZMPSfpDVTJkbbM9dpoU3YcP4rcmG RrfviFzDZLMZtRMtVrHG50jIg+SV/MJbUO3TDrF+YQDR7JH/bAWyQ/8d/m2eyAYK0d yuGIas1qDTURURrBdYoIYkO7sg8fkD7slM6JWkHVGQjC5cYKcGq1BTNgVz8U/TMu4X SeXa2sM+NOlMPHZvgjK3ybeLTp6RKGyjqVXYHaOr9GO8fSnwklz317CeRRWBYFNM/J D761K9QlxvwMQ== Subject: Re: [PATCH net v7 3/4] bnxt_en: stop DMA before releasing rings the firmware did not free 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 Date: Thu, 03 Dec 2026 19:17:12 +0000 Message-ID: <179632543268.3146.6290940877356562929@kernel.org> In-Reply-To: <20261202185628.847699-4-joe@dama.to> References: <20261202185628.847699-4-joe@dama.to> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 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