Skip to contentSkip to conversation

cgroup/cpuset: Fix misplaced DL migration reset

PATCH In review Karl Mehltretter 3 participants 3 messages Sep 1 – Sep 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup/cpuset: Fix misplaced DL migration reset

Mainline commit 4a39eda5fdd8 ("cgroup/cpuset: Reset DL migration state on can_attach() failure") puts the common error cleanup in cpuset_can_attach(). The 6.6.y backport instead placed that hunk at cpuset_can_fork()'s similarly named out_unlock label, while removing cpuset_can_attach()'s two existing targeted resets.

If cpuset_can_attach() fails after accounting a SCHED_DEADLINE task, cgroup_migrate_execute() does not call cpuset_cancel_attach() for the failing subsystem. The temporary migration fields remain set, and a later successful migration can consume the stale state and corrupt deadline-task and pending-bandwidth accounting.

Move the reset to cpuset_can_attach()'s common error exit. It is not needed in cpuset_can_fork(), which never accumulates migration DL state.

Fixes 14897ef9341c ("cgroup/cpuset: Reset DL migration state on can_attach() failure")
Assisted-by LLM

---
Applies to Linux 6.6.155 and 6.6.156-rc1.

A controlled QEMU A/B on 6.6.155 forced an attach error after accounting a real SCHED_DEADLINE task. The affected kernel returned with nr_migrate_dl_tasks=1 and sum_migrate_dl_bw=104857; both fields were zero with this patch.

The equivalent 6.1.y correction is submitted separately.

 kernel/cgroup/cpuset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +2 -2
index f9c7178f51ada..bb413045d1744 100644
@@ -2630,6 +2630,8 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)
 	 */
 	cs->attach_in_progress++;
 out_unlock:
+	if (ret)
+		reset_migrate_dl_data(cs);
 	mutex_unlock(&cpuset_mutex);
 	return ret;
 }
@@ -3462,8 +3464,6 @@ static int cpuset_can_fork(struct task_struct *task, struct css_set *cset)
 	cs->attach_in_progress++;
 
 out_unlock:
-	if (ret)
-		reset_migrate_dl_data(cs);
 	mutex_unlock(&cpuset_mutex);
 	return ret;
 }
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 5 lines

Mainline commit 4a39eda5fdd8 ("cgroup/cpuset: Reset DL migration state on can_attach() failure") puts the common error cleanup in cpuset_can_attach(). The 6.6.y backport instead placed that hunk at cpuset_can_fork()'s similarly named out_unlock label, while removing cpuset_can_attach()'s two existing targeted resets.

Same like the other mail, maintainer ack will be great.

Signature · 2 lines
Thanks,
Sasha
Acked-by on v1 1/1
#2 lore raw
In reply to Karl Mehltretter
Quoted 45 lines · Karl Mehltretter

Mainline commit 4a39eda5fdd8 ("cgroup/cpuset: Reset DL migration state on can_attach() failure") puts the common error cleanup in cpuset_can_attach(). The 6.6.y backport instead placed that hunk at cpuset_can_fork()'s similarly named out_unlock label, while removing cpuset_can_attach()'s two existing targeted resets.

If cpuset_can_attach() fails after accounting a SCHED_DEADLINE task, cgroup_migrate_execute() does not call cpuset_cancel_attach() for the failing subsystem. The temporary migration fields remain set, and a later successful migration can consume the stale state and corrupt deadline-task and pending-bandwidth accounting.

Move the reset to cpuset_can_attach()'s common error exit. It is not needed in cpuset_can_fork(), which never accumulates migration DL state.

Fixes 14897ef9341c ("cgroup/cpuset: Reset DL migration state on can_attach() failure")
Assisted-by LLM

---
Applies to Linux 6.6.155 and 6.6.156-rc1.

A controlled QEMU A/B on 6.6.155 forced an attach error after accounting a real SCHED_DEADLINE task. The affected kernel returned with nr_migrate_dl_tasks=1 and sum_migrate_dl_bw=104857; both fields were zero with this patch.

The equivalent 6.1.y correction is submitted separately.

 kernel/cgroup/cpuset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +2 -0
index f9c7178f51ada..bb413045d1744 100644
@@ -2630,6 +2630,8 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)
 	 */
 	cs->attach_in_progress++;
 out_unlock:
+	if (ret)
+		reset_migrate_dl_data(cs);
 	mutex_unlock(&cpuset_mutex);
 	return ret;
 }

kernel/cgroup/cpuset.c static int cpuset_can_fork(struct task_struct *task, struct css_set *cset) · line 3469

Quoted 8 lines
kernel/cgroup/cpuset.c +0 -2
@@ -3462,8 +3464,6 @@ static int cpuset_can_fork(struct task_struct *task, struct css_set *cset)
 	cs->attach_in_progress++;
 
 out_unlock:
-	if (ret)
-		reset_migrate_dl_data(cs);
 	mutex_unlock(&cpuset_mutex);
 	return ret;
 }