Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shakeel Butt" <shakeel.butt@linux.dev>, "Tejun Heo" <tj@kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutny" <mkoutny@suse.com>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Christian Brauner" <brauner@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"T . J . Mercier" <tjmercier@google.com>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Meta kernel team" <kernel-team@meta.com>,
	linux-mm@kvack.org
Subject: Re: [PATCH v3 09/12] selftests/cgroup: test cgroup.kill in and below a threaded cgroup
Date: Sat, 05 Dec 2026 18:42:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-251806@kernel.org> (raw)
In-Reply-To: <20261204184041.1489976-10-shakeel.butt@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/cgroup: race after cg_run_nowait() in
  test_cgkill_below_threaded()
- [Low] selftests/cgroup: test_cgkill_below_threaded() assumes mixable
  root cgroup
--

commit b98e574a8f900b60b1c3717304d803d6c6ea5814
Author: Shakeel Butt <shakeel.butt@linux.dev>

selftests/cgroup: test cgroup.kill in and below a threaded cgroup

This commit adds two tests to test_kill.c verifying that writing cgroup.kill
fails with EOPNOTSUPP and kills nothing both in a threaded cgroup and in an
invalid domain below a threaded cgroup.

> diff --git a/tools/testing/selftests/cgroup/test_kill.c b/tools/testing/selftests/cgroup/test_kill.c
> index 756bc7193d4b3..e8db5b3356a49 100644
> --- a/tools/testing/selftests/cgroup/test_kill.c
> +++ b/tools/testing/selftests/cgroup/test_kill.c
> @@ -471,6 +471,131 @@ static int test_cgkill_exited_leader_migrated(const char *root)

[ ... ]

> +static int test_cgkill_below_threaded(const char *root)
> +{
> +	char *a = NULL, *b = NULL, *c = NULL;
> +	int ret = KSFT_FAIL;
> +	pid_t pid = -ESRCH;
> +
> +	a = cg_name(root, "cg_test_kill_below_threaded");
> +	b = cg_name(root, "cg_test_kill_below_threaded/b");
> +	c = cg_name(root, "cg_test_kill_below_threaded/b/c");
> +	if (!a || !b || !c)
> +		goto cleanup;
> +
> +	if (cg_create(a) || cg_create(b) || cg_create(c))
> +		goto cleanup;
> +
> +	if (cg_write(c, "cgroup.type", "threaded") ||
> +	    cg_write(a, "cgroup.type", "threaded"))
> +		goto cleanup;

[Severity: Low]
Will turning a threaded fail when test_kill runs inside a cgroup namespace?

In a cgroup namespace, the cgroup2 mount root has a non-NULL parent, so
cgroup_is_mixable() is false.  When root has a populated domain child or a
domain controller in cgroup.subtree_control, cgroup_enable_threaded() rejects
a/cgroup.type with -EOPNOTSUPP.

Creating an intermediate parent domain cgroup under root (parent/a/b/c) and
spawning pid in parent, as test_cgkill_threaded() does, avoids relying on a
mixable root.

> +
> +	pid = cg_run_nowait(root, child_fn, NULL);
> +	if (pid < 0)
> +		goto cleanup;
> +
> +	if (cg_write_numeric(c, "cgroup.threads", pid))
> +		goto cleanup;

[Severity: Low]
Can cg_write_numeric(c, "cgroup.threads", pid) race with cg_run_nowait()?

When cg_run_nowait() falls back from clone3(CLONE_INTO_CGROUP) to fork(), the
parent returns before the child writes its PID to root/cgroup.procs:

Parent                            Child (fork fallback)
cg_run_nowait(root, ...)
  fork()
cg_write_numeric(c, ...)
                                  cg_write(root, "cgroup.procs", ...)
                                    <-- moves child back out of c
cg_write(b, "cgroup.kill", "1")

If test_kill runs in root, the child's delayed write moves it back out of c
before b/cgroup.kill is tested, leaving c empty so a broken cgroup.kill could
pass silently.  If test_kill runs in a non-root cgroup, the child is still in
that cgroup and cgroup_attach_permissions() fails setup with -EOPNOTSUPP.

Spawning in a dedicated parent cgroup and waiting with
cg_wait_for_proc_count(parent, 1), as test_cgkill_threaded() does, closes the
race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204184041.1489976-1-shakeel.butt@linux.dev?part=9


  reply	other threads:[~2026-12-05 18:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:40 [PATCH v3 00/12] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 01/12] cgroup: don't lose a task in css_task_iter when a migration fails Shakeel Butt
2026-12-05  7:54   ` Tejun Heo
2026-12-04 18:40 ` [PATCH v3 02/12] cgroup: kill a child forked while cgroup.kill runs Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 03/12] cgroup: refuse cgroup.kill below a threaded cgroup Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 04/12] cgroup/freezer: check own tasks and descendants for the frozen state Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 05/12] cgroup/freezer: don't update the frozen state of removed cgroups Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 06/12] cgroup/freezer: test the freeze trap bit under siglock Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 07/12] selftests/cgroup: test cgroup.procs reads across a failed migration Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 08/12] selftests/cgroup: test the frozen state of a cgroup with tasks and children Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 09/12] selftests/cgroup: test cgroup.kill in and below a threaded cgroup Shakeel Butt
2026-12-05 18:42   ` sashiko-bot [this message]
2026-12-04 18:40 ` [PATCH v3 10/12] cgroup: factor out cgroup_kn_break_active() and cgroup_kn_unbreak_active() Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 11/12] cgroup: don't hold cgroup_mutex for cgroup.kill Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 12/12] cgroup/freezer: don't hold cgroup_mutex for cgroup.freeze Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:54 ` [PATCH v3 00/12] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze Shakeel Butt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-251806@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=brauner@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=oleg@redhat.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    --cc=tjmercier@google.com \
    --cc=usama.arif@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox