Skip to content

Commit 9ab6a99

Browse files
sreekanthbrcmgregkh
authored andcommitted
bnxt_en: Fix memory corruption when FW resources change during ifdown
[ Upstream commit 2747328 ] bnxt_set_dflt_rings() assumes that it is always called before any TC has been created. So it doesn't take bp->num_tc into account and assumes that it is always 0 or 1. In the FW resource or capability change scenario, the FW will return flags in bnxt_hwrm_if_change() that will cause the driver to reinitialize and call bnxt_cancel_reservations(). This will lead to bnxt_init_dflt_ring_mode() calling bnxt_set_dflt_rings() and bp->num_tc may be greater than 1. This will cause bp->tx_ring[] to be sized too small and cause memory corruption in bnxt_alloc_cp_rings(). Fix it by properly scaling the TX rings by bp->num_tc in the code paths mentioned above. Add 2 helper functions to determine bp->tx_nr_rings and bp->tx_nr_rings_per_tc. Fixes: ec5d31e ("bnxt_en: Handle firmware reset status during IF_UP.") Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com> Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com> Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Link: https://patch.msgid.link/20250825175927.459987-2-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1228285 commit 9ab6a99

File tree

1 file changed

+16
-5
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+16
-5
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12844,6 +12844,17 @@ static int bnxt_set_xps_mapping(struct bnxt *bp)
1284412844
return rc;
1284512845
}
1284612846

12847+
static int bnxt_tx_nr_rings(struct bnxt *bp)
12848+
{
12849+
return bp->num_tc ? bp->tx_nr_rings_per_tc * bp->num_tc :
12850+
bp->tx_nr_rings_per_tc;
12851+
}
12852+
12853+
static int bnxt_tx_nr_rings_per_tc(struct bnxt *bp)
12854+
{
12855+
return bp->num_tc ? bp->tx_nr_rings / bp->num_tc : bp->tx_nr_rings;
12856+
}
12857+
1284712858
static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
1284812859
{
1284912860
int rc = 0;
@@ -16338,7 +16349,7 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
1633816349
bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings);
1633916350
bp->rx_nr_rings = bp->cp_nr_rings;
1634016351
bp->tx_nr_rings_per_tc = bp->cp_nr_rings;
16341-
bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
16352+
bp->tx_nr_rings = bnxt_tx_nr_rings(bp);
1634216353
}
1634316354

1634416355
static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
@@ -16370,7 +16381,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1637016381
bnxt_trim_dflt_sh_rings(bp);
1637116382
else
1637216383
bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
16373-
bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
16384+
bp->tx_nr_rings = bnxt_tx_nr_rings(bp);
1637416385

1637516386
avail_msix = bnxt_get_max_func_irqs(bp) - bp->cp_nr_rings;
1637616387
if (avail_msix >= BNXT_MIN_ROCE_CP_RINGS) {
@@ -16383,7 +16394,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1638316394
rc = __bnxt_reserve_rings(bp);
1638416395
if (rc && rc != -ENODEV)
1638516396
netdev_warn(bp->dev, "Unable to reserve tx rings\n");
16386-
bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
16397+
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
1638716398
if (sh)
1638816399
bnxt_trim_dflt_sh_rings(bp);
1638916400

@@ -16392,7 +16403,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1639216403
rc = __bnxt_reserve_rings(bp);
1639316404
if (rc && rc != -ENODEV)
1639416405
netdev_warn(bp->dev, "2nd rings reservation failed.\n");
16395-
bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
16406+
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
1639616407
}
1639716408
if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
1639816409
bp->rx_nr_rings++;
@@ -16426,7 +16437,7 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp)
1642616437
if (rc)
1642716438
goto init_dflt_ring_err;
1642816439

16429-
bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
16440+
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
1643016441

1643116442
bnxt_set_dflt_rfs(bp);
1643216443

0 commit comments

Comments
 (0)