From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147765; b=wo/oHtMYRD+Szs7nIsB4LFfEvkx37yIAuVuX/E1mkIdnPoMhjYH7E5K5HtgiOrAOzAsl blDnd6EiPAVUQq+Dq3p2pmCnrWw0Tl0R2iK609bVsNW1wvxYu51K4TYCTr6gBDNkK4En0 n9EiqsRDeqeXPYNPzvBi2ymWwMtVD8CWY0ChPKh7u0OZf3R7mXWKcqiS6DIKoJcyUleiz HsTNWmU/WoIm1/HdHnKtSPmCY1UjNZYCQYz218fVmp9MyNi/MJicysUFOoLwYt6ReIAey YsMB2gYk9eh0hrMUS9JDcb7aj0YlnD1YsvpF9vJ+Ztg0G+l2s0GEGkQqfPFuiHG81VQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147765; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=pNUAn+Mlv8ita/tx6pcON9rZZ3IhLjDiaLpGrx+xGRI=; b=ql7jwCZR376Wn89U/FYkDKOzKaAW27wEfPvp47bYPRPhqPcwCpMveKrVz/91sL7gwSVK tnIV9aXiXOlY/acFAUaG0ay/FrlFcXXgfjkQFEo9h/DIFJPM/uDImWGFicOovY0vqnPPm 41Sh4P+uvxBTFFVp2CAkhiiCgWwNsOMTUtzp3RYVZNmiNy7wdkKSv/cA2/Shs/pO1yVt6 F9Y/YNSpthNCPcgZ0ZtC4J9ELVLjQ4beLsl5uw38Nxt5LyGUJ/9u05e9uZJEJifDY/pyA mosdi5N65Ytpde9EfQLQbs8SAOJmGFJIGjJO00eS6iCFSOpjOTf0xqFZ7VY1vzal4vQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=WmjJu3PO; arc=none smtp.remote-ip=100.103.45.18 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 5F088606A31A; Tue, 1 Dec 2026 17:56:05 +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=WmjJu3PO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C5F81F00893; Tue, 1 Dec 2026 17:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796147765; bh=pNUAn+Mlv8ita/tx6pcON9rZZ3IhLjDiaLpGrx+xGRI=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=WmjJu3POorbSMsHRg2yEvSb21/Ypr9AB6EgBB3JMDsNecSNqo197Qvycp9Up6n1S8 w1HhoLmE/pyGR6+VaHAk14oiCnigc9g7//SunMTspr+D6hE9tfmRJ1Q7K/UajOsoeb mnUxGzkU69U0RAPvY4n8D3365BqvhtnGhNIAXnrg= Date: Tue, 1 Dec 2026 09:56:04 -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: <20261201095604.e92178b7ac07f0096794db78@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-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: refuse cgroup.kill below a threaded ancestor Date: Tue, 01 Dec 2026 01:35:32 -0800 A non-threaded cgroup below a threaded ancestor has type "domain invalid". Its threaded descendants can accept a thread from a process in the ancestor's domain. cgroup.kill rejects a threaded target but accepts the intermediate domain-invalid cgroup, then sends SIGKILL to the entire process, including threads outside the target subtree. This fixes Shakeel Butt's "cgroup: don't hold cgroup_mutex for cgroup.kill" patch. Check the ancestor CGRP_THREADED flags under css_set_lock before starting the kill. A concurrent switch to threaded is excluded by the active kill check in the preceding fix. Retain ENODEV precedence for a removed cgroup and return EOPNOTSUPP for this unsupported kill. In a KASAN/lockdep guest, one thread of a two-thread process entered a threaded descendant. cgroup.kill on the intervening domain-invalid cgroup returned success and killed the entire outside process. 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/kernel/cgroup/cgroup.c~cgroup-dont-hold-cgroup_mutex-for-cgroupkill-f= ix-2 +++ a/kernel/cgroup/cgroup.c @@ -4512,13 +4512,20 @@ static int cgroup_kill(struct cgroup *cg { struct cgroup_kill_ctx kill =3D { .cgrp =3D cgrp }; struct cgroup_subsys_state *css; - int ret =3D 0; + int i, ret =3D 0; =20 spin_lock_irq(&css_set_lock); if (cgroup_is_dead(cgrp)) ret =3D -ENODEV; else if (test_bit(CGRP_THREADED, &cgrp->flags)) ret =3D -EOPNOTSUPP; + else + for (i =3D cgrp->level - 1; i > 0; i--) + if (test_bit(CGRP_THREADED, + &cgrp->ancestors[i]->flags)) { + ret =3D -EOPNOTSUPP; + break; + } /* an empty subtree has nothing to kill, see above */ if (ret || !cgroup_is_populated(cgrp)) { spin_unlock_irq(&css_set_lock); _