From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796351212; b=hh1ZA3GWNSqCYc/LjM5WNzFYbMVreHuVcRpKGondJ/MhDf9x25tr2dXi9qyMI61lOumR 9Pc5AGIbwo+5Zl5bgWBCjhf0YB+OPAR66gv+iM3s12Cc00DCcSkoLmuJ42IEL5Hyy108g NpaEK4gh/uXcaepCTB7MHGrwkVC6S6473pe3BFmkQvPBYyUFsJ8sFnFT3eZCtX4L8I/if iWniOOAz97fmAUinqvLzPplyPzOV2YO74A76VFGbv2FiuzozXsOUzJD9AODkud1PC2kpi LXa+BpVfN5D2UcMmfUoUly32/LSFko2B1qFyknKeLelpwUgHwUn93X7oX9AroqQ0Otg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796351212; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=D98D9eDSrWvZP2N+wKDCB6Un+NJo/JyE0QJ+8jJ++yg=; b=zRHhk1rPwk4+Q88VPkKixgdyEZ/BPmRLqGNalp5N9qpBlyj2Wx8N6ofGx3LwWgxl/GVW fBM2BTeTXrPguR6uAOaHJ/NMHMkYd88RsC69ixDU+sA4OsptRebV5EHMIW/IGXYo9jEkR zDrj9q8lqnSqqyL/Jd9FE81Tgbzh6jBfOQMchm9id4JMgyAt9hNQgKi2/hwCKunvPViS2 6tCG8DpOwryBVDgdT8eRAukqA4XeyqJ00uKhFzJOh6yMiQO4lpjsqq/8S9izI54bzjVQL BA/JjdPbNckfWfIPQ5WiNo9291s9BZ4k9kikBCtDwMn9GIoHdiKgPV2UTAg7ZBrpHFg== 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="JS9/+5rr"; arc=none smtp.remote-ip=209.85.214.172 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 E1944606A322 for ; Fri, 4 Dec 2026 02:26:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E1944606A322 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=JS9/+5rr Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2f01f296937so1941865ad.3 for ; Thu, 03 Dec 2026 18:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dama-to.20260707.gappssmtp.com; s=20260707; t=1796351211; x=1796956011; 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=D98D9eDSrWvZP2N+wKDCB6Un+NJo/JyE0QJ+8jJ++yg=; b=JS9/+5rrpipvyRWgf/jRlnAHojcog2Z5OhaFVW9tMOWSVAngYvHRTzSmzfpeQPlcSJ zy8D+YBM51apeNFY/nHKkVdBW7Zkl0FEZtSZtOypVoKLmVZd9XojQbIu5KDL5JDCMs/7 k8dT1/x25+aiWYhNi7+5ayksZLn6iv3+iVQ/pbXIyuq8g8geJp5KJivb46soPAuQftjC Tiv8cxKwCiEHjmNR/GigD9e8wrU7xxquaTNN4d4GK3t+JxyzicVT8VjKt7h9pWtLAVS7 h/n7JzFjmaNtYUKy8Uup3e4kaMGKQ5tiBB4gFeSI2b3T7cp2ofwXRGXvShPEBJEjjeuT bP0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796351211; x=1796956011; 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=D98D9eDSrWvZP2N+wKDCB6Un+NJo/JyE0QJ+8jJ++yg=; b=yXF8aTkd8QDno/+cETI9aO2CXfpiVHBGts8J+WN9oQIfOKqUslXar44YLRVkSbx1gl NSolEjBMeKD27nH3g9hsL7oHAmKBXNgMrJlxg8ZYFcydZoVHwTwT9Cplq8tgx95X7xp+ ++8iXIWKgZahLzbADekwc4dIjN3Zx6QVUUJJmpk7o25V1EC+JTBNMvIVOlsMTDxWR/Nh lna+9deAIAB2Lq6GF27RZuNeda5v7oN16C0DaeKllwjO2JzD4zdAlZlSbFRTf0pI+Y+r Hfdu1OVdgIUfEOdelSNGAb3n5+7UcDfifKIi5IxqFvwo5FLnW8UkoRCpmhY7A2OqmXjj 71mw== X-Forwarded-Encrypted: i=1; AL+hErEGmpWC0pmpyjKdJ1H2huwph/eEOVTUIcNNzGoHxcVEBtpU4Z+7nUgh4PbU9j/YaPsU2BZ9QBVgwhmO3Qo=@vger.kernel.org X-Gm-Message-State: APuU4Z89Vh5DvcF79/X7+4tVhRVuDdTzWR77xUGdtbCipgk5A52mg4Dq YJPZZ3uKJhRpbcizFckbNyhCw8TpPhvw+Y+N8GlZiCzQB3qb9VpmDrX8Q/JMOuZwbV0= X-Gm-Gg: AZFdTZfuUlaJMTjkz28/0s2B218jsc//JLPvnOSnfEbjfC/mcdAFNI9qvchh7I65Qn1 /ALIM9UGpOE5o/Lkp3l9zeiw9peomUUsSEZ3pv5OfYvgdngC9V/jTg0NGNhr0dOu0YC61vV5nJZ fTQhEnU1QvcOBZXGbPWxb0s5Szp9Wb8m/zOLIco0FVTBjEN+ByYVZ/b/m6dHbW/1/Klao8F8Cmp fCbXUHrbEvHxOHEHvCnzxZtfsJSbJi3eq1WBLSV8wlzfH9hD0yPzcGZ2uAhtXfLXwBYSYoMFTMk zksByER1kZBMjk4efsPCkPPQB8fiyjEV+YpFx6DP9VzMbaADPMTTWRZwbFgaMfR8dG5jH7HxT/l 0p4BjPVe68wseYPyk2/UB9tl0LRnvQ0zjF6tiYqP+uflZk4XXvRnorHHsOysrxtPNZ+LEm/Fu04 B54GZljmoPeYf7AoHB59RjaKj0FoJ1QszUS/IT4iNPHNfSiMtP316O3Q/m5BOarKBi3SgQPatK2 DMY3Dv/MWtVkWFik910kQPYcOUCMPGp+LST/cmBXvp2K6G4ocfVTcp77ck3OTTftMaxBIVmP7fs PvLzAbOqPLNC6j+UTRaZjXHHxOp2Ol/8dWI1JOZ8RQ== X-Received: by 2002:a17:90b:184d:b0:3ac:9d14:fe9f with SMTP id 98e67ed59e1d1-3b5e0663607mr490842a91.31.1796351210990; Thu, 03 Dec 2026 18:26:50 -0800 (PST) Received: from localhost ([2a03:2880:2ff:52::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5de29f8easm605881a91.1.2026.12.03.18.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 18:26:50 -0800 (PST) Date: Thu, 3 Dec 2026 18:26:49 -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 4/4] bnxt_en: refuse to open a device with stopped DMA 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-5-joe@dama.to> <179632543413.3146.13728964654428418135@kernel.org> X-Mailing-List: linux-kernel@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: <179632543413.3146.13728964654428418135@kernel.org> On Thu, Dec 03, 2026 at 07:17:14PM +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_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.