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 67E1E606A32A for ; Mon, 30 Nov 2026 04:25:27 +0000 (UTC) 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=AOGIHnyS Received: by kanga.kvack.org (Postfix) id 782446B05B3; Sun, 29 Nov 2026 23:25:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 759F46B05B7; Sun, 29 Nov 2026 23:25:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6971B6B05B8; Sun, 29 Nov 2026 23:25:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3D54F6B05B3 for ; Sun, 29 Nov 2026 23:25:26 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B57168018C for ; Mon, 30 Nov 2026 04:25:25 +0000 (UTC) X-FDA: 85490496210.21.DCDEE83 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf02.hostedemail.com (Postfix) with ESMTP id 219108000B for ; Mon, 30 Nov 2026 04:25:24 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=AOGIHnyS; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of tj@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=tj@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796012724; b=vkqNrC7B4f2qHJPTuwZkXjyZdOTsUuvUKs/PwMKU9clQ0G0KvEwopQ1VBHFjIztbJHZcvB olkpyaNEGjNyI7kLyBVXXJ3W/a7eJecetsgpOgVQeuruMoOUb1o5Oa5DL0VxUvuDimQump RacpCbhSk26dCMnNpTJmYWWCaXEFyL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796012724; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7EL1pOYRUPpJNj0YS69B99XoB+wrFmh/14OWsz0Kjig=; b=0izQ9aqbl7bELGAIQISti1xIjznhnl4Q1OHPm98+ZXouhthrvLOpI/nZYm5IhtHosZZl0R Vi48kS/qApjqUdX1M9w0vSPCNhMDTSt82mnFa54fQQ0YiH77i3Y0jw1otV1O6TyjdVSdu9 AgXa26iuCs5hEppA6snYXxIYOcnc3BY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=AOGIHnyS; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of tj@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=tj@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8F6F5432A5; Mon, 30 Nov 2026 04:25:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D2A61F008A0; Mon, 30 Nov 2026 04:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796012722; bh=7EL1pOYRUPpJNj0YS69B99XoB+wrFmh/14OWsz0Kjig=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=AOGIHnySL2Q/j13S0AojjIehttJPxYg5aZNMqJuJrUWYDXiAqIyBgK0slN1zoX4+V Lp18NKapAa0XAfljxluVPWqD+TsJ4uX/cbpffD9JoXkGBgwyBEBIivpn36CxtcUGpY G6TO/V3KV+g9+p0LKudLI88PSAuIIp0rpexiJ36FXfAVUV8PUuvofzs9cHJWuXtCiN tnldu4/Fj8GZ+sFwJ/R1BLAHijpWDnJ4RJCfgJIqPG6SpYsrEBgP4p5gEHRuwMcS/N h7QI4DNudwxDxyhQEUgKNWt4KjAWOW96T2j0uVRJBF5eIO5BcnuzgkNEhyMdNuVPEa my36YG3Atp7ug== Date: Sun, 29 Nov 2026 18:25:21 -1000 Message-ID: From: Tejun Heo To: Shakeel Butt Cc: Andrew Morton , 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 0/9] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze In-Reply-To: <20261129183524.1052436-1-shakeel.butt@linux.dev> References: <20261129183524.1052436-1-shakeel.butt@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-cgkf-review-1-=boundary" X-Rspamd-Queue-Id: 219108000B X-Stat-Signature: ms64p8m9t4n8znbw6hqa4gdwao5gfzt3 X-Rspam-User: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Server: rspam07 X-HE-Tag: 1796012724-373025 X-HE-Meta: U2FsdGVkX1/7HFQnI1Q8hEgkF8aNTrgsIaNvTaGF/hIy82S8kAZqAOnIv+QoHSomVY52cjDTJSB0DA442FZ0iOvn5NxDlYD+BroA6JBcExGb3mEPnNV55SsYCq6+fTK7WR3UCJTyc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MwA7W9ebX+vqjn2Rw6MgtjG6QCQnD2oAyBdO6Fua4q3WPdsSkKK5qIlWgyNnWVqz29DcNtAL/uWEmUtosN+CclUnqHd7zna0er/JkDiWAZhwm2vOa23/IS8PH8WitNYD9v1RSMfLrx09h7j6Madhkpp5N2flpNWqImexetS6nN7j1pLqUoKKcK4KC+5z55i1qg+h/QBa5lr+qOqYsKdUoCZAFys5CrKN8hCx1ecDDVpXPruTWzSD5iRTlRTx+pYj62FvBFYaHxbx2fBaaH35ovMRkSQ4QvYC9ID9oZzGI6ZJ9Zq07JIo+ln9iDQfSku1iQJUEZJV55ZUHLGQ0K9CDOD68UmeH5ItXFwMxxw5JxrkZTD1FVu+SKHTiW2eZLtEkapbkW1mp1sh/Uay8zmEqMvFVdAk15fr6FrZjFpvtCCohAGt+b9/ybqoraFl5Owh+q9nHKGUZg91nQ1oJXhqtoe/w9LHDwSkLPNO0WXdmbDqKbHgnqD5S+6sJVGofsmJKFzwipTXrsCGUuUf9kNfFWnSwvDW8TEHNnApbj+wvqT54tK8hcwpnPLp1zNB70zhOm0mVqWATZ8+VugJuyw== 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 --=-cgkf-review-1-=boundary Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello, Shakeel. The following is a Claude-generated review. Two problems were found, in 8/9 and 9/9. Both were reproduced in a VM with delays added to widen the windows. The debug patch and the reproducer are attached. 1. A migration that fails before it commits makes the task walk skip a task (8/9 and 9/9). cgroup_migrate_add_task() calls css_set_skip_task_iters() and moves the task to cset->mg_tasks. When ->can_attach() then fails, out_release_tset in cgroup_migrate_execute() splices mg_tasks back onto cset->tasks. An iterator whose next task was that one has already moved past the end of cset->tasks and never returns it. The task didn't change css_set, so neither the kill in cgroup_migrate_execute() nor cgroup_freezer_migrate_task() runs for it. cgroup_mutex used to keep migrations out of the walks. The task has to be the last one on its css_set that the iterator hasn't returned, so a cgroup with one task is enough. With the failed attach between css_task_iter_start() and the first css_task_iter_next(): - cgroup.kill returns success and the task survives. - A freeze leaves cgroup.freeze at 1 with the task running, and the cgroup never reports frozen. - A thaw leaves cgroup.freeze at 0 and "frozen 0" in cgroup.events with the task still frozen. 2. The SIGKILL sent from cgroup_migrate_execute() isn't forced (8/9). send_sig(SIGKILL, task, 0) sends SEND_SIG_NOINFO, which send_signal_locked() forces only when current is outside the target's pid namespace. current is the migrator there, not the cgroup.kill writer. A pid namespace init which writes its own pid to cgroup.procs of a cgroup that the walk has already passed ignores the signal and survives a kill written from the host. The same move made from the host kills it. The other direction follows from the code and wasn't run: a host migration during a kill written inside the container kills an init which that kill would have left alone. A few smaller points, from reading the code only: - 3/9 is only right on top of 2/9, and its stable tag doesn't name 2/9 as a prerequisite. - 8/9: a CLONE_INTO_CGROUP child placed outside the tree by a parent inside it is now killed. The cover letter says so but the documentation update doesn't. cgroup.kill can also fail with EOPNOTSUPP on a domain cgroup while a "threaded" write that later fails is in progress. - 9/9: a task frozen by a freeze that is still in progress runs again when it is moved to a cgroup that the walk hasn't reached, until the walk gets there. Maybe worth documenting? Thanks. -- tejun --=-cgkf-review-1-=boundary Content-Type: text/x-patch; charset=us-ascii; name="debug-delays.diff" Content-Disposition: attachment; filename="debug-delays.diff" Content-Transfer-Encoding: 7bit diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 28fd9b642f5a..d1be3b3c74bc 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -2609,6 +2609,13 @@ void cgroup_attach_unlock(enum cgroup_attach_lock_mode lock_mode, /* cgroup.kill writes in progress, protected by css_set_lock */ static unsigned int cgroup_nr_kills; +/* REVIEW DEBUG: widen race windows */ +#include +static unsigned int cgkill_dbg_iter_ms; +core_param(cgkill_dbg_iter_ms, cgkill_dbg_iter_ms, uint, 0644); +static unsigned int cgkill_dbg_cg_ms; +core_param(cgkill_dbg_cg_ms, cgkill_dbg_cg_ms, uint, 0644); + /** * cgroup_subtree_kill_seq - sample the cgroup.kill state of a cgroup's subtrees * @cgrp: cgroup of interest @@ -4396,6 +4403,8 @@ static void __cgroup_kill(struct cgroup *cgrp) spin_unlock_irq(&css_set_lock); css_task_iter_start(&cgrp->self, CSS_TASK_ITER_THREADED, &it); + if (cgkill_dbg_iter_ms) + msleep(cgkill_dbg_iter_ms); while ((task = css_task_iter_next(&it))) { /* Ignore kernel threads here. */ if (task->flags & PF_KTHREAD) @@ -4470,6 +4479,8 @@ static int cgroup_kill(struct cgroup *cgrp) rcu_read_unlock(); __cgroup_kill(css->cgroup); + if (cgkill_dbg_cg_ms) + msleep(cgkill_dbg_cg_ms); cond_resched(); rcu_read_lock(); diff --git a/kernel/cgroup/freezer.c b/kernel/cgroup/freezer.c index a5e3920f4ad2..4367cb3e3fc1 100644 --- a/kernel/cgroup/freezer.c +++ b/kernel/cgroup/freezer.c @@ -6,6 +6,12 @@ #include "cgroup-internal.h" +/* REVIEW DEBUG: widen race windows */ +#include +#include +static unsigned int cgfreeze_dbg_iter_ms; +core_param(cgfreeze_dbg_iter_ms, cgfreeze_dbg_iter_ms, uint, 0644); + #include /* @@ -205,6 +211,8 @@ static void cgroup_do_freeze(struct cgroup *cgrp, bool freeze) TRACE_CGROUP_PATH(unfreeze, cgrp); css_task_iter_start(&cgrp->self, 0, &it); + if (cgfreeze_dbg_iter_ms) + msleep(cgfreeze_dbg_iter_ms); while ((task = css_task_iter_next(&it))) { /* * Ignore kernel threads here. Freezing cgroups containing --=-cgkf-review-1-=boundary Content-Type: text/x-shellscript; charset=us-ascii; name="cgroup-kill-freeze-repro.sh" Content-Disposition: attachment; filename="cgroup-kill-freeze-repro.sh" Content-Transfer-Encoding: 7bit #!/bin/bash # # Reproducers for two problems in "cgroup: don't hold cgroup_mutex for # cgroup.kill and cgroup.freeze": # # 1. A migration that fails before it commits makes the task walk of # cgroup.kill and cgroup.freeze skip a task. # 2. A pid namespace init that moves itself during a cgroup.kill written # from an ancestor pid namespace survives the kill. # # Needs a kernel with debug-delays.diff applied, cpuset enabled, and root. # Run it in a scratch VM. Each case has a control run that must behave. P=/sys/module/kernel/parameters CG=/run/cgtest mkdir -p $CG mount -t cgroup2 none $CG || exit 1 alive() { [ -d /proc/$1 ] && ! grep -q '^State:.*Z' /proc/$1/status; } utime() { awk '{print $14}' /proc/$1/stat; } runs() { local a=$(utime $1) sleep 1 local b=$(utime $1) [ "$b" -gt "$a" ] && echo "running" || echo "not running" } # D/e is a cgroup that every attach fails on with ENOSPC: its cpuset has no # effective CPUs because the sibling partition D/p took all of D's. echo +cpuset > $CG/cgroup.subtree_control mkdir $CG/D echo 0-1 > $CG/D/cpuset.cpus echo root > $CG/D/cpuset.cpus.partition echo +cpuset > $CG/D/cgroup.subtree_control mkdir $CG/D/p $CG/D/e echo 0-1 > $CG/D/p/cpuset.cpus echo root > $CG/D/p/cpuset.cpus.partition sleep 1000 & probe=$! if echo $probe > $CG/D/e/cgroup.procs 2>/dev/null; then echo "SETUP: attaching to D/e did not fail, case 1 is void" fi kill -9 $probe echo "=== 1a. cgroup.kill, failed migration during the task walk" for with_mig in 0 1; do mkdir -p $CG/S/x sleep 1000 & t=$! echo $t > $CG/S/x/cgroup.procs echo 2000 > $P/cgkill_dbg_iter_ms echo 1 > $CG/S/cgroup.kill & w=$! sleep 3 # the walk of S is done, the iterator of S/x has started [ $with_mig = 1 ] && echo $t > $CG/D/e/cgroup.procs 2>/dev/null wait $w echo 0 > $P/cgkill_dbg_iter_ms sleep 0.5 if alive $t; then echo "failed migration=$with_mig: task SURVIVED, S $(grep populated $CG/S/cgroup.events)" else echo "failed migration=$with_mig: task killed" fi kill -9 $t 2>/dev/null sleep 0.3 rmdir $CG/S/x $CG/S done echo "=== 1b. cgroup.freeze, failed migration during the task walk" for with_mig in 0 1; do mkdir -p $CG/G/x bash -c 'while :; do :; done' & t=$! echo $t > $CG/G/x/cgroup.procs echo 2000 > $P/cgfreeze_dbg_iter_ms echo 1 > $CG/G/cgroup.freeze & w=$! sleep 3 [ $with_mig = 1 ] && echo $t > $CG/D/e/cgroup.procs 2>/dev/null wait $w echo 0 > $P/cgfreeze_dbg_iter_ms sleep 5 echo "failed migration=$with_mig: freeze=$(cat $CG/G/cgroup.freeze), G $(grep frozen $CG/G/cgroup.events), task $(runs $t)" # freeze it fully, then the same for the thaw echo 0 > $CG/G/cgroup.freeze sleep 0.5 echo 1 > $CG/G/cgroup.freeze sleep 1 echo 2000 > $P/cgfreeze_dbg_iter_ms echo 0 > $CG/G/cgroup.freeze & w=$! sleep 3 [ $with_mig = 1 ] && echo $t > $CG/D/e/cgroup.procs 2>/dev/null wait $w echo 0 > $P/cgfreeze_dbg_iter_ms sleep 5 echo "failed migration=$with_mig: freeze=$(cat $CG/G/cgroup.freeze), G/x $(grep frozen $CG/G/x/cgroup.events), task $(runs $t)" kill -9 $t 2>/dev/null sleep 0.3 rmdir $CG/G/x $CG/G done echo "=== 2. cgroup.kill, pid namespace init moved during the kill" for mover in host init; do mkdir -p $CG/C/a $CG/C/b sleep 1000 & echo $! > $CG/C/a/cgroup.procs if [ $mover = init ]; then ( echo $BASHPID > $CG/C/b/cgroup.procs exec unshare -fp bash -c "sleep 4.5; echo 1 > $CG/C/a/cgroup.procs; sleep 1000; true" ) & else ( echo $BASHPID > $CG/C/b/cgroup.procs exec unshare -fp bash -c "sleep 1000; true" ) & fi sleep 0.5 init= for p in $(cat $CG/C/b/cgroup.procs); do grep -q -P '^NSpid:\t\d+\t1$' /proc/$p/status && init=$p done # sleep after each cgroup of the walk: C, then C/a, then C/b echo 3000 > $P/cgkill_dbg_cg_ms echo 1 > $CG/C/cgroup.kill & w=$! if [ $mover = host ]; then sleep 4 echo $init > $CG/C/a/cgroup.procs fi wait $w echo 0 > $P/cgkill_dbg_cg_ms sleep 0.5 if alive $init; then echo "moved by $mover: init SURVIVED in $(cat /proc/$init/cgroup), C $(grep populated $CG/C/cgroup.events)" else echo "moved by $mover: init killed" fi echo 1 > $CG/C/cgroup.kill sleep 0.5 rmdir $CG/C/a $CG/C/b $CG/C done --=-cgkf-review-1-=boundary--