From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795977363; b=yfxLp/4UtG5DE3E9mwRazY4qvrkaMfiY3Isy6XzRMcwmvXIFJwk4SCbholeA/UJ0qBZz 6YmA7gX55JSnLMyZtU5IJx0+Zh29kYpy/6sNgMQfaJJmOdHaFUWTxOzc1t5cXZ5xs+5rb spZ02yR60VC6ygPkA+yb9FYvOB4h2XlfomZF3k3wtA+0n1SxwmrNUX8d2lZuKFSebInFy 0ei8C7luXNNNEWnhhSgx3V5oZLFPziCQjtca+yOcHgVm3MMClwolX1UCk0mXY22+q7lKE YUHzNiGPNYN5EZBxJCcICVoaQ41oEppxOU+fxGPcZCEijXUVM/YadZh1sV0rfPOiV7A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795977363; 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=AVbgDIiclzmscV98AGJV1TZE+EhelbCFuee0bw9+7zIVMahDN7it0Em2U8xwe+FAzc63 2aMEP4C/1QZnqNeyniPgEOkYiw9DvR4FuzPSIATwRgnS1cpM9hHhSlW0D7/W2CVFjNHjC bNxYAosFo1oKAt1mubKbPxT6oGV3Ilogd0Ktqk9qA0WF9A6sAKBF5BflKTlqhykzRZOLV +/6XKEM19y7EvO0qH2bho69BmjRxvkrDVdeO84pfqUUErrDhdke/GZCotHYmBLw9U/y/L d4+lkPF7pgl8Sz6ohq+kaMAKKM702UbnfgFrTm4UskzSg1EmmkL3vMSCJs6cGj/z9Ew== 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=t6irD41m; arc=none smtp.remote-ip=95.215.58.177 Received: from mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 1D613606A33A for ; Sun, 29 Nov 2026 18:36:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D613606A33A 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=t6irD41m 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=1795977361; v=1; x=1796582161; b=t6irD41m/yQ3ANAZWD/N+vBzYFalv8MS2W85xyzqngqJg3ALPRIt5Pda/gw8eDmeWxXKCYxN 1wQ5eMTsoYSJAWY2MRFZDSYlpWTsKr3WV545qsdg8KngaOHOmOtn2W77ePpL3tRtRwaqDiQ3VEo ZH1Q1nP3R/KTIg20k9BLkmdA= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id b9f44feb3edf7841; Sun, 29 Nov 2026 18:36:01 +0000 X-Mizu-Trace-ID: b9f44feb3edf7841 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 6/9] selftests/cgroup: test cgroup.kill in a threaded cgroup Date: Sun, 29 Nov 2026 10:35:21 -0800 Message-ID: <20261129183524.1052436-7-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: 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