* [PATCH] sched_ext: don't rehome a dead task in scx_cgroup_task_migrated
@ 2026-08-11 10:31 Tao Cui
2026-08-14 19:04 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Tao Cui @ 2026-08-11 10:31 UTC (permalink / raw)
To: tj; +Cc: sched-ext, void, arighi, changwoo, linux-kernel, cui.tao, Tao Cui
From: Tao Cui <cuitao@kylinos.cn>
A task can exit between cgroup migration commit and the MIGRATED callback:
sched_ext_dead() marks it SCX_TASK_DEAD before cgroup_task_dead() removes it
from the migration list, so scx_cgroup_task_migrated() can pick up a dead
task and call scx_rehome_task(), which re-enables it and leaks the BPF
scheduler's per-task resources. The other scx_rehome_task() callers already
check for this; do the same here.
Fixes: bf9dee58ab56 ("sched_ext: Re-home tasks on cgroup migration")
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
kernel/sched/ext/sub.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
index b81254be1b04..8f8d21b85abe 100644
--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -2083,6 +2083,13 @@ static void scx_cgroup_task_migrated(struct cgroup_task_migrate_ctx *ctx)
return;
rq = task_rq_lock(p, &rf);
+
+ if (scx_get_task_state(p) == SCX_TASK_DEAD) {
+ /* sched_ext_dead() raced us */
+ task_rq_unlock(rq, p, &rf);
+ return;
+ }
+
scx_rehome_task(to, p);
task_rq_unlock(rq, p, &rf);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] sched_ext: don't rehome a dead task in scx_cgroup_task_migrated
2026-08-11 10:31 [PATCH] sched_ext: don't rehome a dead task in scx_cgroup_task_migrated Tao Cui
@ 2026-08-14 19:04 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-08-14 19:04 UTC (permalink / raw)
To: Tao Cui; +Cc: Tao Cui, void, arighi, changwoo, sched-ext, linux-kernel
Hello,
On Tue, Aug 11, 2026 at 06:31:22PM +0800, Tao Cui wrote:
> A task can exit between cgroup migration commit and the MIGRATED callback:
> sched_ext_dead() marks it SCX_TASK_DEAD before cgroup_task_dead() removes it
> from the migration list, so scx_cgroup_task_migrated() can pick up a dead
> task and call scx_rehome_task(), which re-enables it and leaks the BPF
> scheduler's per-task resources. The other scx_rehome_task() callers already
> check for this; do the same here.
I don't think this window exists. SCX_TASK_DEAD is set only by
sched_ext_dead() from finish_task_switch(), which a task reaches only
after exit_signals(), and exit_signals() sets PF_EXITING inside
cgroup_threadgroup_change_begin(). The MIGRATED notifiers run inside
cgroup_migrate_execute() with the same rwsem write-held through
cgroup_attach_lock(), so no task in the set can enter the exit path
until the migration is done. Tasks which were already exiting are
filtered out by the PF_EXITING test in cgroup_migrate_add_task().
The DEAD tests you referenced are in scx_task_iter walks which run
without the threadgroup rwsem, where dying tasks can actually show up.
Did you try to reproduce the leak? When code review turns up a
suspected bug, it's a good idea to reproduce it first to verify the
assumptions before writing a fix.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-14 19:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 10:31 [PATCH] sched_ext: don't rehome a dead task in scx_cgroup_task_migrated Tao Cui
2026-08-14 19:04 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox