[PATCHSET cgroup/for-7.2] cgroup: Per-css kill_css_finish deferral
From: Tejun Heo
Date: Mon May 04 2026 - 20:51:32 EST
Hello,
Follow-up to 93618edf7538 ("cgroup: Defer css percpu_ref kill on rmdir
until cgroup is depopulated") in cgroup/for-7.1-fixes, assumed merged
into cgroup/for-7.2.
That commit fixed the rmdir race by deferring kill_css_finish() at the
cgroup level so ->css_offline() runs only after PF_EXITING tasks have
left the cgroup. cgroup_apply_control_disable() has the same race shape
(PF_EXITING tasks pinning the dying controller's css while
->css_offline() runs), but fixing it requires switching
cgroup_lock_and_drain_offline()'s wait predicate from
percpu_ref_is_dying() to css_is_dying() to cover the deferral window -
too invasive for -stable, hence -7.2.
This series:
- Replaces the cgroup-level deferral with a per-subsys-css mechanism
so each controller css independently defers kill_css_finish() until
its own subtree drains.
- Pairs smp_mb()s in kill_css_sync() and css_update_populated() to
interlock the synchronous- and deferred-fire decisions.
- Wires cgroup_apply_control_disable() through the per-css deferral
and switches drain_offline to wait on css_is_dying.
After the predicate switch, a +ctrl re-enable issued while a deferred
-ctrl is still draining blocks in TASK_UNINTERRUPTIBLE on offline_waitq
until the dying css drains. Pre-existing for rmdir; the apply path now
joins it.
Verified by 200001 iterations of repro-a72f73c4dd9b, per-commit
deterministic repros for the bug-chain commits, 5292 iterations of
stress-disable-control, and targeted ftrace coverage of rmdir,
apply_disable, and nested-destroy paths. No warnings or stalls.
Based on cgroup/for-7.2 (d8769544bde5) with cgroup/for-7.1-fixes
(93618edf7538) assumed merged.
Patches:
[PATCH 1/5] cgroup: Inline cgroup_has_tasks() in cgroup.h
[PATCH 2/5] cgroup: Annotate unlocked nr_populated_* accesses with READ_ONCE/WRITE_ONCE
[PATCH 3/5] cgroup: Move populated counters to cgroup_subsys_state
[PATCH 4/5] cgroup: Add per-subsys-css kill_css_finish deferral
[PATCH 5/5] cgroup: Defer kill_css_finish() in cgroup_apply_control_disable()
Git tree: git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git cgroup-drain-for-7.2
include/linux/cgroup-defs.h | 30 ++++---
include/linux/cgroup.h | 27 ++++++-
kernel/cgroup/cgroup.c | 188 +++++++++++++++++++++++++-------------------
kernel/cgroup/cpuset-v1.c | 2 +-
kernel/cgroup/cpuset.c | 2 +-
5 files changed, 148 insertions(+), 101 deletions(-)
Thanks.
--
tejun