From: netdev-bot+sashiko@kernel.org
To: sigefriedhyy@gmail.com
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
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 [thread overview]
Message-ID: <179154713053.434549.11454657718901075006@kernel.org> (raw)
In-Reply-To: <20261007115821.11332-4-sigefriedhyy@gmail.com>
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
next prev parent reply other threads:[~2026-10-09 11:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 11:58 [PATCH net-next v10 0/6] rtnetlink: dump link-layer multicast addresses Yuyang Huang
2026-10-07 11:58 ` [PATCH net-next v10 1/6] netlink: specs: rt-addr: fix the type of target-netnsid Yuyang Huang
2026-10-09 11:58 ` netdev-bot+sashiko
2026-10-07 11:58 ` [PATCH net-next v10 2/6] net: change netdev_hw_addr_list count through helpers Yuyang Huang
2026-10-07 11:58 ` [PATCH net-next v10 3/6] net: add a generation counter for dev->mc changes Yuyang Huang
2026-10-09 9:50 ` Nicolas Dichtel
2026-10-09 11:58 ` netdev-bot+sashiko [this message]
2026-10-07 11:58 ` [PATCH net-next v10 4/6] net: add AF_PACKET multicast dumps Yuyang Huang
2026-10-09 9:57 ` Nicolas Dichtel
2026-10-09 11:58 ` netdev-bot+sashiko
2026-10-07 11:58 ` [PATCH net-next v10 5/6] netlink: specs: rt-addr: document " Yuyang Huang
2026-10-07 11:58 ` [PATCH net-next v10 6/6] selftests: net: test " Yuyang Huang
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=179154713053.434549.11454657718901075006@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=ajay.kathat@microchip.com \
--cc=aleksandr.loktionov@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=claudiu.beznea@tuxon.dev \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jacob.e.keller@intel.com \
--cc=johannes@sipsolutions.net \
--cc=kees@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nickgarlis@gmail.com \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
--cc=sdf.kernel@gmail.com \
--cc=shuah@kernel.org \
--cc=sigefriedhyy@gmail.com \
--cc=vadim.fedorenko@linux.dev \
--cc=willemb@google.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