Re: [PATCH net-next v8 10/10] bnge: add cpu_rmap support for IRQ affinity

From: netdev-bot+sashiko

Date: Thu Nov 19 2026 - 12:10:19 EST


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] bnge_free_cpu_rmap()
(drivers/net/ethernet/broadcom/bnge/bnge_netdev.c) tears down…

--

bnge: add cpu_rmap support for IRQ affinity

This patch allocates and fills a cpu_rmap for the bnge RX IRQ vectors
when CONFIG_RFS_ACCEL is set. That sets dev->rx_cpu_rmap and turns aRFS
on for the driver. It also adds bnge_free_cpu_rmap(), which clears and
frees the rmap from bnge_free_irq().

> diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> index 0e7c506af402c..507f920ea1d3f 100644
> --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c

[ ... ]

> @@ -2496,12 +2510,35 @@ static void bnge_hwrm_resource_free(struct bnge_net *bn, bool close_path)
> bnge_hwrm_stat_ctx_free(bn);
> }
>
> +#ifdef CONFIG_RFS_ACCEL
> +/* set_rps_cpu() reads rx_cpu_rmap under rcu_read_lock(). Hide the pointer and
> + * wait for readers that already loaded it before the rmap is freed.
> + */
> +static void bnge_free_cpu_rmap(struct bnge_net *bn)
> +{
> + struct cpu_rmap *rmap = bn->netdev->rx_cpu_rmap;
> +
> + if (!rmap)
> + return;
> +
> + WRITE_ONCE(bn->netdev->rx_cpu_rmap, NULL);
> + synchronize_net();
> + free_irq_cpu_rmap(rmap);
> +}

[Severity: Low]
Does the reader in set_rps_cpu() give the guarantee this comment relies
on?

The ordering here does prevent a use-after-free. However, set_rps_cpu()
in net/core/dev.c does not take a single snapshot of the pointer. It
loads dev->rx_cpu_rmap twice with plain loads, with no READ_ONCE() and
no __rcu annotation:

net/core/dev.c:set_rps_cpu() {
...
if (!skb_rx_queue_recorded(skb) || !dev->rx_cpu_rmap ||
!(dev->features & NETIF_F_NTUPLE))
goto out;
rxq_index = cpu_rmap_lookup_index(dev->rx_cpu_rmap, next_cpu);
...
}

Suppose the WRITE_ONCE() above lands between those two loads. The
reader then passes the NULL check and calls cpu_rmap_lookup_index()
with a NULL rmap. synchronize_net() does not help here, because the
reader is already inside its RCU section. The race is between the two
loads, not between the reader and the free.

The teardown runs from ndo_stop:

bnge_close()->bnge_close_core()->bnge_free_irq()->bnge_free_cpu_rmap()

IFF_UP is still set at this point. That means skbs injected into the
bnge ingress path, for example via bpf_redirect() with BPF_F_INGRESS,
dev_forward_skb() or tc mirred ingress, could still reach
netif_rx()->get_rps_cpu()->set_rps_cpu() for this device.

In practice the compiler will most likely merge the two loads into one.
If so, the visible result would be a KCSAN data race report against
this WRITE_ONCE() rather than an oops. Before this patch bnge never set
rx_cpu_rmap, so set_rps_cpu() always took the early exit for this
device.

Would it make sense to have set_rps_cpu() take one READ_ONCE() snapshot
of dev->rx_cpu_rmap? Alternatively, the driver could avoid clearing the
pointer while readers can still run. Either way, the comment above
should probably be adjusted to match.

> +#else
> +static void bnge_free_cpu_rmap(struct bnge_net *bn)
> +{
> +}
> +#endif
> +
> static void bnge_free_irq(struct bnge_net *bn)
> {
> struct bnge_dev *bd = bn->bd;
> struct bnge_irq *irq;
> int i;
>
> + bnge_free_cpu_rmap(bn);
> +

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116140653.1685797-1-vikas.gupta%40broadcom.com