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

From: netdev-bot+sashiko

Date: Tue Nov 24 2026 - 05:21:19 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] Off-by-one between aRFS rmap slots and RX queues: RX ring 0's
vector is never added to dev->rx_cpu_rmap, so every rule the kernel…
- [Medium] bnge_free_cpu_rmap() assumes each reader loads
dev->rx_cpu_rmap once, but set_rps_cpu() loads it twice.

--

bnge: add cpu_rmap support for IRQ affinity

This patch allocates dev->rx_cpu_rmap when NTUPLE is enabled under
CONFIG_RFS_ACCEL. It adds each RX ring's IRQ vector to the rmap when the
open-time IRQs are requested, and frees the rmap in bnge_free_irq(). This
is the patch that turns on aRFS for bnge.

> diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> index de7320521a3e0..dcd073d8bdfac 100644
> --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c

[ ... ]

> @@ -2569,15 +2583,53 @@ static void bnge_nq_free_irq(struct bnge_net *bn, struct bnge_napi *bnapi)
> irq->requested = 0;
> }
>
> +#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: Medium]
Does this teardown hold up given how set_rps_cpu() reads the pointer? The
comment assumes each reader loads dev->rx_cpu_rmap once. set_rps_cpu() in
net/core/dev.c loads it twice, both times with plain loads:

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);
...
}

cpu_rmap_lookup_index() dereferences rmap->near[cpu] without checking for
NULL.

Suppose a reader passes the NULL check before the WRITE_ONCE() and does
the second load after it. Wouldn't it dereference NULL? synchronize_net()
only delays the free, so it can't close that window.

bnge_close_core() disables NAPI before it calls bnge_free_irq(), so the
device's own RX path is quiet by then. But IFF_UP is still set during
ndo_stop. A netif_rx() caller can still reach
get_rps_cpu()->set_rps_cpu() when RFS is configured, if skb->dev is this
netdev and queue_mapping is recorded. One example is multicast loopback
of a forwarded packet via dev_loopback_xmit(), which keeps the ingress
queue_mapping.

If such a reader exists, this code turns a use-after-free into a window
for a NULL dereference. If no such reader can exist, then the
synchronize_net() and the comment aren't needed for the reason the
comment gives.

Could set_rps_cpu() load the pointer once with READ_ONCE(), or use proper
RCU annotation? Separately, could the comment here avoid claiming
protection it doesn't provide?

[ ... ]

> static int bnge_nq_request_irq(struct bnge_net *bn, struct bnge_napi *bnapi)
> {
> int map_idx = bnapi->nq_ring.ring_struct.map_idx;
> + struct cpu_rmap *rmap = NULL;
> struct bnge_dev *bd = bn->bd;
> struct bnge_irq *irq;
> int rc;
>
> +#ifdef CONFIG_RFS_ACCEL
> + rmap = bn->netdev->rx_cpu_rmap;
> +#endif
> +
> irq = &bd->irq_tbl[map_idx];
>
> + if (IS_ENABLED(CONFIG_RFS_ACCEL) &&
> + rmap && bnapi->rx_ring) {
> + rc = irq_cpu_rmap_add(rmap, irq->vector);

[Severity: High]
Is RX ring 0's vector ever added to the rmap?

bnge_alloc_core() makes NQ0 bnapi[0] and binds the RX rings starting at
index 0:

bn->bnapi[0] = bn->nq0;
...
bn->bnapi[i]->rx_ring = &bn->rx_ring[i];

So NQ0 (irq_tbl[0]) services RX ring 0.

NQ0's IRQ is only requested at probe, through
bnge_nq0_init()->bnge_nq_request_irq(). At that point dev->rx_cpu_rmap
and nq0->rx_ring are both NULL, so this block is skipped.

At open, bnge_setup_interrupts() allocates an rmap with bd->rx_nr_rings
slots. bnge_request_irq() then walks only bnge_for_each_open_nq(), which
starts at BNGE_FIRST_OPEN_NQ (1). cpu_rmap_add() hands out the first free
slot. RX ring 1's vector gets slot 0, ring 2's gets slot 1, and so on, and
the last slot stays empty.

Now suppose next_cpu in set_rps_cpu() is the affinity CPU of ring k+1's
vector. cpu_rmap_lookup_index() returns k, and bnge_rx_flow_steer()
writes:

new_fltr->base.rxq = rxq_index;

The flow then lands on ring k, whose IRQ is affined to
cpumask_local_spread(k) rather than next_cpu. On later packets rxq_index
matches skb_get_rx_queue(skb), so set_rps_cpu() leaves the wrong
placement in place.

The commit message says the rmap lets aRFS "correctly map flows to the RX
queues serviced by the nearest CPU". It also guards against a later ring
taking a free slot and mapping "to the wrong RX queue". Doesn't the
missing ring 0 cause that same shift on every open when there is more
than one RX ring?

One possible fix is to add irq_tbl[0]'s vector for RX ring 0 at open
time, before the open NQs. NQ0's IRQ stays requested across close, so its
affinity notifier would also need to be cleared at close.

[ ... ]

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