Re: [PATCH net-next v10 10/10] bnge: add cpu_rmap support for IRQ affinity
From: Vikas Gupta
Date: Sun Nov 29 2026 - 20:47:39 EST
Hi,
There is a valid issue (High) in this patch so I will send v11.
Thanks,
Vikas
On Sun, Nov 29, 2026 at 6:16 PM <netdev-bot+sashiko@xxxxxxxxxx> wrote:
>
> 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] RX ring 0's slot in the aRFS cpu_rmap is never filled, so aRFS
> still steers flows on ring 0's CPU to the wrong RX queue.
> - [Medium] The teardown in bnge_free_cpu_rmap() assumes each reader loads
> rx_cpu_rmap once, but set_rps_cpu() loads it twice.
>
> --
>
> bnge: add cpu_rmap support for IRQ affinity
>
> When CONFIG_RFS_ACCEL and NTUPLE are enabled, this patch allocates a
> cpu_rmap for the RX IRQ vectors, which turns aRFS on for bnge. At open,
> NQ0 (requested at probe) is added to the rmap first, so each vector's
> rmap index matches its RX ring index. If adding an IRQ to the rmap fails,
> aRFS is turned off for all rings.
>
> > diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> > index de7320521a3e0..b031b3c0af0b4 100644
> > --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> > +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
>
> [ ... ]
>
> > @@ -2569,6 +2583,50 @@ 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 sequence give the protection the comment describes?
>
> set_rps_cpu() in net/core/dev.c loads dev->rx_cpu_rmap twice, with two
> separate plain loads:
>
> net/core/dev.c:set_rps_cpu() {
> ...
> if (!skb_rx_queue_recorded(skb) || !dev->rx_cpu_rmap ||
> ...
> rxq_index = cpu_rmap_lookup_index(dev->rx_cpu_rmap, next_cpu);
> ...
> }
>
> Suppose the WRITE_ONCE(..., NULL) above lands on another CPU between
> those two loads. The reader passes the NULL check, then reloads NULL, and
> cpu_rmap_lookup_index() dereferences a NULL rmap. Because
> synchronize_net() runs after the store, it can't prevent this.
>
> To hit this, a reader has to be in set_rps_cpu() for this netdev while
> bnge_free_cpu_rmap() runs. That can happen from
> bnge_close_core()->bnge_free_irq(), or from the irq_cpu_rmap_add()
> failure path in bnge_nq_add_cpu_rmap().
>
> bnge's own NAPI is already disabled by then. Skbs injected into the
> device with a recorded rx queue can still reach get_rps_cpu(), though.
> One example is a TC bpf_redirect() with BPF_F_INGRESS into bnge, which
> goes through __dev_forward_skb()->netif_rx(). is_skb_forwardable() only
> checks IFF_UP, and __dev_close_many() clears that flag only after
> ndo_stop returns. This also needs RPS/RFS and NTUPLE to be configured,
> and the window is narrow.
>
> The double load is in core code. Would set_rps_cpu() need to read
> rx_cpu_rmap once with READ_ONCE() for this teardown to be safe? If not,
> should the comment here be changed so it doesn't overstate what the
> sequence guarantees?
>
> [ ... ]
>
> > @@ -2616,6 +2678,13 @@ static int bnge_request_irq(struct bnge_net *bn)
> > netdev_err(bn->netdev, "bnge_setup_interrupts err: %d\n", rc);
> > return rc;
> > }
> > +
> > + /* NQ0 is requested at probe, before the rmap exists, and is not one
> > + * of the open NQs below. Add it first, so that the rmap index of
> > + * every vector is its RX ring index.
> > + */
> > + bnge_nq_add_cpu_rmap(bn, bn->bnapi[0]);
>
> [Severity: High]
> Does RX ring 0's slot in the rmap ever get filled in?
>
> NQ0's vector was bound and given its affinity hint at probe, while
> dev->rx_cpu_rmap was still NULL:
>
> bnge_nq0_init()
> bnge_nq_request_irq()
> bnge_nq_add_cpu_rmap() <- returns early, rmap is NULL
> request_irq()
> irq_set_affinity_hint(irq->vector, irq->cpu_mask)
>
> At open, irq_cpu_rmap_add() only calls cpu_rmap_add() and
> irq_set_affinity_notifier(). irq_set_affinity_notifier() installs
> desc->affinity_notify but does not schedule an initial notification.
> irq_set_affinity_locked() schedules one only when the affinity changes.
> So it looks like cpu_rmap_update(rmap, 0, ...) never runs for NQ0.
>
> This also goes against the kernel-doc for irq_cpu_rmap_add():
>
> Must be called in process context, after the IRQ is allocated but
> before it is bound with request_irq().
>
> The open NQs avoid this, because bnge_nq_request_irq() adds the notifier
> before it calls irq_set_affinity_hint().
>
> alloc_irq_cpu_rmap() starts every CPU at CPU_RMAP_DIST_INF. When rings
> 1..N-1 get their notifications, NQ0's CPU would therefore be assigned to
> the nearest other ring.
>
> For flows consumed on ring 0's CPU, wouldn't
> set_rps_cpu()->cpu_rmap_lookup_index() then return some ring k != 0?
> bnge_rx_flow_steer() would then program the NTUPLE filter for that other
> ring.
>
> free_irq_cpu_rmap() removes NQ0's notifier at close. That means this
> would happen again on every open, unless something outside the driver
> changes NQ0's affinity (irqbalance, or a write to /proc/irq).
>
> The comment above and the commit message say the NQ0 handling stops aRFS
> from steering flows to the wrong RX queue. The slot order looks right,
> but slot 0 doesn't seem to get populated.
>
> Could NQ0's affinity be applied again after irq_cpu_rmap_add() succeeds?
> One option is to call irq_set_affinity_hint() again for NQ0's vector.
> Another is to seed slot 0 directly with cpu_rmap_update() from the IRQ's
> current affinity.
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125115434.2080590-1-vikas.gupta%40broadcom.com
pw-bot: cr
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature