sched_ext: Drop %NONE early return in scx_disable_and_exit_task()
Subsystems (2)
Tejun Heo
reviewerPATCH 1/1 sched_ext: Drop %NONE early return in scx_disable_and_exit_task()
d3e73a0808dd ("sched_ext: Handle SCX_TASK_NONE in disable/switched_from paths") skipped the trailing scx_set_task_sched(p, NULL) on %NONE tasks. After scx_fail_parent() parks a task at %NONE/sched=parent and the parent is later freed via queue_rcu_work() during root_disable, the preserved p->scx.sched dangles - print_scx_info() from sched_show_task() reads sch->ops.name from freed memory.
Drop the early return. __scx_disable_and_exit_task() already short- circuits on %NONE and the SUB_INIT block was cleared by scx_fail_parent()'s earlier call, so clearing p->scx.sched is the only work left - and the one thing the path actually needs.
--- kernel/sched/ext.c | 9 --------- 1 file changed, 9 deletions(-)
kernel/sched/ext.c +0 -9
@@ -3703,15 +3703,6 @@ static void scx_sub_init_cancel_task(struct scx_sched *sch, struct task_struct *static void scx_disable_and_exit_task (struct scx_sched *sch,struct task_struct *p) { -/* -* %NONE means @p is already detached at the SCX level (e.g. handed -* back to the parent by scx_fail_parent() with no init to undo). -* Skip to avoid clobbering scx_task_sched() and writing %NONE again -* on a state that's already %NONE. -*/ -if (scx_get_task_state (p) ==SCX_TASK_NONE ) -return ; -__scx_disable_and_exit_task (sch, p);/*
Signature · 1 line
2.51.0
Hi Tejun,
Quoted 26 lines · Tejun Heo
d3e73a0808dd("sched_ext: HandleSCX_TASK_NONEin disable/switched_from paths") skipped the trailingscx_set_task_sched(p, NULL)on %NONE tasks. Afterscx_fail_parent()parks a task at %NONE/sched=parent and the parent is later freed viaqueue_rcu_work()duringroot_disable, the preservedp->scx.scheddangles -print_scx_info()fromsched_show_task()readssch->ops.namefrom freed memory.Drop the early return.
__scx_disable_and_exit_task()already short- circuits on %NONE and theSUB_INITblock was cleared by scx_fail_parent()'s earlier call, so clearingp->scx.schedis the only work left - and the one thing the path actually needs.Fixes d3e73a0808dd ("sched_ext: Handle SCX_TASK_NONE in disable/switched_from paths")Signed-off-by Tejun Heo <[email protected]>--- kernel/sched/ext.c | 9 --------- 1 file changed, 9 deletions(-)kernel/sched/ext.c +0
-0@@ -3703,15 +3703,6 @@ static void scx_sub_init_cancel_task(struct scx_sched *sch, struct task_struct *static void scx_disable_and_exit_task (struct scx_sched *sch,struct task_struct *p) {
kernel/sched/ext.c static void scx_sub_init_cancel_task(struct scx_sched *sch, struct task_struct * · line 3706
Quoted 10 lines
kernel/sched/ext.c +0
-9-/* -* %NONE means @p is already detached at the SCX level (e.g. handed -* back to the parent by scx_fail_parent() with no init to undo). -* Skip to avoid clobbering scx_task_sched() and writing %NONE again -* on a state that's already %NONE. -*/ -if (scx_get_task_state (p) ==SCX_TASK_NONE ) -return ; -__scx_disable_and_exit_task (sch, p);
I was wondering if a task here can have both SCX_TASK_SUB_INIT and SCX_TASK_NONE, because in this case scx_sub_init_cancel_task() (called from the SCX_TASK_SUB_INIT block, further down in this function) would be called for a task that never entered the sub-sched initialization path, which would be incorrect from a task lifecycle perspective.
But this should never happen: SCX_TASK_SUB_INIT is set in scx_sub_enable() on tasks that just successfully passed __scx_init_task(sch, p, false) against a child sub-sched, so those tasks are in READY/ENABLED, not NONE.
Maybe we can add something like this in the block below to make this clear:
/*
* SCX_TASK_SUB_INIT is only set on the sub-enable path, so it is always clear
* when @p reaches this function with SCX_TASK_NONE.
*/
Apart than that, LGTM.
Thanks,
-Andrea