Re: [PATCH] cpuset: Fix multi-source deadline task accounting and bandwidth bypass

From: Dietmar Eggemann

Date: Wed May 13 2026 - 12:37:54 EST


On 12.05.26 03:03, Aaron Tomlin wrote:
> During a batch migration where threads in a taskset originate from
> multiple source cpusets (e.g., via cgroup.procs), cpuset_can_attach()
> and cpuset_attach() currently evaluate the source cpuset exactly once
> by caching the first task's oldcs.
>
> This creates two distinct critical flaws for SCHED_DEADLINE tasks:
>
> 1. oldcs->nr_deadline_tasks is decremented solely on the first
> source cpuset. If tasks originated from other cpusets, their
> counts are permanently leaked, and the first cpuset permanently
> underflows.
>
> 2. cpumask_intersects() is evaluated strictly against the first
> task's source cpuset. This allows tasks originating from
> entirely isolated root domains to silently bypass the
> dl_bw_alloc() admission control.
>
> This patch refactors the deadline accounting to evaluate task_cs(task)
> on a per-task basis during the cgroup_taskset_for_each() loops. To
> achieve accurate accounting before the core cgroup migration actually
> executes, the permanent nr_deadline_tasks increments/decrements are
> shifted into cpuset_can_attach(). If the migration aborts, the counts
> are gracefully reverted via an internal rollback loop or the
> cpuset_cancel_attach() callback.

Is there a testcase to provoke this issue in the current code?

I tried to move a process with 6 DL tasks from one cpuset to another by:

echo $PID > /sys/fs/cgroup/B/cgroup.procs

but in this case old_cs is the same for all these tasks.

[ 1991.852034] cgroup_migrate() (7) leader=[dl_batch_cgroup 823] threadgroup=1
[ 1991.852068] cgroup_migrate_execute() tset->nr_tasks=7
[ 1991.852238] cpuset_can_attach() (4) [dl_batch_cgroup 832] nr_migrate_dl_tasks=1 sum_migrate_dl_bw=104857 old_cs=ffff0000c4955200
[ 1991.852246] cpuset_can_attach() (4) [dl_batch_cgroup 833] nr_migrate_dl_tasks=2 sum_migrate_dl_bw=209714 old_cs=ffff0000c4955200
[ 1991.852248] cpuset_can_attach() (4) [dl_batch_cgroup 834] nr_migrate_dl_tasks=3 sum_migrate_dl_bw=314571 old_cs=ffff0000c4955200
[ 1991.852249] cpuset_can_attach() (4) [dl_batch_cgroup 835] nr_migrate_dl_tasks=4 sum_migrate_dl_bw=419428 old_cs=ffff0000c4955200
[ 1991.852249] cpuset_can_attach() (4) [dl_batch_cgroup 836] nr_migrate_dl_tasks=5 sum_migrate_dl_bw=524285 old_cs=ffff0000c4955200
[ 1991.852250] cpuset_can_attach() (4) [dl_batch_cgroup 837] nr_migrate_dl_tasks=6 sum_migrate_dl_bw=629142 old_cs=ffff0000c4955200
[ 1991.852328] cpuset_attach() (5) cs=ffff0000c1e9fc00 oldcs=ffff0000c4955200 cs->nr_deadline_tasks=6 oldcs->nr_deadline_tasks=6 cs->nr_migrate_dl_tasks=6

dl_batch_cgroup 823 823 19 - 0 TS
dl_batch_cgroup 823 832 140 0 - DLN
dl_batch_cgroup 823 833 140 0 - DLN
dl_batch_cgroup 823 834 140 0 - DLN
dl_batch_cgroup 823 835 140 0 - DLN
dl_batch_cgroup 823 836 140 0 - DLN
dl_batch_cgroup 823 837 140 0 - DLN

[...]