From: netdev-bot+sashiko@kernel.org
To: vikas.gupta@broadcom.com
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bhargava.marreddy@broadcom.com, rahul-rg.gupta@broadcom.com,
vsrama-krishna.nemani@broadcom.com,
rajashekar.hudumula@broadcom.com, dharmender.garg@broadcom.com,
ajit.khaparde@broadcom.com
Subject: Re: [PATCH net-next v9 10/10] bnge: add cpu_rmap support for IRQ affinity
Date: Tue, 24 Nov 2026 10:20:38 +0000 [thread overview]
Message-ID: <179551563894.3135.1768774823155933236@kernel.org> (raw)
In-Reply-To: <20261123100746.1975030-11-vikas.gupta@broadcom.com>
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
prev parent reply other threads:[~2026-11-24 10:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 10:07 [PATCH net-next v9 00/10] add features to bnge Vikas Gupta
2026-11-23 10:07 ` [PATCH net-next v9 01/10] bnge: restructure VNIC and filter code Vikas Gupta
2026-11-23 10:07 ` [PATCH net-next v9 02/10] bnge: add NTUPLE/ARFS VNIC Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko
2026-11-23 10:07 ` [PATCH net-next v9 03/10] bnge: add helper functions for multi RSS contexts Vikas Gupta
2026-11-23 10:07 ` [PATCH net-next v9 04/10] bnge: add RXFH ethtool support Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko
2026-11-23 10:07 ` [PATCH net-next v9 05/10] bnge: add ethtool support to manage RSS contexts Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko
2026-11-23 10:07 ` [PATCH net-next v9 06/10] bnge: remove refcount from L2 filter Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko
2026-11-23 10:07 ` [PATCH net-next v9 07/10] bnge: add NTUPLE filter infrastructure Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko
2026-11-23 10:07 ` [PATCH net-next v9 08/10] bnge: add NTUPLE filter support in ethtool Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko
2026-11-23 10:07 ` [PATCH net-next v9 09/10] bnge: add aRFS flow steering ndo support Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko
2026-11-23 10:07 ` [PATCH net-next v9 10/10] bnge: add cpu_rmap support for IRQ affinity Vikas Gupta
2026-11-24 10:20 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179551563894.3135.1768774823155933236@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=ajit.khaparde@broadcom.com \
--cc=andrew+netdev@lunn.ch \
--cc=bhargava.marreddy@broadcom.com \
--cc=davem@davemloft.net \
--cc=dharmender.garg@broadcom.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rahul-rg.gupta@broadcom.com \
--cc=rajashekar.hudumula@broadcom.com \
--cc=vikas.gupta@broadcom.com \
--cc=vsrama-krishna.nemani@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox