Skip to content

Commit d00e989

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 3d6a89f commit d00e989

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • drivers/net/ethernet/broadcom/bnxt

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

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

12244+
static int bnxt_tx_nr_rings(struct bnxt *bp)
12245+
{
12246+
return bp->num_tc ? bp->tx_nr_rings_per_tc * bp->num_tc :
12247+
bp->tx_nr_rings_per_tc;
12248+
}
12249+
12250+
static int bnxt_tx_nr_rings_per_tc(struct bnxt *bp)
12251+
{
12252+
return bp->num_tc ? bp->tx_nr_rings / bp->num_tc : bp->tx_nr_rings;
12253+
}
12254+
1224412255
static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
1224512256
{
1224612257
int rc = 0;
@@ -15676,7 +15687,7 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
1567615687
bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings);
1567715688
bp->rx_nr_rings = bp->cp_nr_rings;
1567815689
bp->tx_nr_rings_per_tc = bp->cp_nr_rings;
15679-
bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
15690+
bp->tx_nr_rings = bnxt_tx_nr_rings(bp);
1568015691
}
1568115692

1568215693
static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
@@ -15708,7 +15719,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1570815719
bnxt_trim_dflt_sh_rings(bp);
1570915720
else
1571015721
bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
15711-
bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
15722+
bp->tx_nr_rings = bnxt_tx_nr_rings(bp);
1571215723

1571315724
avail_msix = bnxt_get_max_func_irqs(bp) - bp->cp_nr_rings;
1571415725
if (avail_msix >= BNXT_MIN_ROCE_CP_RINGS) {
@@ -15721,7 +15732,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1572115732
rc = __bnxt_reserve_rings(bp);
1572215733
if (rc && rc != -ENODEV)
1572315734
netdev_warn(bp->dev, "Unable to reserve tx rings\n");
15724-
bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
15735+
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
1572515736
if (sh)
1572615737
bnxt_trim_dflt_sh_rings(bp);
1572715738

@@ -15730,7 +15741,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1573015741
rc = __bnxt_reserve_rings(bp);
1573115742
if (rc && rc != -ENODEV)
1573215743
netdev_warn(bp->dev, "2nd rings reservation failed.\n");
15733-
bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
15744+
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
1573415745
}
1573515746
if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
1573615747
bp->rx_nr_rings++;
@@ -15764,7 +15775,7 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp)
1576415775
if (rc)
1576515776
goto init_dflt_ring_err;
1576615777

15767-
bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
15778+
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
1576815779

1576915780
bnxt_set_dflt_rfs(bp);
1577015781

0 commit comments

Comments
 (0)