🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21156

Re: [PATCH net 3/3] net: multicast: account group and source allocations to memcg

#21156
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 16:24
181 lines
14415 bytes
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
Technical Details
Message-ID: <179545104659.3135.11573235607470978138@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369578-linux-kernel-netdev=dewy.ru
References: <eabf67fe94dc239f6cc59720e8468f2bf9b4cd62.1795102467.git.x-professor@outlook.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369578-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 3/3] net: multicast: account group and source
 allocations to memcg
Date: Mon, 23 Nov 2026 16:24:06 +0000
Organization: Usenet Network
Message-ID: <179545104659.3135.11573235607470978138@kernel.org>
References: <eabf67fe94dc239f6cc59720e8468f2bf9b4cd62.1795102467.git.x-professor@outlook.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3927102"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:5bsnN9cmNXli4I28HkEHjHcU0mU= sha256:5Lf4iBha7BZV94F5CQe6HJzZ3NC5INU21Uutqc9FClc=
	sha1:KUA4lvi3Zn8AABHhO2GR4sRMHiM= sha256:tBgY5QHkfVZhZjGI1j+UHwRXQDPOc9k8FrvlzGLpmHA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id A5897125DC1; Mon, 23 Nov 2026 19:24:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Vx0qcqwJwArF;
	Mon, 23 Nov 2026 19:24:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-369578-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 8D9AA125DBF; Mon, 23 Nov 2026 19:24:20 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 418EA26D9C; Mon, 23 Nov 2026 16:24:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795451049;
	b=r7gNnzjcG/0kVbCDMYu78S5y66zdDIpgEM+VTHPgjxOfo5hqIIe/90jHOuLsll0MdG1x
	 0rNAqFI3vvE98CYH4cHxK9RKisxq2X7ycM1r9Nh6G3MP9160v7hy6JZIGPH48r0vT2dod
	 ycWIeP8C/qji1ARKJlJ5WgYzlDDkyBCW/+AjoqboD4btrfpSsLfFK5jSuxOfGeV2JX5bg
	 Ekgj5y5mFU9zcjf8fDGwBqixdg1tcs946PHKebuoOFGjm6VVheaqDMNcnYPp1ukCF7G8h
	 uMYaeu/COOJBUAOHDkeyfEH5Ebzg7GSQG3xBZM9Ah8QBYpcUDCr/b7QPGkGCX2Gw2Ug==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795451049;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=QZXIFYILtCNn6BOcPijM59Qx4+riXxSWUomOV63QZGA=;
	b=bw1IbP3K1zeXCCSgIEjkNJYPpPDhUIGgLEDGUpkSqd6mcWG21bIz1wrpdoEsQyROnIN/
	 SCaLGl9LC09K10Os/8jHtuPfYTpucju8sXy8iuD+kxI0hn5GJ1QKgdgkLl+FJF99acedk
	 ed2DPvsp1nZ6bDHYEoBtvCj9NdyZk/vLhwhQxmq8JCivXj8EZADmz/D6ZyuktydZFnJI6
	 NucqGxHHcTeHuWxD+SizpIulNfGgnmGdG+8qRan7coQ5W399qdLH+9CrARmMB750YjdB8
	 jzu6NkjuR03cNs13LOMvsQOrj4jq+QuhVuXLvr7uKvxuZgxEUVM48rMznSsF9KwvcfA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XGRrDED2;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 67451606A6A1;
	Mon, 23 Nov 2026 16:24:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XGRrDED2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795451048;
	b=3HIEPmZ08aFoBNAQpA+N2TpU3D3cmAaK3mQKlR84C6XN4aeZ8otQByUIIquLYVw7ECFB
	 +3jcAODQvy/ti/HPUd6S4/L5Uk/qt9qOUVOKXZOvHlP3mFhaUfwKx94Rwb6pqrV5hFlZN
	 AmZOmABJfkx/ObDoedfw3sCllMIE7fr0pu/wkyA1ObM5xxtRxSivpr4VGcKqZ1OZNL9+K
	 wMg8ttTXXluPfr91BC+yh/zuZ5vkHotweJnHC4uD3qcH0Vms86H8D3KcIqOqr3hl2Bcy9
	 HoBUNSDtqeOWxdGTJ+3ct3WhSo0b4tzFQcOTo/pJWs0pvf8iJg0kOM53Vx9tNYB3nMg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795451048;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=QZXIFYILtCNn6BOcPijM59Qx4+riXxSWUomOV63QZGA=;
	b=dUT50/IhdrpV61+mfp6tQn9M/0qkVPsb5j7FfJ1ZHA6J5XztIqsXWwk94+OrpjZQB8/f
	 S4rW9/5i9J/gEtdjddO5J2l0FgOmb9jPOzZ1Fkai35Ba33T1tWC2Fqt2qVMNr8irKxbhl
	 olaeV5FjVFkwMN6f0IBM12kNsOfBBwQNBeY1YjVrojwIITKUk+A5oo+sRIJrEQBBqO4X8
	 S0PWP6hLN1QmkOzgljAJJV1CQNtyU4Ki8WPqhhGR40ht4p7r/n4ELWNDn9BnU0vLM13l4
	 LoqRaxanKoPl/cRG01vWgxlRmlcLLtnhHS96oq52D7tEP/yhqHV4Pa0hwfnvKC0OVWQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XGRrDED2;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8897C606A332;
	Mon, 23 Nov 2026 16:24:08 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05C8E1F0089E;
	Mon, 23 Nov 2026 16:24:06 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795451048;
	bh=QZXIFYILtCNn6BOcPijM59Qx4+riXxSWUomOV63QZGA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=XGRrDED2jEpYvgE50oiY8fPCgtnMvmLiEjkzS9FnyjwWlK9puHJ6oI7nelee/TFeD
	 lS1P04iIZVUe4XuZ6aRXAsvEiMnq4K4BOVyDge/J9mFHykpnlc6oIgtBnDp/j/fiZh
	 quzGh29ASYGTa7s1f3UQwns13EGVLZ4dveF31N4N07R3HzQjlxL2KuI+vVfxJ9VJ/+
	 1dPbAxOVEL9ztnZEgWbcj5zeFbf7zg5vZVytEaiT4OAqAu5/YHjMMhuHwykzZb+22g
	 H6OMZuUYsYWivzO6wTf7DtreT/FA6O83v58iowhWEzhtkThRU8EzfIcAF7d9G01N67
	 rySgow1eEa+KQ==
X-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
X-In-Reply-To: <eabf67fe94dc239f6cc59720e8468f2bf9b4cd62.1795102467.git.x-professor@outlook.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list