bnxt_en: 3 bug fixes
Michael Chan
maintainercover bnxt_en: 3 bug fixes
The first one fixes a memory corruption issue that can happen when FW resources change during ifdown with TCs created. The next two fix FW resource reservation logic for TX rings and stats context.
Michael Chan (2):
bnxt_en: Adjust TX rings if reservation is less than requested
bnxt_en: Fix stats context reservation logic
Sreekanth Reddy (1):
bnxt_en: Fix memory corruption when FW resources change during ifdown
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 36 +++++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-)
Signature · 1 line
2.30.1
Michael Chan
maintainerPATCH 1/3 bnxt_en: Fix memory corruption when FW resources change during ifdown
From: Sreekanth Reddy <[email protected]>
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.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +16 -5
@@ -12851,6 +12851,17 @@ static int bnxt_set_xps_mapping(struct bnxt *bp)return rc; } +static int bnxt_tx_nr_rings (struct bnxt *bp) +{ +return bp->num_tc ? bp->tx_nr_rings_per_tc * bp->num_tc : + bp->tx_nr_rings_per_tc; +} + +static int bnxt_tx_nr_rings_per_tc (struct bnxt *bp) +{ +return bp->num_tc ? bp->tx_nr_rings / bp->num_tc : bp->tx_nr_rings; +} +static int __bnxt_open_nic (struct bnxt *bp,bool irq_re_init,bool link_re_init) {int rc =0 ;
@@ -16325,7 +16336,7 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp) bp->cp_nr_rings =min_t (int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings); bp->rx_nr_rings = bp->cp_nr_rings; bp->tx_nr_rings_per_tc = bp->cp_nr_rings; - bp->tx_nr_rings = bp->tx_nr_rings_per_tc; + bp->tx_nr_rings =bnxt_tx_nr_rings (bp); }static int bnxt_set_dflt_rings (struct bnxt *bp,bool sh)
@@ -16357,7 +16368,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)bnxt_trim_dflt_sh_rings (bp); else bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings; - bp->tx_nr_rings = bp->tx_nr_rings_per_tc; + bp->tx_nr_rings =bnxt_tx_nr_rings (bp); avail_msix =bnxt_get_max_func_irqs (bp) - bp->cp_nr_rings;if (avail_msix >=BNXT_MIN_ROCE_CP_RINGS ) {
@@ -16370,7 +16381,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) rc =__bnxt_reserve_rings (bp);if (rc && rc != -ENODEV )netdev_warn (bp->dev,"Unable to reserve tx rings\n" ); - bp->tx_nr_rings_per_tc = bp->tx_nr_rings; + bp->tx_nr_rings_per_tc =bnxt_tx_nr_rings_per_tc (bp);if (sh)bnxt_trim_dflt_sh_rings (bp);
@@ -16379,7 +16390,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) rc =__bnxt_reserve_rings (bp);if (rc && rc != -ENODEV )netdev_warn (bp->dev,"2nd rings reservation failed.\n" ); - bp->tx_nr_rings_per_tc = bp->tx_nr_rings; + bp->tx_nr_rings_per_tc =bnxt_tx_nr_rings_per_tc (bp); }if (BNXT_CHIP_TYPE_NITRO_A0 (bp)) { bp->rx_nr_rings++;
@@ -16413,7 +16424,7 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp)if (rc) goto init_dflt_ring_err; - bp->tx_nr_rings_per_tc = bp->tx_nr_rings; + bp->tx_nr_rings_per_tc =bnxt_tx_nr_rings_per_tc (bp);bnxt_set_dflt_rfs (bp);
Signature · 1 line
2.30.1
Michael Chan
maintainerPATCH 2/3 bnxt_en: Adjust TX rings if reservation is less than requested
In reply to Michael ChanBefore we accept an ethtool request to increase a resource (such as rings), we call the FW to check that the requested resource is likely available first before we commit. But it is still possible that the actual reservation or allocation can fail. The existing code is missing the logic to adjust the TX rings in case the reserved TX rings are less than requested. Add a warning message (a similar message for RX rings already exists) and add the logic to adjust the TX rings. Without this fix, the number of TX rings reported to the stack can exceed the actual TX rings and ethtool -l will report more than the actual TX rings.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +12 -0
@@ -8024,6 +8024,11 @@ static int __bnxt_reserve_rings(struct bnxt *bp) hwr.rx = rx_rings <<1 ; tx_cp =bnxt_num_tx_to_cp (bp, hwr.tx); hwr.cp = sh ?max_t (int, tx_cp, rx_rings) : tx_cp + rx_rings; +if (hwr.tx != bp->tx_nr_rings) { +netdev_warn (bp->dev, +"Able to reserve only %d out of %d requested TX rings\n" , + hwr.tx, bp->tx_nr_rings); + } bp->tx_nr_rings = hwr.tx;/* If we cannot reserve all the RX rings, reset the RSS map only
@@ -12879,6 +12884,13 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)if (rc)return rc; +/* 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) { + bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc; + bp->tx_nr_rings += bp->tx_nr_rings_xdp; + } rc =bnxt_alloc_mem (bp, irq_re_init);if (rc) {netdev_err (bp->dev,"bnxt_alloc_mem err: %x\n" , rc);
Signature · 1 line
2.30.1
Michael Chan
maintainerPATCH 3/3 bnxt_en: Fix stats context reservation logic
In reply to Michael ChanThe HW resource reservation logic allows the L2 driver to use the RoCE resources if the RoCE driver is not registered. When calculating the stats contexts available for L2, we should not blindly subtract the stats contexts reserved for RoCE unless the RoCE driver is registered. This bug may cause the L2 rings to be less than the number requested when we are close to running out of stats contexts.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
@@ -8016,7 +8016,8 @@ static int __bnxt_reserve_rings(struct bnxt *bp) } rx_rings =min_t (int, rx_rings, hwr.grp); hwr.cp =min_t (int, hwr.cp, bp->cp_nr_rings); -if (hwr.stat >bnxt_get_ulp_stat_ctxs (bp)) +if (bnxt_ulp_registered (bp->edev) && + hwr.stat >bnxt_get_ulp_stat_ctxs (bp)) hwr.stat -=bnxt_get_ulp_stat_ctxs (bp); hwr.cp =min_t (int, hwr.cp, hwr.stat); rc =bnxt_trim_rings (bp, &rx_rings, &hwr.tx, hwr.cp, sh);
Signature · 1 line
2.30.1
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 25 Aug 2025 10:59:24 -0700 you wrote:
The first one fixes a memory corruption issue that can happen when FW resources change during ifdown with TCs created. The next two fix FW resource reservation logic for TX rings and stats context.
Michael Chan (2):
bnxt_en: Adjust TX rings if reservation is less than requested
bnxt_en: Fix stats context reservation logic[...]
Here is the summary with links:
- [net,1/3] bnxt_en: Fix memory corruption when FW resources change during ifdown
https://git.kernel.org/netdev/net/c/2747328ba271 - [net,2/3] bnxt_en: Adjust TX rings if reservation is less than requested https://git.kernel.org/netdev/net/c/1ee581c24dfd
- [net,3/3] bnxt_en: Fix stats context reservation logic
https://git.kernel.org/netdev/net/c/b4fc8faacfea
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html