Re: [PATCH] cgroup: fix race between task migration and iteration
From: Michal Koutný
Date: Thu Feb 12 2026 - 05:51:12 EST
Hi Qingye.
On Wed, Feb 11, 2026 at 09:24:04AM +0000, zhaoqingye <zhaoqingye@xxxxxxxxx> wrote:
...
> Under this setup, cgroup.procs can intermittently show only PID 101
> while skipping PID 103. Once the migration completes, reading the
> file again shows all tasks as expected.
Yup, such a skip is buggy -- at places when task is removed from
task->cg_list's list, the iterators should be skipped.
> Note that this change does not allow removing the existing
> css_set_skip_task_iters() call in css_set_move_task().
Sure, css_set_move_task() isn't called together with
cgroup_migrate_add_task() under one css_set_lock.
> The race window between migration and iteration is very small, and
> css_task_iter is not on a hot path. In the worst case, when an
> iterator is positioned on the first thread of the migrating process,
> cgroup_migrate_add_task() may have to skip multiple tasks via
> css_set_skip_task_iters().
Only when it->task_pos == &task->cg_list (in css_task_iter_skip()).
> However, this only happens when migration and iteration actually race,
> so the performance impact is negligible compared to the correctness
> fix provided here.
Of course, correctness > performance in these discrete cases.
This is a good catch, well described and correction is OK.
Reviewed-by: Michal Koutný <mkoutny@xxxxxxxx>