From: netdev-bot+sashiko@kernel.org
To: x-professor@outlook.com
Cc: netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, hannes@cmpxchg.org,
mhocko@kernel.org, roman.gushchin@linux.dev,
shakeel.butt@linux.dev, muchun.song@linux.dev,
akpm@linux-foundation.org, vdavydov.dev@gmail.com,
cgroups@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 3/3] net: multicast: account group and source allocations to memcg
Date: Mon, 23 Nov 2026 16:24:06 +0000 [thread overview]
Message-ID: <179545104659.3135.11573235607470978138@kernel.org> (raw)
In-Reply-To: <eabf67fe94dc239f6cc59720e8468f2bf9b4cd62.1795102467.git.x-professor@outlook.com>
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] The fix leaves the IPv4 device group records uncharged, even
though their IPv6 counterparts are now charged.
- [Medium] Several IPv6 allocations whose failure is always silently
ignored now use GFP_KERNEL_ACCOUNT, so they can fail on memcg charge…
--
net: multicast: account group and source allocations to memcg
This commit adds memcg accounting to the IPv4 and IPv6 multicast source
filter entries and their tomb records. It also accounts the IPv6 live and
deleted device group records. IPv4 keeps GFP_ATOMIC and adds __GFP_ACCOUNT,
IPv6 switches to GFP_KERNEL_ACCOUNT, and a gfp parameter is passed through
__ipv6_dev_mc_inc() and mca_alloc() so that only socket joins charge the
live IPv6 group.
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> index ede1f0825bad5..e7afe61871132 100644
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
[ ... ]
> @@ -232,7 +233,7 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex,
> RCU_INIT_POINTER(mc_lst->sflist, NULL);
>
> /* now add/increase the group membership on the device */
> - err = __ipv6_dev_mc_inc(dev, addr, mode);
> + err = __ipv6_dev_mc_inc(dev, addr, mode, GFP_KERNEL_ACCOUNT);
>
> dev_put(dev);
>
[Severity: High]
The IPv6 socket join now charges the live ifmcaddr6 group record. What
about the IPv4 equivalents?
__ip_mc_join_group() in net/ipv4/igmp.c still creates the live ip_mc_list
without accounting:
net/ipv4/igmp.c:__ip_mc_join_group() {
...
rcu_assign_pointer(inet->mc_list, iml);
____ip_mc_inc_group(in_dev, addr, mode, GFP_KERNEL);
...
}
____ip_mc_inc_group() then allocates the record with
kzalloc_obj(*im, gfp).
The IPv4 deleted group record is also left uncharged. On leave or close
the chain is:
ip_mc_leave_group() / ip_mc_drop_socket()
ip_mc_dec_group()
igmp_group_dropped()
__igmp_group_dropped(im, GFP_KERNEL)
igmpv3_add_delrec(in_dev, im, gfp)
pmc = kzalloc_obj(*pmc, gfp);
Its IPv6 counterpart, mld_add_delrec(), is switched to GFP_KERNEL_ACCOUNT
by this patch.
These tomb records stay on in_dev->mc_tomb until crcount counts down
through IGMPv3 interface-change reports. crcount comes from in_dev->mr_qrv
or the per-netns igmp_qrv sysctl. igmp_max_memberships does not limit
these records.
Could a user namespace root in its own netns raise igmp_qrv and the report
interval, and then join and leave distinct groups in a loop? That would
pile up uncharged ip_mc_list records in the same way as the delayed MLD
join/leave reproducer in the commit message, which this patch fixes only
for IPv6.
The commit message gives this reason for charging the IPv6 join:
"socket joins already propagate allocation failure to the caller"
That is not true for IPv4, since ____ip_mc_inc_group() returns void. It
might explain leaving out the IPv4 live group. It does not explain leaving
out the deleted record, because igmpv3_add_delrec() already ignores
allocation failure the same way mld_add_delrec() does.
Should the IPv4 group records be charged too? For example, an accounted
gfp could be passed to igmpv3_add_delrec() on socket paths, and the IPv4
join could either propagate the failure or force the charge. If they are
left out on purpose, could the commit message say why?
> @@ -770,7 +771,7 @@ static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
> * for deleted items allows change reports to use common code with
> * non-deleted or query-response MCA's.
> */
> - pmc = kzalloc_obj(*pmc);
> + pmc = kzalloc_obj(*pmc, GFP_KERNEL_ACCOUNT);
> if (!pmc)
> return;
>
[Severity: Medium]
With GFP_KERNEL_ACCOUNT, can this allocation now fail when the memcg
charge fails?
For requests without __GFP_HIGH or __GFP_NOFAIL, try_charge_memcg()
returns -ENOMEM in several cases:
- the current task is an OOM victim with MMF_OOM_SKIP
- passed_oom && task_is_dying()
- mem_cgroup_oom() makes no progress
The relevant check is:
mm/memcontrol.c:try_charge_memcg() {
...
if (!(gfp_mask & (__GFP_NOFAIL | __GFP_HIGH))) {
ret = -ENOMEM;
goto out;
}
...
}
mld_add_delrec() returns void and just returns when the allocation fails.
In that case no deleted group record is created, and the MLDv2 leave
state-change report is never sent.
A typical case is an OOM-killed task in a memcg that exits and closes its
multicast sockets:
ipv6_sock_mc_close() / __ipv6_sock_mc_drop()
__ipv6_dev_mc_dec()
igmp6_group_dropped()
igmp6_leave_group()
mld_add_delrec()
kzalloc_obj(*pmc, GFP_KERNEL_ACCOUNT) returns NULL
The tomb allocations this patch changes in ip6_mc_del1_src() and
sf_setstate() look similar.
In ip6_mc_del1_src(), when dpsf is NULL, psf is still unlinked and freed
with rv = 0, so the source removal is never announced.
In sf_setstate(), this check drops the record:
if (!dpsf)
continue;
The IPv4 tomb conversions avoid this, because GFP_ATOMIC includes
__GFP_HIGH and the charge is forced.
mld_add_delrec() also hardcodes GFP_KERNEL_ACCOUNT, but non-socket callers
reach it through igmp6_group_dropped(). Examples are __ipv6_dev_mc_dec()
called from addrconf, ndisc and the bridge, as well as ipv6_mc_down() and
ipv6_mc_unmap(). On those paths, isn't the deleted record charged to
whichever task happens to trigger the operation?
That seems to conflict with the commit message, which keeps GFP_KERNEL
for:
"ipv6_dev_mc_inc() callers such as address configuration, which may
ignore allocation failure"
It also says:
"A group created by address configuration stays uncharged"
Would it make sense for callers to pass a gfp into mld_add_delrec(), as
igmpv3_add_delrec() already takes one on the IPv4 side?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795102467.git.x-professor%40outlook.com
prev parent reply other threads:[~2026-11-23 16:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 15:34 [PATCH net 0/3] net: account socket and multicast " Yingjie Wang
2026-11-19 15:34 ` [PATCH net 1/3] net: multicast: keep source filter state when a source update fails Yingjie Wang
2026-11-23 16:24 ` netdev-bot+sashiko
2026-11-19 15:34 ` [PATCH net 2/3] net: account IPV6_2292PKTOPTIONS and multicast socket state to memcg Yingjie Wang
2026-11-23 16:24 ` netdev-bot+sashiko
2026-11-19 15:34 ` [PATCH net 3/3] net: multicast: account group and source allocations " Yingjie Wang
2026-11-23 16:24 ` netdev-bot+sashiko [this message]
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=179545104659.3135.11573235607470978138@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=vdavydov.dev@gmail.com \
--cc=x-professor@outlook.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
all inboxes | Powered by JetHome®