From: sashiko-bot@kernel.org
To: "Yingjie Wang" <x-professor@outlook.com>
Cc: "David Ahern" <dsahern@kernel.org>,
"Ido Schimmel" <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Willem de Bruijn" <willemb@google.com>,
"Simon Horman" <horms@kernel.org>,
"Binbin Deng" <18983559317@163.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Hocko" <mhocko@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
tj@kernel.org, mkoutny@suse.com
Subject: Re: [PATCH net-next v2 3/3] net: multicast: account device records created by sockets to memcg
Date: Sun, 06 Dec 2026 08:19:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-252269@kernel.org> (raw)
In-Reply-To: <20261205081925.2230129-1-x-professor@outlook.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] net: igmp: GFP_ATOMIC | __GFP_ACCOUNT force-charges past
memory.max
- [High] net: multicast: GFP_KERNEL_ACCOUNT tombstones trigger memcg OOM
on close/exit
- [Medium] net: multicast: sf_setstate() charges memcg on non-socket
group joins
- [Medium] net: multicast: blocking memcg charge loops stall rtnl_lock
and mc_lock
--
commit 5c15b2b8f2430c6138cc500d32bf6bfa76cf5b05
Author: Yingjie Wang <x-professor@outlook.com>
net: multicast: account device records created by sockets to memcg
This commit charges IPv4 and IPv6 multicast device group records, source
entries, and deleted-record tombstones created by socket operations to the
caller's memory cgroup, and makes ____ip_mc_inc_group() return an error so
IPv4 socket joins fail with -ENOBUFS on allocation failure.
> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index 1ed7192e7cd6f..eb48c940397a3 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c
[ ... ]
> @@ -2062,7 +2061,9 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,
> #ifdef CONFIG_IP_MULTICAST
> if (psf->sf_oldin &&
> !IGMP_V1_SEEN(in_dev) && !IGMP_V2_SEEN(in_dev)) {
> - struct ip_sf_list *dpsf = kmalloc_obj(*dpsf, GFP_ATOMIC);
> + struct ip_sf_list *dpsf;
> +
> + dpsf = kmalloc_obj(*dpsf, GFP_ATOMIC | __GFP_ACCOUNT);
>
> if (dpsf) {
> *dpsf = *psf;
[Severity: High]
Can GFP_ATOMIC | __GFP_ACCOUNT here (and in ip_mc_add1_src() and
sf_setstate()) allow an unprivileged task to force-charge unbounded
struct ip_sf_list records past memory.max?
Because GFP_ATOMIC includes __GFP_HIGH, try_charge_memcg() skips reclaim
and OOM and unconditionally force-charges past memory.max without failing.
In ip_mc_source(), once psl is allocated on the first IP_BLOCK_SOURCE,
alternating IP_UNBLOCK_SOURCE and IP_BLOCK_SOURCE for distinct sources
reuses psl in place with zero blocking GFP_KERNEL_ACCOUNT allocations.
Each IP_UNBLOCK_SOURCE appends a force-charged dpsf to pmc->tomb and
postpones in_dev->mr_ifc_timer via igmp_ifc_start_timer(), preventing
pmc->tomb from draining while the loop runs. This defeats memory.max
isolation and contradicts the commit message claim that unchargeable
deleted records are not created.
Using GFP_NOWAIT | __GFP_ACCOUNT (without __GFP_HIGH) for the optional
tombstones in ip_mc_del1_src() and sf_setstate(), and either
GFP_NOWAIT | __GFP_ACCOUNT or preallocation outside pmc->lock for
ip_mc_add1_src(), would let try_charge_memcg() fail at memory.max.
[ ... ]
> @@ -2923,7 +2929,9 @@ void ip_mc_drop_socket(struct sock *sk)
> in_dev = inetdev_by_index(net, iml->multi.imr_ifindex);
> (void) ip_mc_leave_src(sk, iml, in_dev);
> if (in_dev)
> - ip_mc_dec_group(in_dev, iml->multi.imr_multiaddr.s_addr);
> + __ip_mc_dec_group(in_dev,
> + iml->multi.imr_multiaddr.s_addr,
> + GFP_KERNEL_ACCOUNT);
> /* decrease mem now to avoid the memleak warning */
> atomic_sub(sizeof(*iml), &sk->sk_omem_alloc);
> kfree_rcu(iml, rcu);
[Severity: High]
Will passing plain GFP_KERNEL_ACCOUNT for optional deleted-group tombstones
on socket teardown trigger spurious memcg OOM kills of sibling processes
and O(N) reclaim storms under rtnl_lock()?
The same applies to ip_mc_leave_group() and IPv6 __ipv6_sock_mc_drop(),
ip6_mc_del1_src(), and sf_setstate(). Old membership and group records
are freed via kfree_rcu(), so their slab charges stay accounted while
synchronous tombstone allocations push the cgroup over memory.max.
In do_exit(), exit_mm() clears current->mm before exit_files() closes
sockets, while current->objcg remains set until cgroup_task_exit().
Because task_will_free_mem(current) returns false without current->mm,
try_charge_memcg() calls mem_cgroup_oom() and kills a surviving sibling.
Since these callers ignore NULL and continue iterating, every remaining
group or source repeats direct reclaim and OOM while holding rtnl_lock()
or idev->mc_lock. Using GFP_NOWAIT | __GFP_ACCOUNT (or adding
__GFP_NORETRY) for best-effort tombstones avoids OOM kills on teardown.
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> index a9f2e474fad05..be648c768ecb5 100644
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
[ ... ]
> @@ -275,7 +276,8 @@ static void __ipv6_sock_mc_drop(struct sock *sk, struct ipv6_mc_socklist *mc_lst
> ip6_mc_leave_src(sk, mc_lst, idev);
>
> if (idev) {
> - __ipv6_dev_mc_dec(idev, &mc_lst->addr);
> + __ipv6_dev_mc_dec(idev, &mc_lst->addr,
> + GFP_KERNEL_ACCOUNT);
> in6_dev_put(idev);
> }
[Severity: Medium]
Could blocking GFP_KERNEL_ACCOUNT charges in teardown loops stall
idev->mc_lock and global rtnl_lock() for seconds when a cgroup exceeds
memory.high?
Once a single syscall accumulates more than MEMCG_CHARGE_BATCH (64 pages)
in current->memcg_nr_pages_over_high, try_charge_memcg() synchronously
calls __mem_cgroup_handle_over_high() on blocking allocations, reclaiming
and sleeping up to 2 seconds while holding the caller's lock.
Under default sysctls, closing one IPv6 socket with ~2,000 joined groups
loops through __ipv6_sock_mc_drop() -> mld_add_delrec() and sleeps under
idev->mc_lock, blocking rtnl_lock() holders in ipv6_mc_down() or
ipv6_mc_destroy_dev().
The same happens directly under global rtnl_lock() in ip_mc_drop_socket()
(for example via close_range() across sockets) and ip_mc_leave_group().
Using GFP_NOWAIT | __GFP_ACCOUNT for these best-effort tombstones defers
memory.high throttling to return to userspace after locks are released.
[ ... ]
> @@ -2566,7 +2573,7 @@ static int sf_setstate(struct ifmcaddr6 *pmc)
> &psf->sf_addr))
> break;
> if (!dpsf) {
> - dpsf = kmalloc_obj(*dpsf);
> + dpsf = kmalloc_obj(*dpsf, GFP_KERNEL_ACCOUNT);
> if (!dpsf)
> continue;
> *dpsf = *psf;
[Severity: Medium]
Does hardcoding GFP_KERNEL_ACCOUNT in sf_setstate() (and
GFP_ATOMIC | __GFP_ACCOUNT in IPv4 sf_setstate()) charge non-socket
multicast joins to the caller's memcg?
When a non-socket caller such as addrconf or ndisc calls
ipv6_dev_mc_inc() -> __ipv6_dev_mc_inc() for a group that already has
socket MCAST_EXCLUDE source filters, __ipv6_dev_mc_inc() calls
ip6_mc_add_src() without forwarding gfp, which reaches sf_setstate().
The same happens in IPv4 via ____ip_mc_inc_group() -> ip_mc_add_src() ->
sf_setstate(). This can trigger memcg reclaim, OOM, or forced charges in
an unrelated task's cgroup, contradicting the stated policy that
non-socket joins remain uncharged.
Forwarding the caller's gfp (or whether __GFP_ACCOUNT is set) from
__ipv6_dev_mc_inc() and ____ip_mc_inc_group() through ip6_mc_add_src() and
ip_mc_add_src() into sf_setstate() would keep non-socket joins uncharged.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205081856.2229881-1-x-professor@outlook.com?part=3
prev parent reply other threads:[~2026-12-06 8:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 8:18 [PATCH net-next v2 0/3] net: multicast: account memberships and device records to memcg Yingjie Wang
2026-12-05 8:19 ` [PATCH net-next v2 1/3] net: multicast: keep source filter state when adding a source fails Yingjie Wang
2026-12-05 8:19 ` [PATCH net-next v2 2/3] net: multicast: account socket memberships and source lists to memcg Yingjie Wang
2026-12-05 8:19 ` [PATCH net-next v2 3/3] net: multicast: account device records created by sockets " Yingjie Wang
2026-12-06 8:19 ` sashiko-bot [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=sashiko-outbox-252269@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=18983559317@163.com \
--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-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=pabeni@redhat.com \
--cc=roman.gushchin@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=willemb@google.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