* [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users
@ 2026-05-22 9:39 Yuyang Huang
2026-05-22 10:38 ` Jiayuan Chen
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Yuyang Huang @ 2026-05-22 9:39 UTC (permalink / raw)
To: Yuyang Huang
Cc: Jiayuan Chen, David S. Miller, David Ahern, Eric Dumazet,
Ido Schimmel, Jakub Kicinski, Paolo Abeni, Simon Horman,
linux-kernel, netdev
/proc/net/igmp walks IPv4 multicast memberships under RCU and
prints im->users without holding RTNL, while multicast join and leave
paths update the field while holding RTNL. Annotate this intentional
lockless snapshot with READ_ONCE() and the matching writers with
WRITE_ONCE().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
---
Changes in v2:
- Added Fixes: tag
net/ipv4/igmp.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 27d120183779..f2aca659b29c 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1541,7 +1541,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
}
if (im) {
- im->users++;
+ WRITE_ONCE(im->users, im->users + 1);
ip_mc_add_src(in_dev, &addr, mode, 0, NULL, 0);
goto out;
}
@@ -1550,7 +1550,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
if (!im)
goto out;
- im->users = 1;
+ WRITE_ONCE(im->users, 1);
im->interface = in_dev;
in_dev_hold(in_dev);
im->multiaddr = addr;
@@ -1784,7 +1784,10 @@ void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp)
(i = rtnl_dereference(*ip)) != NULL;
ip = &i->next_rcu) {
if (i->multiaddr == addr) {
- if (--i->users == 0) {
+ int new_users = i->users - 1;
+
+ WRITE_ONCE(i->users, new_users);
+ if (new_users == 0) {
ip_mc_hash_remove(in_dev, i);
*ip = i->next_rcu;
in_dev->mc_count--;
@@ -2977,7 +2980,7 @@ static int igmp_mc_seq_show(struct seq_file *seq, void *v)
delta = im->timer.expires - jiffies;
seq_printf(seq,
"\t\t\t\t%08X %5d %d:%08lX\t\t%d\n",
- im->multiaddr, im->users,
+ im->multiaddr, READ_ONCE(im->users),
im->tm_running,
im->tm_running ? jiffies_delta_to_clock_t(delta) : 0,
im->reporter);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users
2026-05-22 9:39 [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users Yuyang Huang
@ 2026-05-22 10:38 ` Jiayuan Chen
2026-05-22 11:07 ` Eric Dumazet
2026-05-24 13:59 ` Ido Schimmel
2026-05-25 18:30 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 7+ messages in thread
From: Jiayuan Chen @ 2026-05-22 10:38 UTC (permalink / raw)
To: Yuyang Huang
Cc: Jiayuan Chen, David S. Miller, David Ahern, Eric Dumazet,
Ido Schimmel, Jakub Kicinski, Paolo Abeni, Simon Horman,
linux-kernel, netdev
On 5/22/26 5:39 PM, Yuyang Huang wrote:
> /proc/net/igmp walks IPv4 multicast memberships under RCU and
> prints im->users without holding RTNL, while multicast join and leave
> paths update the field while holding RTNL. Annotate this intentional
> lockless snapshot with READ_ONCE() and the matching writers with
> WRITE_ONCE().
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users
2026-05-22 10:38 ` Jiayuan Chen
@ 2026-05-22 11:07 ` Eric Dumazet
0 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2026-05-22 11:07 UTC (permalink / raw)
To: Jiayuan Chen
Cc: Yuyang Huang, David S. Miller, David Ahern, Ido Schimmel,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev
On Fri, May 22, 2026 at 3:38 AM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>
>
> On 5/22/26 5:39 PM, Yuyang Huang wrote:
> > /proc/net/igmp walks IPv4 multicast memberships under RCU and
> > prints im->users without holding RTNL, while multicast join and leave
> > paths update the field while holding RTNL. Annotate this intentional
> > lockless snapshot with READ_ONCE() and the matching writers with
> > WRITE_ONCE().
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
>
>
> Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users
2026-05-22 9:39 [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users Yuyang Huang
2026-05-22 10:38 ` Jiayuan Chen
@ 2026-05-24 13:59 ` Ido Schimmel
2026-05-24 14:05 ` Yuyang Huang
2026-05-25 18:30 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 7+ messages in thread
From: Ido Schimmel @ 2026-05-24 13:59 UTC (permalink / raw)
To: Yuyang Huang
Cc: Jiayuan Chen, David S. Miller, David Ahern, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev
On Fri, May 22, 2026 at 06:39:06PM +0900, Yuyang Huang wrote:
> /proc/net/igmp walks IPv4 multicast memberships under RCU and
> prints im->users without holding RTNL, while multicast join and leave
> paths update the field while holding RTNL. Annotate this intentional
> lockless snapshot with READ_ONCE() and the matching writers with
> WRITE_ONCE().
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> ---
> Changes in v2:
> - Added Fixes: tag
>
> net/ipv4/igmp.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index 27d120183779..f2aca659b29c 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c
> @@ -1541,7 +1541,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
> }
>
> if (im) {
> - im->users++;
> + WRITE_ONCE(im->users, im->users + 1);
> ip_mc_add_src(in_dev, &addr, mode, 0, NULL, 0);
> goto out;
> }
> @@ -1550,7 +1550,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
> if (!im)
> goto out;
>
> - im->users = 1;
> + WRITE_ONCE(im->users, 1);
This one isn't necessary since the object was just allocated and not yet
published
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users
2026-05-24 13:59 ` Ido Schimmel
@ 2026-05-24 14:05 ` Yuyang Huang
2026-05-25 14:02 ` Ido Schimmel
0 siblings, 1 reply; 7+ messages in thread
From: Yuyang Huang @ 2026-05-24 14:05 UTC (permalink / raw)
To: Ido Schimmel
Cc: Jiayuan Chen, David S. Miller, David Ahern, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev
>This one isn't necessary since the object was just allocated and not yet
>published
Thanks for the comment. I did consider not modifying it when writing
the patch, but decided to keep it for consistency, it makes the code
easier to reason about later. If you feel strongly about removing it,
I'm happy to send a v3.
On Sun, May 24, 2026 at 10:59 PM Ido Schimmel <idosch@nvidia.com> wrote:
>
> On Fri, May 22, 2026 at 06:39:06PM +0900, Yuyang Huang wrote:
> > /proc/net/igmp walks IPv4 multicast memberships under RCU and
> > prints im->users without holding RTNL, while multicast join and leave
> > paths update the field while holding RTNL. Annotate this intentional
> > lockless snapshot with READ_ONCE() and the matching writers with
> > WRITE_ONCE().
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
>
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
>
> > ---
> > Changes in v2:
> > - Added Fixes: tag
> >
> > net/ipv4/igmp.c | 11 +++++++----
> > 1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> > index 27d120183779..f2aca659b29c 100644
> > --- a/net/ipv4/igmp.c
> > +++ b/net/ipv4/igmp.c
> > @@ -1541,7 +1541,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
> > }
> >
> > if (im) {
> > - im->users++;
> > + WRITE_ONCE(im->users, im->users + 1);
> > ip_mc_add_src(in_dev, &addr, mode, 0, NULL, 0);
> > goto out;
> > }
> > @@ -1550,7 +1550,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
> > if (!im)
> > goto out;
> >
> > - im->users = 1;
> > + WRITE_ONCE(im->users, 1);
>
> This one isn't necessary since the object was just allocated and not yet
> published
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users
2026-05-24 14:05 ` Yuyang Huang
@ 2026-05-25 14:02 ` Ido Schimmel
0 siblings, 0 replies; 7+ messages in thread
From: Ido Schimmel @ 2026-05-25 14:02 UTC (permalink / raw)
To: Yuyang Huang
Cc: Jiayuan Chen, David S. Miller, David Ahern, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev
On Sun, May 24, 2026 at 11:05:43PM +0900, Yuyang Huang wrote:
> >This one isn't necessary since the object was just allocated and not yet
> >published
>
> Thanks for the comment. I did consider not modifying it when writing
> the patch, but decided to keep it for consistency, it makes the code
> easier to reason about later. If you feel strongly about removing it,
> I'm happy to send a v3.
I don't think it's worth another version. Personally I wouldn't add
WRITE_ONCE() where it's not necessary.
P.S. Please don't top post.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users
2026-05-22 9:39 [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users Yuyang Huang
2026-05-22 10:38 ` Jiayuan Chen
2026-05-24 13:59 ` Ido Schimmel
@ 2026-05-25 18:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-25 18:30 UTC (permalink / raw)
To: Yuyang Huang
Cc: jiayuan.chen, davem, dsahern, edumazet, idosch, kuba, pabeni,
horms, linux-kernel, netdev
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 22 May 2026 18:39:06 +0900 you wrote:
> /proc/net/igmp walks IPv4 multicast memberships under RCU and
> prints im->users without holding RTNL, while multicast join and leave
> paths update the field while holding RTNL. Annotate this intentional
> lockless snapshot with READ_ONCE() and the matching writers with
> WRITE_ONCE().
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
>
> [...]
Here is the summary with links:
- [net-next,v2] ipv4: igmp: annotate data-races around im->users
https://git.kernel.org/netdev/net-next/c/061c0aa740d5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-05-25 18:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-22 9:39 [PATCH net-next v2] ipv4: igmp: annotate data-races around im->users Yuyang Huang
2026-05-22 10:38 ` Jiayuan Chen
2026-05-22 11:07 ` Eric Dumazet
2026-05-24 13:59 ` Ido Schimmel
2026-05-24 14:05 ` Yuyang Huang
2026-05-25 14:02 ` Ido Schimmel
2026-05-25 18:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox