From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Yuyang Huang <sigefriedhyy@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Ido Schimmel <idosch@nvidia.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next] ipv4: igmp: annotate data-races around im->users
Date: Thu, 21 May 2026 18:53:27 +0800 [thread overview]
Message-ID: <a6e9081a-b2d9-4a51-a7eb-aaf27a50fe1f@linux.dev> (raw)
In-Reply-To: <20260521093612.207475-1-sigefriedhyy@gmail.com>
On 5/21/26 5:36 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().
>
> Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
> ---
> 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) {
Using a local variable here feels slightly awkward, but it does save one
extra load compared
to re-reading i->users after the WRITE_ONCE(), so it's acceptable.
One suggestion: please add a Fixes: tag, like other data-race fixes
annotated with READ_ONCE()/WRITE_ONCE().
next prev parent reply other threads:[~2026-05-21 10:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 9:36 [PATCH net-next] ipv4: igmp: annotate data-races around im->users Yuyang Huang
2026-05-21 10:53 ` Jiayuan Chen [this message]
2026-05-21 11:02 ` Uyo Ko
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=a6e9081a-b2d9-4a51-a7eb-aaf27a50fe1f@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sigefriedhyy@gmail.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