From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795977362; b=C0T/ZLaolII/NL0cg61ZuIHc8ZE5x5zFm2jNus4BLjzA/ZbQprp5IGP8XPuzIAGpIzqO 5+/f8zVpqCr5M/wsgRKPii+mHPhuiKskurxF4iRWI6nkDdsLxhVzoK3ErwyyiGGE6vWoM unyJTSscLcBV1eLTvi0yx1aEOtV86+G2FWrQGb+0ez/9pJGJuA6go6I6O3smz9lX3rhW3 NZlVCbIG1iQspSlrOix6/N2zDnTEx9Cc0E68OuvAeQ+Aq8P5uQBh3Gv53Gph/Z7M9anJn pvMG0yz0fmvduR6TuZMiu9R5W4hs2Q46RXTam1if0blWXysqSQ9USk3g1E7MwoXjuaA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795977362; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=wYrb0Ql4FSDcjWoz2aMRA9BsELhhAOHvIT9aduOkyqE=; b=bBcefu3Jvy9mwJlgjL2V/Ixf7mqculXLJhTwXCCuVM++mNiLjkfp1pZDQTwhlB27kNEp A08E0WV1dTstmQ9gpNfHka2RVIiAXwHOWbupPM/+wJoMrp4fuYQSH6ESLWgg79XOptMKr X71vlHWDRkPsDMUa0EyAGA1pku1PF1tmYvPT9sGKx/765nTuGhzvqsd/AoLDrAvwAi83j emkgXE9bSQuNhel7YwCPCDfwVYB4LlZ5ZnBqZPyLuLv6EI6efgCYPcIziUSXBR1V2uN18 SXY04YUXPa36wS4WSnSFGimBxk12HDxuPo8RVJ3zfV6GxGrx6cEeQVIr3lrvcZsHyYw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=mVLiz2Rn; arc=none smtp.remote-ip=95.215.58.175 Received: from mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 873A1606A688 for ; Sun, 29 Nov 2026 18:36:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 873A1606A688 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=mVLiz2Rn X-Envelope-To: cgroups@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=H3Tg5ENR46HuWmcCmfiUT8CKn0nwTynWeJjpplsbDd8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795977359; v=1; x=1796582159; b=mVLiz2RnPBTzFC8sHYFTN/efYzNFMw1XbzG9LJbNuHYsGa7y6PzCh2j1Zjgefe05eoiMcYr7 BnncH43DPYpDbj+VIilvy3GvbKvDGTMpbDJDvg1n4gC7J3UtEAbSXv8k0IMApkGoq9mlFj/jcHw HGdYnfSnq/xyDdXwiGqgpDW0= X-Envelope-To: cgroups@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 1d82cfbf6a1f69be; Sun, 29 Nov 2026 18:35:59 +0000 X-Mizu-Trace-ID: 1d82cfbf6a1f69be X-Migadu-Flow: FLOW_OUT From: Shakeel Butt To: Tejun Heo 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: [PATCH 5/9] selftests/cgroup: test the frozen state of a cgroup with tasks and children Date: Sun, 29 Nov 2026 10:35:20 -0800 Message-ID: <20261129183524.1052436-6-shakeel.butt@linux.dev> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261129183524.1052436-1-shakeel.butt@linux.dev> References: <20261129183524.1052436-1-shakeel.butt@linux.dev> 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-Transfer-Encoding: 8bit Add a test for a cgroup that has tasks of its own and a child cgroup. It must report frozen only when its own tasks and the child are all frozen, and it must not stay frozen after a thaw. To get a task that the cgroup2 freezer can't stop, freeze it in a cgroup v1 freezer hierarchy. It then sleeps in the refrigerator, where the cgroup2 freezer can't trap it. A stopped task counts as frozen, and a thaw doesn't wake it. The test is skipped if the v1 freezer can't be mounted. Without "cgroup/freezer: check own tasks and descendants for the frozen state", the parent reports frozen=1 while its child is not frozen. Signed-off-by: Shakeel Butt --- tools/testing/selftests/cgroup/test_freezer.c | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_freezer.c b/tools/testing/selftests/cgroup/test_freezer.c index 266b1a0f889f..e24e97742492 100644 --- a/tools/testing/selftests/cgroup/test_freezer.c +++ b/tools/testing/selftests/cgroup/test_freezer.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -804,6 +805,109 @@ static int test_cgfreezer_vfork(const char *root) return ret; } +/* + * A cgroup with tasks of its own and child cgroups is frozen only once its + * tasks and all its descendants are frozen. + * + * A task frozen in a cgroup v1 freezer hierarchy sleeps in the refrigerator, + * where the cgroup v2 freezer can't trap it, so its v2 cgroup can't freeze + * until it is thawed. A stopped task counts as frozen and isn't woken by a + * thaw. + */ +static int test_cgfreezer_nonleaf(const char *root) +{ + char *parent = NULL, *child = NULL, *staging = NULL, *v1cg = NULL; + char v1root[] = "/tmp/cg_test_freezer_v1_XXXXXX"; + int ret = KSFT_FAIL, frozen_pid, stopped_pid, i; + bool mounted = false; + + if (!mkdtemp(v1root)) + return KSFT_FAIL; + + if (mount("none", v1root, "cgroup", 0, "freezer")) { + debug("Can't mount the cgroup v1 freezer\n"); + ret = KSFT_SKIP; + goto cleanup; + } + mounted = true; + + parent = cg_name(root, "cg_test_nonleaf"); + child = cg_name(parent, "child"); + staging = cg_name(root, "cg_test_nonleaf_staging"); + v1cg = cg_name(v1root, "cg_test_nonleaf"); + if (!parent || !child || !staging || !v1cg) + goto cleanup; + + if (cg_create(parent) || cg_create(child) || cg_create(staging) || + cg_create(v1cg)) + goto cleanup; + + frozen_pid = cg_run_nowait(child, child_fn, NULL); + stopped_pid = cg_run_nowait(staging, child_fn, NULL); + if (frozen_pid < 0 || stopped_pid < 0 || + cg_wait_for_proc_count(child, 1) || + cg_wait_for_proc_count(staging, 1)) + goto cleanup; + + /* Freeze one task in the v1 hierarchy and stop the other. */ + if (cg_enter(v1cg, frozen_pid) || + cg_write(v1cg, "freezer.state", "FROZEN") || + cg_read_strcmp_wait(v1cg, "freezer.state", "FROZEN\n")) + goto cleanup; + + if (kill(stopped_pid, SIGSTOP) || + waitpid(stopped_pid, NULL, WUNTRACED) != stopped_pid) + goto cleanup; + + /* + * Freeze the parent and move the stopped task in. All of the + * parent's own tasks are frozen now, but its child isn't. + */ + if (cg_freeze_nowait(parent, true) || cg_enter(parent, stopped_pid)) + goto cleanup; + + for (i = 0; i < 50; i++) { + if (cg_check_frozen(parent, false) || + cg_check_frozen(child, false)) + goto cleanup; + usleep(10000); + } + + /* The thaw doesn't wake the stopped task, the parent stays thawed. */ + if (cg_freeze_nowait(parent, false) || cg_check_frozen(parent, false)) + goto cleanup; + + /* Once the task is thawed in v1, the whole subtree can freeze. */ + if (cg_write(v1cg, "freezer.state", "THAWED")) + goto cleanup; + + if (cg_freeze_wait(parent, true) || cg_check_frozen(child, true)) + goto cleanup; + + if (cg_freeze_wait(parent, false)) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + /* SIGKILL doesn't wake up a task in the refrigerator. */ + if (mounted && v1cg) + cg_write(v1cg, "freezer.state", "THAWED"); + cg_destroy(child); + cg_destroy(parent); + cg_destroy(staging); + if (mounted) { + cg_destroy(v1cg); + umount(v1root); + } + rmdir(v1root); + free(v1cg); + free(staging); + free(child); + free(parent); + return ret; +} + /* * Get the current frozen_usec for the cgroup. */ @@ -1479,6 +1583,7 @@ struct cgfreezer_test { T(test_cgfreezer_stopped), T(test_cgfreezer_ptraced), T(test_cgfreezer_vfork), + T(test_cgfreezer_nonleaf), T(test_cgfreezer_time_empty), T(test_cgfreezer_time_simple), T(test_cgfreezer_time_populate), -- 2.53.1-Meta