From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060133; b=3RnBTgUzLNtCaF94VDMuDdEbA/xPxND7DA2CW1FNIxd7J3nsrpkBN18IsgZF3ChiXcNb gmGtRu1FHd/ssZBT051lqH8NF/Hc1FqPr2ZqReR6w9e2YX5iPc6GzdLOtx3+xa0UzQPLi hSQtQ5LHb/qThTXJguIobwaNeZ2znVhc/i1HFhgR9bzVkN/uEeELjv2w5G6Z5aImbRQos V5dmg6D3f67tTzQkyZSlKAZJmQhGBhj/yCD0LEWgPOnHL57CK2RFalTN9qqo3oNfpnkeK WcZodh74bBoOGu9CenGay8VaHRBa6zjvpb3IC1mkHMjv2TwDoV8Fcqg4ICpLhtXKfuw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060133; 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=+O2GBqH4AtNpEhLN/wm8G+mH0oiuOxFtMBw4u3xFap4=; b=j/r305KjOQBXlBYbcLEpWfDjuvuZhUHWdWYt9YBYZMAwOwEw9e2VqYL8BKrknuoQqzn5 VSyyj7KAsinz1rFX2DdSgMKDpARAOE42mg+s6rHPytzowrb6IcC2fjXZe2dCePUVZCmN8 e6VYde+Pv/d26CSWirpTNvFcJlYOm/JXgHPUp8wLttCWtH/u2l8iTZ1Tn78xuEQQv1juE 6OG98bbnBpt31O4XiNoG40H0DBBjezEguca7V3BfOIEjeOY1yfQhF+LZkeg7F+NE4HZNO WhGFsDJ0H1yZ1EXVlwtiF33hQO7Y5m1FI4hDTbMkq8c62dZXJqSYoXerA+SCpodmayA== 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="kqz1/T1+"; arc=none smtp.remote-ip=95.215.58.171 Received: from mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (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 98495606A33A for ; Mon, 30 Nov 2026 17:35:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 98495606A33A 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=kqz1/T1+ X-Envelope-To: cgroups@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ncOOK6JyypZCAnH3ny/bc7aTVkOBIfxVMsunmowZ658=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796060130; v=1; x=1796664930; b=kqz1/T1+ShrliVwxOSx5GLFRXg1ZgTIkh8jdhoACDbGaN2U8B6QPNMV/jJALD6HnXeIv6+Xo ehUFsgPO5DqBcQRmvBPlcIFGQNK2PfrAZ0XO52IbRL6dY0aN/eMszcAu8loDE8ugXHWjuByT679 jVlKa+0HA5kPvU2k0do4AFtk= X-Envelope-To: cgroups@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 36d75fc5791683ed; Mon, 30 Nov 2026 17:35:28 +0000 X-Mizu-Trace-ID: 36d75fc5791683ed 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 v2 08/11] selftests/cgroup: test cgroup.kill in a threaded cgroup Date: Mon, 30 Nov 2026 09:34:22 -0800 Message-ID: <20261130173425.4117363-9-shakeel.butt@linux.dev> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261130173425.4117363-1-shakeel.butt@linux.dev> References: <20261130173425.4117363-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 Check that writing cgroup.kill in a threaded cgroup fails with EOPNOTSUPP and kills nothing, and that the thread root can still kill a process whose thread was moved into the threaded cgroup. This is existing behavior. The next patches change how cgroup.kill checks for threaded cgroups, and this test shows that the behavior stays the same. Signed-off-by: Shakeel Butt --- tools/testing/selftests/cgroup/test_kill.c | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_kill.c b/tools/testing/selftests/cgroup/test_kill.c index 756bc7193d4b..d3fab2ba732b 100644 --- a/tools/testing/selftests/cgroup/test_kill.c +++ b/tools/testing/selftests/cgroup/test_kill.c @@ -471,6 +471,73 @@ static int test_cgkill_exited_leader_migrated(const char *root) return ret; } +/* + * cgroup.kill is refused in a threaded cgroup, as killing is directed at + * whole processes. The thread root can still kill a process whose thread + * was moved into the threaded cgroup. + */ +static int test_cgkill_threaded(const char *root) +{ + char *parent = NULL, *threaded = NULL; + int ret = KSFT_FAIL; + pid_t pid = -ESRCH; + + parent = cg_name(root, "cg_test_kill_thread_root"); + if (!parent) + goto cleanup; + + threaded = cg_name(parent, "threaded"); + if (!threaded) + goto cleanup; + + if (cg_create(parent) || cg_create(threaded)) + goto cleanup; + + if (cg_write(threaded, "cgroup.type", "threaded")) + goto cleanup; + + pid = cg_run_nowait(parent, child_fn, NULL); + if (pid < 0 || cg_wait_for_proc_count(parent, 1)) + goto cleanup; + + if (cg_write_numeric(threaded, "cgroup.threads", pid)) + goto cleanup; + + if (cg_write(threaded, "cgroup.kill", "1") != -EOPNOTSUPP) + goto cleanup; + + /* + * The refused write must not kill the child. A SIGKILL from it would + * end the child well within this delay. + */ + usleep(100000); + if (waitpid(pid, NULL, WNOHANG)) { + pid = -ESRCH; + goto cleanup; + } + + if (cg_kill_wait(parent)) + goto cleanup; + + if (cg_read_strcmp_wait(parent, "cgroup.events", "populated 0\n")) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + if (pid > 0) { + kill(pid, SIGKILL); + wait_for_pid(pid); + } + if (threaded) + cg_destroy(threaded); + if (parent) + cg_destroy(parent); + free(threaded); + free(parent); + return ret; +} + #define T(x) { x, #x } struct cgkill_test { int (*fn)(const char *root); @@ -482,6 +549,7 @@ struct cgkill_test { T(test_cgkill_clone_into_killed), T(test_cgkill_exited_leader), T(test_cgkill_exited_leader_migrated), + T(test_cgkill_threaded), }; #undef T -- 2.53.1-Meta