From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E64E3606A32A for ; Tue, 1 Dec 2026 17:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Rx2t+4p8 Received: by kanga.kvack.org (Postfix) id A7CFB6B065A; Tue, 1 Dec 2026 12:55:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A54256B065B; Tue, 1 Dec 2026 12:55:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 992256B068A; Tue, 1 Dec 2026 12:55:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DC7DA6B065A for ; Tue, 1 Dec 2026 12:55:58 -0500 (EST) Received: from smtpin17.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 228AEC0FBD for ; Tue, 1 Dec 2026 17:55:58 +0000 (UTC) X-FDA: 85496167596.17.1436733 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf17.hostedemail.com (Postfix) with ESMTP id 604C54000A for ; Tue, 1 Dec 2026 17:55:56 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Rx2t+4p8; dmarc=none; spf=pass (imf17.hostedemail.com: domain of akpm@linux-foundation.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796147756; b=8O1OsFQMgavZuEBZRM9yF7MJBEFZ4TzSInmh+kN8EpwwFCZKkFDVKFD+RWc0PtajuFnWzk Eiv716No//8KKgOAo2p+UWDjZbbnhEktXL5Axe4kHQnU0fKL5l5leZLtCykj8KcDLXAkJr WNGJQT9m6GBc8mE20InW9hNXuMU8nuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796147756; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+viV9IKVgtNVk9aM1uel7H9tOHgghJ/dnPf4Hf4RNUw=; b=tRavvfFuerAtjzyyUDGUnLovky1BxKpCzOFNX1BHhcvrPxPKqFDY4jmpPyfX8uKnE2Qh7j bt8TpfGWm8ltsjYjQa1CrXGgAYfRbU4t44dfenEWGHeSPZ8NuGqriWYWwQeFDy5QeqFFzG Cy/WJ9cmlvKJIxhP35p6HPDKgxrJgvU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Rx2t+4p8; dmarc=none; spf=pass (imf17.hostedemail.com: domain of akpm@linux-foundation.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id ED9BC61CD8; Tue, 1 Dec 2026 17:55:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28FB31F000C1; Tue, 1 Dec 2026 17:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796147755; bh=+viV9IKVgtNVk9aM1uel7H9tOHgghJ/dnPf4Hf4RNUw=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Rx2t+4p8o8IQPrsqtj6Pzi/GyKLDmjjrd1CznoX4LXWkxG2qqeVlgBdLCHI6XFz+J l0/sDkZScvzI6y+OFs5jNTKWAAipk+osnnXS9gE8ukuiG/AeOQ1fubWcHwS/YVXC9U mY8iPjl7OBXi2Qh6QG2BoM6WJ7nAOWb1pN/sinf0= Date: Tue, 1 Dec 2026 09:55:54 -0800 From: Andrew Morton To: Shakeel Butt Cc: Tejun Heo , Johannes Weiner , Michal Koutny , Michal Hocko , Roman Gushchin , Christian Brauner , Oleg Nesterov , Sebastian Andrzej Siewior , Suren Baghdasaryan , "T . J . Mercier" , Usama Arif , Meta kernel team , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 10/11] cgroup: don't hold cgroup_mutex for cgroup.kill Message-Id: <20261201095554.faf34ccb08077ff486e74cb9@linux-foundation.org> In-Reply-To: <20261130173425.4117363-11-shakeel.butt@linux.dev> References: <20261130173425.4117363-1-shakeel.butt@linux.dev> <20261130173425.4117363-11-shakeel.butt@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Archived-By: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: grh8nsfrsh34g3ossnn7mntfq56e1ste X-Rspamd-Queue-Id: 604C54000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796147756-931392 X-HE-Meta: U2FsdGVkX19XlfKCN4AfRYbjwdFDnsAVsuhK43gsDWvTISzMUDVfqZ2N5WX6rLDcQQtCDi9lHAaQfcqImbGDPvCpTmiPGUAha5Tjn0K6PVnnmcHEohgL8NvnJzJEBlSi5Gn4xMGwjoPuFMacN8hF3Dk9EZOKP+HAn0p8cQWC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b4aSeu8Ul63yUvIqIM2ME0W6E5bt9JUHLH5W2Z9zbyIAeeY1DiA0ZCbyARsiSk3ogIO+ooDcmzoIbFwUOkR72G9/MRhPySD1bqFk4U0AfHvUotVwMDxW3w5iuTe4bPzmjyfsTXuGn2WuX+eNCqcBXKHEg/mlrHIuvxiD07lz7pcCkszoMTEhC3ZF5s89ab5EXwjxRN8KRa8KGQcJWqHBw34WDqFAq8hox+h4/tqeqpa14ZHeJwjTxQ+NfiSq5U5+8GoLkribAnqAgdoenzcQE4dmo5yIW0iDtLUnwkGaJpbv8rxUXIxjf5N4b3H3pNKGS/OCSU66IAdZVxSxVcjJXo+9vtZHfqbDafV+FyFa4Ts298mWl6Petm4iZnCS4akpy2BJ8D6KbEqv4SKKsQVDPOt5vyqGlamHfdUj/B2PNTxmbTNw/MpRoTxUY= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Mon, 30 Nov 2026 09:34:24 -0800 Shakeel Butt wr= ote: > It is often used when the system is already in trouble, so it should not > wait for other cgroup operations, and they should not wait for it. >=20 > cgroup_mutex kept the cgroup and its subtree stable, and blocked > migrations, CLONE_INTO_CGROUP forks and switches to threaded during the > kill. Replace it: From: Andrew Morton Subject: cgroup: reject a threaded switch during a descendant kill Date: Tue, 01 Dec 2026 01:35:32 -0800 A kill of a descendant can outlive its last task. The ancestor then looks empty, and cgroup_enable_threaded() checks only the ancestor's own nr_subtree_kills. It can switch the ancestor to threaded while the descendant kill is still active. The switch changes the domain of threaded descendants, allowing threads from outside the killed subtree to enter it during the kill. This fixes Shakeel Butt's "cgroup: don't hold cgroup_mutex for cgroup.kill" patch. Check the active kill list for the cgroup and all its descendants under css_set_lock. cgroup_mutex keeps the ancestry stable. Once the empty ancestor passes the check, migrations cannot populate it until the switch finishes, and a new kill of an empty subtree returns immediately. A 64 CPU KASAN/lockdep test held a descendant kill open for one second after its last task exited. The v2 kernel accepted the ancestor's cgroup.type=3Dthreaded write during that interval. With this change the write returns EBUSY. Link: https://lore.kernel.org/r/20261130173425.4117363-11-shakeel.butt@linu= x.dev Signed-off-by: Andrew Morton Cc: Tejun Heo Cc: Johannes Weiner Cc: Michal Koutn=FD kernel/cgroup/cgroup.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) --- a/kernel/cgroup/cgroup.c~cgroup-dont-hold-cgroup_mutex-for-cgroupkill-f= ix +++ a/kernel/cgroup/cgroup.c @@ -3865,6 +3865,7 @@ static int cgroup_enable_threaded(struct struct cgroup *dom_cgrp =3D parent->dom_cgrp; struct cgroup *dsct; struct cgroup_subsys_state *d_css; + struct cgroup_kill_ctx *kill; int ret; =20 lockdep_assert_held(&cgroup_mutex); @@ -3889,15 +3890,20 @@ static int cgroup_enable_threaded(struct return -EOPNOTSUPP; =20 /* - * cgroup.kill doesn't hold cgroup_mutex. Threads that join @cgrp - * after the switch could be killed with their whole process by a kill - * of @cgrp that is still running, so don't switch during such a kill. - * No new kill of @cgrp can start until we're done: @cgrp is empty, - * nothing can enter it while we hold cgroup_mutex, and cgroup_kill() - * returns right away for an empty subtree. + * A kill of @cgrp or a descendant may still be running after its last + * task exits. Switching now changes threaded descendants' domains and + * can let outside threads enter a subtree whose kill is still active. + * No new kill can start after this check: @cgrp is empty, migrations + * wait for cgroup_mutex, and cgroup_kill() skips empty subtrees. */ spin_lock_irq(&css_set_lock); - ret =3D cgrp->nr_subtree_kills ? -EBUSY : 0; + ret =3D 0; + list_for_each_entry(kill, &cgroup_kills, node) { + if (cgroup_is_descendant(kill->cgrp, cgrp)) { + ret =3D -EBUSY; + break; + } + } spin_unlock_irq(&css_set_lock); if (ret) return ret; _