From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.222 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795977363; b=GkZfSmKFjRibTeGMnAxlqSG8fhmxRbnFjeCqvH8cijmj+YHImEA7u4R5QDdz/nZfHiUt YDmMi02fol5TrvQHUBFPso6+WPj88vt9P+WXDvJfr9Af+FNqAYt4HoGEGMSuPhnFqUuez 0BJEENyrObQ3OwcC5l4zSb07tfDlSUduBu325RHj2/MryeN7hcxGNXYCEoMGt79/mjvMp kLsLWhUw110NoWQ+ns9VbEWa3duvfWQwoIWZPMl+ejjons+ETBsC2ULy4vUylWJzzO36x eNKBuTdEq/vO5GfyB/TR/V5/O+ufzORoIU9BXnO//wX7jtFwtaeDct0Q6Se4p9qfvZw== 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=NEYDCRiz4Fy1kE9XGmtKztuwpKpaXBnO8nw17W30I83qe+rKhAgiAFsFRl6TRh13xAVR iK6vLFZg/110+LG52zSQahqiHT3Sk24wc07jbxTvOriGB5RiMKVnOKkJZueQ5dHg7SWm1 9kqMJjlydEtIi1ksD8S7dYj0MDVl/Bf5U8oBLNpVdxYmGYdDROrcovPUZU5qU7bsVCAyo TD6TkPyRRldPiUJ+bBbwPIef6r+jtRs3HX2mzjjqB1Cy6hL1662d374ZBKLOoqpzRI19V oavZELcVv+N01z/MRAr6dhV5acbQy19DTDOQSb80WcaoE9iecZ9nS7mjEfKHMwdrq2A== 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=91.218.175.222 Received: from mta0.migadu.com (out-222.mta0.migadu.com [91.218.175.222]) (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 144A9606A686 for ; Sun, 29 Nov 2026 18:36:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 144A9606A686 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: 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=1795977361; v=1; x=1796582161; b=t6irD41m/yQ3ANAZWD/N+vBzYFalv8MS2W85xyzqngqJg3ALPRIt5Pda/gw8eDmeWxXKCYxN 1wQ5eMTsoYSJAWY2MRFZDSYlpWTsKr3WV545qsdg8KngaOHOmOtn2W77ePpL3tRtRwaqDiQ3VEo ZH1Q1nP3R/KTIg20k9BLkmdA= X-Envelope-To: cgroups@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: 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