๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by netdev-bot+sashiko Tue, 24 Nov 2026 02:10
Re: [PATCH net-next v5 5/9] bnxt_en: Reinit IRQ when configuring LRO/GRO/HDS
#21469
Author: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 02:10
160 lines
13238 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message understates the bug being fixed.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but this patch
  sends more paths into it.

--

bnxt_en: Reinit IRQ when configuring LRO/GRO/HDS

When LRO/GRO/HDS is enabled, new RX aggregation rings may be needed. The
FW may grant fewer rings than requested, and then the number of channels
shrinks. The patch sets irq_re_init in bnxt_set_features() and
bnxt_set_ringparam() so that the IRQs and NAPIs are rebuilt when agg rings
are newly needed.

> Without
> this patch, when the driver is eventually shutdown, some memory for the
> unused NAPIs may never be freed properly if the rings have shrunk.

[Severity: Low]
Does this describe the pre-patch behavior accurately? It reads more like
a use-after-free than a leak.

Before this patch, the sequence looks like this:

bnxt_set_features() / bnxt_set_ringparam()
  close/open with irq_re_init == false
    bp->bnapi is kept, NAPIs for the old cp_nr_rings stay registered
  __bnxt_reserve_rings()
    BNXT_FLAG_AGG_RINGS is set, FW grants fewer rings
    bp->rx_nr_rings and bp->cp_nr_rings shrink

Then the next close with irq_re_init == true (ndo_stop, remove, ...) runs:

__bnxt_close_nic()
  bnxt_free_irq()      <- loops only to the reduced bp->cp_nr_rings
  bnxt_del_napi()      <- same bound
  bnxt_free_mem()
    kfree(bp->bnapi);  <- single block holding every bnxt_napi

The napi_structs above the reduced count would stay linked on
dev->napi_list after their memory is freed. Their IRQs would also stay
requested, with dev_id pointing into the freed block.

Later walks of dev->napi_list would then read freed memory. Examples are
netif_napi_dev_list_add() from the next bnxt_init_napi(), and
netif_napi_del() from free_netdev().

Could the commit message call this a use-after-free, so stable and
distro reviewers can see it is a memory safety fix?

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index f4eff048eea5a..887a67d42bb37 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c

[ ... ]

> @@ -14184,8 +14185,12 @@ static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
>  		update_tpa = true;
>  		if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
>  		    (flags & BNXT_FLAG_TPA) == 0 ||
> -		    (bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
> +		    (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)) {
>  			re_init = true;
> +			if (!(bp->flags & BNXT_FLAG_AGG_RINGS) &&
> +			    (flags & BNXT_FLAG_AGG_RINGS))
> +				irq_re_init = true;
> +		}
>  	}

[ ... ]

> @@ -14208,7 +14213,7 @@ static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
>  			return bnxt_reinit_features(bp, true, false, flags, update_tpa);
>  
>  		if (re_init)
> -			return bnxt_reinit_features(bp, false, false, flags, update_tpa);
> +			return bnxt_reinit_features(bp, irq_re_init, false, flags, update_tpa);

[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but this
patch sends more paths into it.

irq_re_init can now be true here, and in bnxt_set_ringparam() when
tcp-data-split is enabled. That means ethtool -K gro/lro on and ethtool -G
tcp-data-split on now reach the part of __bnxt_close_nic() that frees
bp->bnapi and the ring stats. Existing triggers already include
set_channels, change_mtu, the ntuple toggle and FW reset.

That free path is protected against stats readers by a single shared
state bit:

bnxt_get_stats64() {
	set_bit(BNXT_STATE_READ_STATS, &bp->state);
	smp_mb__after_atomic();
	if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
		clear_bit(BNXT_STATE_READ_STATS, &bp->state);
		...
	}
	bnxt_sync_ring_stats(bp);
	bnxt_get_ring_stats(bp, stats);
	...
	clear_bit(BNXT_STATE_READ_STATS, &bp->state);
}

__bnxt_close_nic() {
	clear_bit(BNXT_STATE_OPEN, &bp->state);
	smp_mb__after_atomic();
	while (bnxt_drv_busy(bp))
		msleep(20);
	...
	if (irq_re_init) {
		bnxt_free_irq(bp);
		bnxt_del_napi(bp);
	}
	bnxt_free_mem(bp, irq_re_init);
}

Stats readers such as /proc/net/dev and the sysfs statistics files can run
at the same time, and they do not hold RTNL. What happens when there are
two readers?

reader A                         reader B
set_bit(READ_STATS)              set_bit(READ_STATS)
sees OPEN                        sees OPEN
bnxt_get_ring_stats()            bnxt_get_ring_stats()
  (preempted mid-walk)           clear_bit(READ_STATS)

__bnxt_close_nic()
  clear_bit(OPEN)
  bnxt_drv_busy() returns false
  bnxt_free_mem(bp, true)
    kfree(bp->bnapi)

reader A resumes
  bp->bnapi[i]->cp_ring.stats    <- freed or NULL

Can reader A end up dereferencing freed bnapi or stats memory in
bnxt_get_ring_stats() here?

Would a real lock or RCU in bnxt_get_stats64() and __bnxt_close_nic() be
a better fit than the BNXT_STATE_READ_STATS bit?

>  
>  		if (update_tpa) {
>  			bp->flags = flags;

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120012921.2537903-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