]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
cgroup: Fix cgroup_drain_dying() testing the wrong condition
authorTejun Heo <tj@kernel.org>
Wed, 25 Mar 2026 17:23:48 +0000 (07:23 -1000)
committerTejun Heo <tj@kernel.org>
Thu, 26 Mar 2026 00:08:04 +0000 (14:08 -1000)
commit4c56a8ac6869855866de0bb368a4189739e1d24f
tree671cfe0c2a9456f1a55dbdc6d4eb2131fa525d0d
parent6680c162b4850976ee52b57372eddc4450c1d074
cgroup: Fix cgroup_drain_dying() testing the wrong condition

cgroup_drain_dying() was using cgroup_is_populated() to test whether there are
dying tasks to wait for. cgroup_is_populated() tests nr_populated_csets,
nr_populated_domain_children and nr_populated_threaded_children, but
cgroup_drain_dying() only needs to care about this cgroup's own tasks - whether
there are children is cgroup_destroy_locked()'s concern.

This caused hangs during shutdown. When systemd tried to rmdir a cgroup that had
no direct tasks but had a populated child, cgroup_drain_dying() would enter its
wait loop because cgroup_is_populated() was true from
nr_populated_domain_children. The task iterator found nothing to wait for, yet
the populated state never cleared because it was driven by live tasks in the
child cgroup.

Fix it by using cgroup_has_tasks() which only tests nr_populated_csets.

v3: Fix cgroup_is_populated() -> cgroup_has_tasks() (Sebastian).

v2: https://lore.kernel.org/r/20260323200205.1063629-1-tj@kernel.org

Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Fixes: 1b164b876c36 ("cgroup: Wait for dying tasks to leave on rmdir")
Signed-off-by: Tejun Heo <tj@kernel.org>
Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
kernel/cgroup/cgroup.c