Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by netdev-bot+sashiko
Tue, 20 Oct 2026 07:25
Re: [PATCH net-next v4 8/8] bnxt_en: Fix ring accounting and validation when rings are constrained
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads