๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24150

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

#24150
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 12:46
154 lines
13949 bytes
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
Technical Details
Message-ID: <179595640978.3146.2248814989251776899@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373497-linux-kernel-netdev=dewy.ru
References: <20261125115434.2080590-11-vikas.gupta@broadcom.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373497-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v10 10/10] bnge: add cpu_rmap support for IRQ affinity
Date: Sun, 29 Nov 2026 12:46:49 +0000
Organization: Usenet Network
Message-ID: <179595640978.3146.2248814989251776899@kernel.org>
References: <20261125115434.2080590-11-vikas.gupta@broadcom.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="1169917"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:JRvxUZ+T38dgaMLxhNaRBESvxNM= sha256:dP63L1BDvnodK39+FvnqGU7pH8KMjZE56noGmgeJJU8= sha1:hhhLL3opgl007osEouG4cGjjmYs= sha256:Gjq1BeXAZSXOjBDYWQlorf7sMsX2w5uBXfDOAeGC7XQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 85A2C125CEE; Sun, 29 Nov 2026 15:47:21 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jzc6Bupj8Vyr; Sun, 29 Nov 2026 15:47:18 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373497-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id B5261125F96; Sun, 29 Nov 2026 15:47:09 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 1198F26438; Sun, 29 Nov 2026 12:46:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795956412; b=j2WJHPGs9NCPfXhe5kjgmH0Wk9gb/VoZRm/6jh5Irfg0kmSfF9qJM1uZr8dL4FjsHCwF ZgJbZuyq2jus4cMkGB1MSS3dB11v1ytQVZSo0kmJprS6CFlOyzRY/UpmXnriP+CZj5QUc Xt4eKQ1VfOovFB8quOw6T4WXqzgoISDja273XkhO4SGL+foZM/kQxdXi/FL9sHIxwARIE chPcdY14QqPcIDcc8AnV70G61zHz8RKipMn6vpDmpRIdAu3PPoMlCEHbm8i1XshxlFrpG MnTHjPUQYNrmn+w2rBMQXwM2gXO1rQBAu0HbpKqz+ppRfzT7ypf2E5/dSkwEWcgMhNA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795956412; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=VW/eXYWLLPmQlrGFsh1P3LlOUlWYI6XawYe3DEuNBi8=; b=joDTppCTN9eKPiklyL3EGrclgNHkq2PNbvi2BuFs6Kp5FOmXL1siX3pZzg7AM4rz2hm/ 25t1CV1n54eJlPePmQfVNXgwLu+7sk3lvvTkYl+TtPl6PDoIeBu6YAmA+rCNaW5YuzM8l BD7vdC2tz/Q46RjFTfLZeM11/o7Zy/WERRpBKvz7nhgvKSMw2LUL0gV+6TGBW45sjWTxj Yd66nQeYauXJRbN047KoFT9gniW5GEcue3eS0eNrJ3bBN26DJP7r1Tkwd+hjc/IwbHplQ 4DK/LVtYAh+6s5r8UGtV/tre5vtfGlQf6NyfuhHFgTZOxqwkbrkUIPb2HTzHOscxXSA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=efynjgDO; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F248606A338; Sun, 29 Nov 2026 12:46:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=efynjgDO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795956411; b=GoeLMw2vyOlxHwySQ8oShiH1QfGTtje9EwNJqXXLvwpmZfkiXWsShqU3ItgwdUU9VF20 AuDcMTH6DJ8c11oOWQj/3sBeUVM/7tETCeYg9fJlUIRuQvxw3LTCMmo2jf1ucM7QhqqnQ 28zS8fQN7g/3OjqzBaHIBsjHsUiYiKst8XgfaBsYyrYdrRd87P07OPbk2vQhT5I9UUjbG 7kqeuyvi6opmaS+uf0Am/dbNrHD1q6mFYq8jaATK9L0+7tUpiEM0Rr2H6r67ffmU1FoSe SwoXPA0K+9lTddgupc1t4Mtdt3X+uumIP9B/r9DC2fuH1xAkH8CPqiQ5+dJJYtorrbw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795956411; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=VW/eXYWLLPmQlrGFsh1P3LlOUlWYI6XawYe3DEuNBi8=; b=M47REjTcQS1hHTY5x8HjLfagNBHBNTTM8HfHR9vEgi/TBTBoKhwNRmmtwh9zEd6CdeEH N48hERm1ha+l37ON/5PQXV0Jr+2Amc7OrU7jSWPDoIadBG8OeR1a2+TqDpib76K4WJkg7 gp/tWlGMeSB3H3HBuYfQDfVXVnT9Ra4u5JoSUAp3roPmMQPDVzwRJ6BKFoTQWTnqwIMbV zn3b+Ax04MiU0eG14pyq6LltWtkAmxwBMgGvKhRGOyTtE2h3r4FO1sYOZKh/sa1lDUIfY ZUDipiQLA2fkm9FJF+44yGEna4Hd4ZkyPfI+IzcARjIdPfdHHjPU2lS8Rper+hxllww==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=efynjgDO; arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FFDD606A686; Sun, 29 Nov 2026 12:46:51 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 395E51F00898; Sun, 29 Nov 2026 12:46:50 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795956411; bh=VW/eXYWLLPmQlrGFsh1P3LlOUlWYI6XawYe3DEuNBi8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=efynjgDOArUY7XU1X98Qdu4EipDmWnZfWyqsdL798zhmdIJ3VQO74M63z6hCcYcum RpIKApeumaaVgQiZ3deE4Kp7OM2c6PgMzBPcHqIAWtnRqg/oJ2hzcmom039k2rPBRD 6GU8QdD1wZflssZZHFSzVcX+d4FQKTVJrAepInMr/i6mr2aju8ubRnhVEl3ZiVxsHV 6PIApzYTVJTEM0d/0/KcwF4iUwFGBQnAa62AEh3j2bRglpCQG8Sjvv9Sc9VUeukRSJ IftVEhPikvb99FZw3XCMxUfUXfC3YATqzThEK5gSpcJLaBEatUAptkQpxGhbgZhiUG 5UfT6CtciMUkw==
X-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
X-In-Reply-To: <20261125115434.2080590-11-vikas.gupta@broadcom.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list