[PATCH v2 0/2] cgroup/cpuset: fix DL attach bandwidth accounting

Guopeng Zhang posted 2 patches 1 month, 1 week ago
include/linux/sched/deadline.h  |   9 +++
kernel/cgroup/cpuset-internal.h |   1 +
kernel/cgroup/cpuset.c          | 105 ++++++++++++++++++++++----------
kernel/sched/deadline.c         |  13 +++-
4 files changed, 92 insertions(+), 36 deletions(-)
[PATCH v2 0/2] cgroup/cpuset: fix DL attach bandwidth accounting
Posted by Guopeng Zhang 1 month, 1 week ago
Hi,

cpuset_can_attach() and set_cpus_allowed_dl() must make the same
decision about whether migrating a SCHED_DEADLINE task requires moving
bandwidth accounting between root domains.

The can_attach path used the destination cpuset effective CPU mask for
that decision. The attach path, however, applies a per-task target mask
which is constrained by task_cpu_possible_mask(), cpu_active_mask, and
the fallback walk up the cpuset hierarchy. On asymmetric CPU systems,
that per-task mask can be a strict subset of the destination cpuset
effective mask. This can make cpuset_can_attach() skip destination
bandwidth reservation while set_cpus_allowed_dl() later performs the
source-side bandwidth subtraction.

There is also an internal cpuset_can_attach() failure path where
temporary DL migration state can be left behind if a later per-task
check fails before cpuset marks attach_in_progress.

Patch 1 resets the temporary DL migration state on those internal
cpuset_can_attach() failure paths.

Patch 2 computes the same per-task target mask in cpuset_can_attach()
that cpuset_attach_task() later applies, and only includes DL tasks that
actually need a root-domain bandwidth move in the destination bandwidth
reservation.

The broader can_attach()/attach() transaction window is left unchanged.
This series does not attempt to rework sched_setattr() or source cpuset
resmask TOCTOU issues. It only aligns the reservation decision with the
attach-time bandwidth move decision and fixes the temporary state leak.

Guopeng Zhang (2):
  cgroup/cpuset: reset DL migration state on can_attach() failure
  cgroup/cpuset: align DL bandwidth reservation with attach target mask

 include/linux/sched/deadline.h  |   9 +++
 kernel/cgroup/cpuset-internal.h |   1 +
 kernel/cgroup/cpuset.c          | 105 ++++++++++++++++++++++----------
 kernel/sched/deadline.c         |  13 +++-
 4 files changed, 92 insertions(+), 36 deletions(-)

---
Changes since v1:
- Split the original patch into two patches.
- Reset temporary DL migration state on cpuset_can_attach() internal
  failure paths.
- Computed the same per-task attach mask in cpuset_can_attach() as
  cpuset_attach_task().
- Kept nr_migrate_dl_tasks counting all migrating DL tasks for cpuset
  task accounting, while restricting sum_migrate_dl_bw to tasks that need
  destination DL bandwidth reservation.
- Tightened Fixes tags.
- Documented the existing aggregate reservation invariant near the
  dl_bw_cpu selection.
- Removed the unnecessary RCU guard from dl_task_needs_bw_move().

v1:
  https://lore.kernel.org/all/20260421083449.95750-1-zhangguopeng@kylinos.cn

-- 
2.43.0