From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060133; b=FE2c5OHchztDI/1nI1jBJhUvS8G/pIrCQucchHDf8GJYeLjCR7kmrGMLmgPcRihNb9fl +mbCCtq8vTfwlHDtyHGtDOoI+BGCLsl9I5KZXQ0E4bE2F3m06BpKTkGV/4U2dylf/xO9t Gu0A7zDab6E9t49GOWS+txMnLCKdqFOV5WK0sh+Te267qdG9rFCBbiY9tTBtZH521TuL/ kdjk1CymPi1sMlomd2AHYNu4zCI0l/2yQA3aS5ZyPy5z+vf24Ghkii+Q7cFa1B3qPny7o btm4iGYd6P2G8u+ZknjuLBdpSoPB3zrq0fCJ5KGZWCr0hSVpffNSumDz26FiltizxEA== 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=i0o/BYj9/iHp0iCg+teklhANnavTU76eELRu0zmkJ5ULqt9jrhdsHN9wA0loffVrKEYU fBJAtObC3/P6zHzNE6dXdFifjZaTEGLSDddV7IhT2BKYwtaU+sis+QFe/qUxbMPr4wJFu Y6r980HqrGT+jFo7xwD9XXRPQ3R5QEo7IHfaj8XQhtcPXUYJGuaSYvcO9Bk45QKkY29iC tiop4S7Sb1kQ8aXlIbWrHbAd1/r8Syz911HzQZ+2k7LxX1ab89TmjWwsnUb6yvp4F53cm bAgx2TVMwynBJ55FfAkMooNrlGe8IFxzdxGRRwuFTH5TJMTGJhZLAW0sfZwfX+nawJw== 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.172 Received: from mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 A0009606A330 for ; Mon, 30 Nov 2026 17:35:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A0009606A330 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: linux-kernel@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: linux-kernel@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: linux-kernel@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