Article View: linux.kernel.netdev
Article #5339Re: [PATCH net-next v4 8/8] bnxt_en: Fix ring accounting and validation when rings are constrained
From: netdev-bot+sashiko
Date: Tue, 20 Oct 2026 07:25
Date: Tue, 20 Oct 2026 07:25
239 lines
16050 bytes
16050 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 (2) · Medium: 1 · 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).
- [Medium] In bnxt_init_int_mode(), the new min_tx check (`min_tx =
bp->tx_nr_rings_xdp ?
Pre-existing issues:
- [High] Out-of-bounds read of bp->rx_ring in bnxt_fill_hw_rss_tbl_p5()
through stale non-default RSS context indirection tables after the RX…
- [High] This problem wasn't introduced by this patch, but the
BNXT_STATE_READ_STATS single-bit reader protocol in bnxt_get_stats64()…
--
bnxt_en: Fix ring accounting and validation when rings are constrained
This patch renames bnxt_adj_tx_rings() to bnxt_adj_rings(). The new
function scales TX, RX and CP rings together when fewer rings are
reserved. It also strengthens bnxt_rings_ok() to check the minimum ring
configuration needed for TCs and XDP. The adjustment is now done only in
__bnxt_reserve_rings() and bnxt_init_int_mode(), and the TC reset error
path at the end of bnxt_reserve_rings() is removed.
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index 9ea2de8e81358..7cc50c48f3b9e 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
[ ... ]
> @@ -11528,20 +11579,50 @@ static int bnxt_init_int_mode(struct bnxt *bp)
> bp->irq_tbl[i].vector = pci_irq_vector(bp->pdev, i);
>
> bp->total_irqs = total_vecs;
[ ... ]
> /* Trim rings based upon num of vectors allocated */
> rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
> total_vecs - ulp_msix, min == 1);
> if (rc)
> goto msix_setup_exit;
>
> - tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings, bp->tx_nr_rings_xdp,
> - bp->rx_nr_rings);
> - bp->cp_nr_rings = (min == 1) ?
> - max_t(int, tx_cp, bp->rx_nr_rings) :
> - tx_cp + bp->rx_nr_rings;
> + min_tx = bp->tx_nr_rings_xdp ? tcs + 1 : tcs;
> + if (bp->tx_nr_rings < min_tx) {
> + netdev_err(bp->dev, "Not enough MSI-X to satisfy min. TX rings\n");
> + rc = -ENOMEM;
> + goto msix_setup_exit_restore;
> + }
[Severity: Medium]
Does this check also reject the driver's own "rings not reserved yet"
state, where bp->tx_nr_rings is 0?
That state is created by bnxt_clear_reservations(bp, false), which is
called from bnxt_dl_reload_down() and bnxt_cancel_reservations(). A
failed bnxt_set_dflt_rings() creates it too. In both cases cp_nr_rings
is left nonzero:
bnxt_clear_reservations() {
...
if (!fw_reset) {
bp->tx_nr_rings = 0;
bp->rx_nr_rings = 0;
}
...
}
In this state the sequence is:
- bnxt_get_num_msix() returns cp_nr_rings plus the ULP vectors, so
vectors get allocated.
- bnxt_trim_rings() succeeds with rx = tx = 0.
- tx_nr_rings (0) is then less than min_tx (at least 1).
- The function frees irq_tbl, calls pci_free_irq_vectors() and returns
-ENOMEM.
Before this patch the same input returned 0.
Some callers run bnxt_init_int_mode() before the default rings are
reserved again:
bnxt_open()
bnxt_reinit_after_abort()
bnxt_clear_int_mode()
bnxt_init_int_mode() <- fails, BNXT_STATE_ABORT_ERR stays set
bnxt_open() then returns -ENODEV and never reaches
__bnxt_open_nic()->bnxt_init_dflt_ring_mode(), which would rebuild the
rings. Would every later open fail the same way until the driver is
rebound?
bnxt_sriov_disable()->bnxt_restore_pf_fw_resources() has the same
problem. It calls bnxt_clear_int_mode() and bnxt_init_int_mode(), then
passes the -ENOMEM to bnxt_ulp_irq_restart(). With the interface down,
wouldn't the RoCE ULP be left without MSI-X vectors?
Should this check be skipped when tx_nr_rings is 0?
[ ... ]
> @@ -13118,13 +13194,29 @@ static void bnxt_set_xdp_tx_rings(struct bnxt *bp)
> bp->tx_nr_rings += bp->tx_nr_rings_xdp;
> }
>
> -static void bnxt_adj_tx_rings(struct bnxt *bp)
> +static void bnxt_adj_rings(struct bnxt *bp)
> {
> - /* Make adjustments if reserved TX rings are less than requested */
> - bp->tx_nr_rings -= bp->tx_nr_rings_xdp;
> - bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
> - if (bp->tx_nr_rings_xdp)
> - bnxt_set_xdp_tx_rings(bp);
> + int tcs = bp->num_tc ? bp->num_tc : 1;
> + int rx = bp->rx_nr_rings;
> +
> + /* Make adjustments to rings based on TC/XDP/shared rings policies */
> + if (bp->tx_nr_rings_xdp) {
> + tcs++;
> + bp->tx_nr_rings_per_tc = bp->tx_nr_rings / tcs;
> + bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
> + } else {
> + bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
> + }
> +
> + if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
> + bp->tx_nr_rings_per_tc = min(bp->tx_nr_rings_per_tc, rx);
> + bp->rx_nr_rings = bp->tx_nr_rings_per_tc;
> + if (bp->tx_nr_rings_xdp)
> + bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
> + }
[Severity: High]
This is a pre-existing issue, but this clamp gives rx_nr_rings new ways
to shrink:
- In shared-ring mode, a TX-only shortfall from firmware or MSI-X now
also reduces RX.
- Under XDP, RX is clamped to tx / (tcs + 1).
After a shrink, __bnxt_reserve_rings() and bnxt_init_int_mode() only
check and reset the default table (bp->rss_indir_tbl).
Non-default contexts in dev->ethtool->rss_ctx are kept across close and
applied again at open:
__bnxt_open_nic()
bnxt_hwrm_realloc_rss_ctx_vnic()
__bnxt_setup_vnic_p5()
bnxt_fill_hw_rss_tbl_p5()
In bnxt_fill_hw_rss_tbl_p5() the stored index is used directly:
else if (vnic->flags & BNXT_VNIC_RSSCTX_FLAG)
j = ethtool_rxfh_context_indir(vnic->rss_ctx)[i];
...
rxr = &bp->rx_ring[j];
bnxt_alloc_mem() has already reallocated bp->rx_ring with the smaller
rx_nr_rings. Can this read past the end of bp->rx_ring[]? Would
bnxt_cp_ring_for_rx() then dereference a garbage rxr->rx_cpr?
The commit message says the fix for non-default RSS contexts is
deferred to a separate patchset. This patch makes the shrink reachable
in more configurations. Would it make sense to land that fix with this
one or before it?
> +
> + bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs;
> + bnxt_set_cp_rings(bp, bp->flags & BNXT_FLAG_SHARED_RINGS);
> }
>
> static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
> @@ -13144,7 +13236,6 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
> if (rc)
> return rc;
>
> - bnxt_adj_tx_rings(bp);
> rc = bnxt_alloc_mem(bp, irq_re_init);
> if (rc) {
> netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
[Severity: High]
This isn't a bug introduced by this patch, but it concerns the
allocation and freeing of bp->bnapi around this path. The
BNXT_STATE_READ_STATS handshake in bnxt_get_stats64() seems to track
only a single reader:
bnxt_get_stats64() {
set_bit(BNXT_STATE_READ_STATS, &bp->state);
...
clear_bit(BNXT_STATE_READ_STATS, &bp->state);
}
Consider two readers:
- Reader A sets the bit and starts walking
bp->bnapi[i]->cp_ring.stats.
- Reader B sets and clears the same bit while A is still reading.
__bnxt_close_nic() then sees bnxt_drv_busy() as false and frees the
memory:
clear_bit(BNXT_STATE_OPEN, &bp->state);
smp_mb__after_atomic();
while (bnxt_drv_busy(bp))
msleep(20);
...
bnxt_free_mem(bp, irq_re_init);
RTM_GETSTATS goes through rtnl_stats_get()->dev_get_stats() under RTNL
without rcu_read_lock(). So synchronize_net() in bnxt_del_napi() does
not wait for it.
The FW reset close path also runs under netdev_lock only, without RTNL:
bnxt_fw_reset_task()
bnxt_fw_reset_close()
__bnxt_close_nic()
Can reader A then access the freed bnapi and ring stats? Would a real
lock or RCU be a better fit here than the state bit?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016064427.496944-1-michael.chan%40broadcom.com
Technical Details
Message-ID:
<179248113613.3135.941378516751494969@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349088-linux-kernel-netdev=dewy.ruReferences:
<20261016064427.496944-9-michael.chan@broadcom.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349088-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v4 8/8] bnxt_en: Fix ring accounting and validation when rings are constrained Date: Tue, 20 Oct 2026 07:25:36 +0000 Organization: Usenet Network Message-ID: <179248113613.3135.941378516751494969@kernel.org> References: <20261016064427.496944-9-michael.chan@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3802385"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:KcTWmnAirSuIyjhmPwM/YSBlO0w= sha256:DuRRIFfDmAEil0Vp0UHlQpHLe/SqKZpWttAZWgNlB4M= sha1:Aeo4VFW1QDmuVZv9QxtmQflqByw= sha256:TeHrcSS8fcHx31x4F9qqp9PBoH83CFjHZh88G8T9Jhg= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id EC5FA110C2C; Tue, 20 Oct 2026 10:30:13 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.729 X-Spam-Status: No, score=-3.729 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.329, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UN7c9i89rXl3; Tue, 20 Oct 2026 10:30:10 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-349088-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id A7AB5110C07; Tue, 20 Oct 2026 10:30:00 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id B3C312EC1F; Tue, 20 Oct 2026 07:25:48 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1792481138; b=UldRbamDNfwo/AR2W63Ri0CjA4y+E0rgY+2qXyu6q0OHE31Lxc/zMrKQCRUJtJdsxqO4 25XiAd7raqSzUj6hZgN4Jdvo6vaLF7rsCoRDR0kjWnbzv3LaRM8WipzG8s3fGGBdFyzjQ 7erjqD2THzjYtSUGQbzbSBzba4P2vlawXFW+aesnJeVjekn5gxeM0pz49ujdzSAFg3KA0 oU3Du8y6rF9KdNkyLkPtbmek/ie44YnT5mWjbor8oJaob3fqmZ/zYrriOJiSi6CaD+UNO spHF7hzgJN2sRU/J5ipali42siwnwD3hBIo9ngOUyIzBXZu2+xCfoFZnkbHo9a3eqQQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792481138; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=lfp58XwQi70g7NLqVgPwHNlO3lGqNpuNaYUDj97KvYY=; b=XPaIzA1HTex8kbznt8kKcSfxyVN2Hi70PAJWnaXUvH3zEsjDARFC75+btQ5oCvA8/3N/ m/fsRNm/f1V9S/2ldIsEEq/dz8qzSdfnVmXvLeXd+0sgiYEP2sYCx1LpGA4wBM+eNGd6y JX0u9bhDR9/2t5XuuG8NtKWjz7bEChRmQYpUvvuYiWFUbhI5hdTa6Ww4mT03Rzm3m24qa wRyCaNLwj2PbRY9S1Yf83bfBtYzl395Z5asqODYktuovQwOJxuyayDqZccX8yNxwkyY5X WY0IwVeIDYyJPqICRA9ZV4y1xD/SL+KzTkt6gw5BcgeDVBnPEZIDnR2V9XfoTxfQ7NQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="EPRS/1Rj"; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A43EF60A260A; Tue, 20 Oct 2026 07:25:38 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EPRS/1Rj X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792481137; b=bib1nt5281N3YqBDIqudPxMwWksxvY9vnD+tg07UaPtc4wRBJVS8D8t1upiKPNgtdYtk i0+PF0ZuzR7JVeWBEiXd6BDsOhQyzfGw02obT56SerQM+c+UmqOKkVj4qkyG+heXp4cn2 bDaWhKmRlHpExlQR+v41Uj0ihW6BCPQTfZ5GFYf9B3cWQOm7QVqd1oa5WwRLvuYBRPL41 Yvug+DEcP9cBxWc6KSYHew6CgKMnbnFYj2mbElsRRfMU83OEnFY25exh7FY/jwffPMH8g fKhzycCuBOFdWRoWO8/0tBX9WkC+TBbJQGrsIl2YwcDpVbIXDXgNHPDrTXo2OmkkyZg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792481137; 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=lfp58XwQi70g7NLqVgPwHNlO3lGqNpuNaYUDj97KvYY=; b=NQ4Q5O9OL9XJ2BXdomvVtj2mC1x3Ih63VkIb2sWEXkR1L+TNEy+cXpbDP1E7z/oz0Avx sIK+LBgXqUEoQIHwm8uqLvJxp9fGkN83sPXssw0Tu6gX+y3C/d7fEzlbPkLt77c6sj9cD /kFPu9rij6cMPXIo9JADkmdFkCbO/Xgk6j2qTMNeVnL93ngO1eMxAM3BFLV3MD0jALhk0 S/RhmzRKDBAjmKHsZVjc+MIKdPY/OV4AkMZhLvpkHuIpCKuAh6Ro+vQal2WTNrIwKibCr twUuJeNeisjdEBPjsJ0s9Kfj9Eyo5n52uvyKkzfu6g0IZ5aPqEjqSasKm9zfF8kiTCQ== X-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="EPRS/1Rj"; arc=none smtp.remote-ip=100.103.45.18 X-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 80A48606A33A for <netdev@vger.kernel.org>; Tue, 20 Oct 2026 07:25:37 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 928571F000C6; Tue, 20 Oct 2026 07:25:36 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792481137; bh=lfp58XwQi70g7NLqVgPwHNlO3lGqNpuNaYUDj97KvYY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=EPRS/1RjpS5N5xK7XrhqtsfWzWxGJHhLOtp5rAWrSX97U1iMIKXyCPdu8x2njqbU1 2S+hhFJauJ+ePl02MDCABlViSW+FiiAhaWXO/tRMawcDLySr0t4FyXOoe/7DLVvyhj 97fyM7wTuzCBVjPkMh+4IfKafz7CUSjyMglehP1RsrYgDz15RFs+FXYOcSXGHG/mep iwglMxftT9nRukwc9gLPQ7w46WwYglV+mMclvHKw65NAKcx/l1m09+v2YA09KkXJg4 CeJQYABTmfpXV9SuLPl9w8flFlqS7Y44JE6z8YJvoNbSTLIzxGf2CqsuQZd1ywDvK1 tKz9Urvmxmxog== X-Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew+netdev@lunn.ch, pavan.chebbi@broadcom.com, andrew.gospodarek@broadcom.com X-In-Reply-To: <20261016064427.496944-9-michael.chan@broadcom.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list