Article View: linux.kernel.netdev
Article #1201Re: [PATCH net-next v10 3/6] net: add a generation counter for dev->mc changes
From: netdev-bot+sashiko
Date: Fri, 09 Oct 2026 11:58
Date: Fri, 09 Oct 2026 11:58
137 lines
11189 bytes
11189 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 1
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).
- [Medium] netlink: AF_PACKET multicast dump misses changes due to
reading sequence after loop
- [Low] __hw_addr_changed() (net/core/dev_addr_lists.c) does
atomic_inc(&dev_net(list->mc_dev)->dev_mc_genid).
--
net: add a generation counter for dev->mc changes
This commit adds a per netns generation counter, dev_mc_genid, that is
bumped whenever an entry is added to or removed from any dev->mc list.
To find the netns, netdev_hw_addr_list gets an mc_dev pointer, which is
set only for dev->mc, and the count helpers bump
dev_net(mc_dev)->dev_mc_genid. The counter will be used by a following
patch for the AF_PACKET multicast dump.
> diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
> index d615192d1c3b1..3ab053cbf8b99 100644
> --- a/net/core/dev_addr_lists.c
> +++ b/net/core/dev_addr_lists.c
> @@ -16,9 +16,19 @@
>
> #include "dev.h"
>
> +/* RTM_GETMULTICAST dumps use the netns generation counter to detect
> + * changes of dev->mc between dump rounds.
> + */
> +static void __hw_addr_changed(struct netdev_hw_addr_list *list)
> +{
> + if (list->mc_dev)
> + atomic_inc(&dev_net(list->mc_dev)->dev_mc_genid);
[Severity: Medium]
This counter only catches changes if the dump samples it before it
walks the lists, but the user in the following patch seems to sample it
afterwards. dev_mc_dump() assigns cb->seq from
dev_mc_base_seq(filter.tgt_net) only after the for_each_netdev_dump()
loop has finished.
The reader holds netif_addr_lock_bh() while it walks each dev->mc, so
the ordering of the atomic_inc() against the list update is not the
problem. The problem is the window between releasing the address lock
of the last device dumped in a round and taking the sample. For
example:
- a round fills the skb partway through eth0's dev->mc and stops,
recording the resume position
- eth0's addr_list_lock is released
- another CPU deletes an eth0 entry that sits before the resume
position and bumps dev_mc_genid
- dev_mc_dump() then stores the already bumped value in cb->seq
- the next round resumes eth0 at the stored position and skips one
entry, but the genid it sees matches the value stamped at the end
of the previous round, so nl_dump_check_consistent() has nothing
to flag and NLM_F_DUMP_INTR is never set
An add in the same window gives a duplicated entry instead. Either way
user space receives an inconsistent dump with no hint that it should
retry, which is what this counter is meant to prevent.
The commit message names inet_base_seq() as the model. In
inet_dump_ifaddr() it is sampled under rcu_read_lock() before
for_each_netdev_dump() is entered, so any change made during or after
the traversal shows up as a different value in the next round. Should
dev_mc_dump() take its sample before the loop in the same way?
[Severity: Low]
Is dev_net() safe to use here? __hw_addr_changed() runs with only the
device's addr_list_lock held. __dev_change_net_namespace() switches
dev->nd_net under RTNL and netdev_lock(dev), and it never takes
addr_list_lock:
net/core/dev.c:__dev_change_net_namespace() {
...
netdev_lock(dev);
dev_net_set(dev, net);
netdev_unlock(dev);
...
}
So a dev->mc writer that holds neither RTNL nor the instance lock can
run at the same time as a netns move. The rxe driver looks like one such
caller:
rxe_attach_mcast()
rxe_get_mcg()
rxe_mcast_add()
dev_mc_add(ndev)
__dev_mc_add()
__hw_addr_add_ex()
__hw_addr_count_inc()
__hw_addr_changed()
dev_net(ndev)
rxe_mcast_add() only holds the reference it gets from
ib_device_get_netdev(). On NETDEV_UNREGISTER, rxe_notify() only queues
the ib device unregistration, and rxe_net_del() does not clear the port
netdev. That means this path can still run while something like
"ip link set <ndev> netns X" executes.
dev_net() is read_pnet(), which does a plain load through
rcu_dereference_protected(pnet->net, true). That load races with the
rcu_assign_pointer() in dev_net_set().
Would KCSAN report this as a data race? And could the increment then
land on the old netns's dev_mc_genid instead of the new one?
The old struct net can't be freed under the BH-disabled spinlock, and
dev_base_seq covers the device appearing in the new netns. So the impact
looks limited to the race report and one bump going to the wrong netns.
Would dev_net_rcu() be a better fit for this reader?
> +}
> +
> static void __hw_addr_count_add(struct netdev_hw_addr_list *list, int value)
> {
> list->_count += value;
> + __hw_addr_changed(list);
> }
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261007115821.11332-1-sigefriedhyy%40gmail.com
Technical Details
Message-ID:
<179154713053.434549.11454657718901075006@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-343614-linux-kernel-netdev=dewy.ruReferences:
<20261007115821.11332-4-sigefriedhyy@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-343614-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v10 3/6] net: add a generation counter for dev->mc changes Date: Fri, 09 Oct 2026 11:58:50 +0000 Organization: Usenet Network Message-ID: <179154713053.434549.11454657718901075006@kernel.org> References: <20261007115821.11332-4-sigefriedhyy@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1098860"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:N/b6cj26JNpB/B+8YKRSQc2A4MA= sha256:OVeq/2pnvNnkUCyQoT+/WFe6CXZqlywRE3T4hSRYRmk= sha1:eQUHWq0YL7C7/4mtR+/n0BSLgKI= sha256:EzYTGK6WetZd6660nzu97A9teX6rf7Q5c3kyS954ESQ= 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 3DFFD10F66E; Fri, 9 Oct 2026 15:12:49 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.64 X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.241, 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, URIBL_BLOCKED=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 pvSdG1NRJAGD; Fri, 9 Oct 2026 15:12:45 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-343614-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 4B23A10F5B8; Fri, 9 Oct 2026 15:12:38 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id C737B61CE7; Fri, 9 Oct 2026 12:04:30 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BD914DEC3B; Fri, 9 Oct 2026 11:58:58 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Eie1cvU8" X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FB364D7D2C; Fri, 9 Oct 2026 11:58:52 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791547137; cv=none; b=tQ/YPgXL3KNRxzYwIPSzJtMbNQCeseq5PY1z2YUUOz+fCgBQXTvxGLuzilq4VCiIxEDpMwoiSR8NVJkPlvcYyypc/++2qeGDOJixFXxyacS3S1nhBO+D1uHs1mhq0TpbMg2sDjnkXYZpWvbNorS568H//VTZQoRBDtTId6QhN5o= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791547137; c=relaxed/simple; bh=keCw4JklAnUtBzjIBtrgg0wyQxcqkxo6DfAROena4CM=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Fw+sgsnd++3PEQsaO6iVVWlKP1G8KkI9MbSh9qheiMkC5B38/MBc5GTHWM2dA/9pOJYxKrnmwYek6qkvUIzp/k+0+fbBHcSLa88w5rlPv/dV9msRu7Jvzvk2SPDXSa/Cj5yuO19JCnpMW5XBOKS3CTKy36bNwK/gPtlLigYIx7c= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Eie1cvU8; arc=none smtp.client-ip=100.103.45.18 X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id F00631F00893; Fri, 9 Oct 2026 11:58:50 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791547132; bh=XjSa8BZ6E/qZMUBiBDIIDAIfAUgfdrDgAn/Tx1MO5sA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Eie1cvU88zwby0sCcUEIPMTCyeouw0+rOY7811AXsiMZ+7vTzU2g+i+lL7mk7P/iN /FxKslyew7BwA+0xb3GvdF2U5IIIxFmRpU4RkRs12E7N64yRWPXej0OQX7CgMCdwXv hS5GpNYelivOO+aTmMT9JntK4w3EsODJ9vSXZ20xKnjwehGWXOFe7h1aZANjFZY9CT LHWve2U65A9Dbyn9BG+t+73LvcnJmMTXytcMCKDV874Y0SPLRXaJYlFmZavxUZcqiJ MrMwQyyTF3c1z/V2+AfLLxk5F03/HgX6YiaifpqqGkq3rmtdKYpWklsPO4CJrovzGh Be5cE/YgxHOQA== X-Cc: ajay.kathat@microchip.com, aleksandr.loktionov@intel.com, andrew+netdev@lunn.ch, claudiu.beznea@tuxon.dev, davem@davemloft.net, dsahern@kernel.org, donald.hunter@gmail.com, edumazet@google.com, idosch@nvidia.com, jacob.e.keller@intel.com, kuba@kernel.org, johannes@sipsolutions.net, kees@kernel.org, kory.maincent@bootlin.com, kuniyu@google.com, nicolas.dichtel@6wind.com, nickgarlis@gmail.com, pabeni@redhat.com, sd@queasysnail.net, shuah@kernel.org, horms@kernel.org, sdf.kernel@gmail.com, vadim.fedorenko@linux.dev, willemb@google.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org X-In-Reply-To: <20261007115821.11332-4-sigefriedhyy@gmail.com> X-sashiko-severity: Medium X-Precedence: bulk X-Mailing-List: netdev@vger.kernel.org X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>