FAILED: patch "[PATCH] sched_ext: Fix CPU hotplug hang when a dying CPU's tasks sit" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x d35a535d3e3e71f92a051d94e415f43612c4edfc
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026101226-devotion-reassure-71fa@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From d35a535d3e3e71f92a051d94e415f43612c4edfc Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Wed, 23 Sep 2026 12:39:20 -1000
Subject: [PATCH] sched_ext: Fix CPU hotplug hang when a dying CPU's tasks sit
in the BPF scheduler
A CPU going down has to empty its own rq. Its hotplug thread waits in sched_cpu_wait_empty() until nothing else is left, and the only thing that wakes it is balance_push(), which runs from __schedule() on the dying CPU and pushes off the migratable tasks the CPU picks.
sched_ext breaks this. A task sitting on a user DSQ or held by the BPF scheduler is still counted on its rq, but an inactive CPU no longer calls ops.dispatch() and can't pull the task back. The dying CPU goes idle with the task still counted, and one of two things happens:
- Another CPU consumes the task. The rq empties without a __schedule() on the dying CPU, so the hotplug thread is never woken and cpu_down() hangs holding cpu_hotplug_lock.
- The task is affine only to the dying CPU. Nothing can move it, and the offline stalls until the watchdog ejects the BPF scheduler.
When the rq goes offline, re-enqueue every task on it that isn't already on the local DSQ. An enqueue on an offline rq lands on the local DSQ, so the dying CPU itself picks the tasks and balance_push() pushes them off, the same as for the other sched classes. From then on no sched_ext path on another CPU can pull a task off the rq.
ops.dispatch() currently stops as soon as the CPU goes inactive, and CPU hotplug then waits for an RCU grace period before taking the rq offline. A BPF-held task affine only to the dying CPU and preempted inside an RCU read-side critical section would block that grace period, and the rq would never go offline. Test SCX_RQ_ONLINE directly so that ops.dispatch() keeps running until the rq goes offline. Only the dying CPU's own hotplug thread clears the flag during teardown, and task_can_run_on_remote_rq() still keeps other rqs' tasks off the CPU.
kernel/sched/ext/ext.c +20 -2
@@ -2123,8 +2123,8 @@ static void set_task_runnable(struct rq *rq, struct task_struct *p) }/* -* list_add_tail() must be used. scx_bypass() depends on tasks being -* appended to the runnable_list. +* list_add_tail() must be used. scx_bypass() and rq_offline_scx() +* depend on tasks being appended to the runnable_list. */ list_add_tail (&p->scx.runnable_node, &rq->scx.runnable_list);
@@ -3731,8 +3731,26 @@ static void rq_online_scx(struct rq *rq)static void rq_offline_scx (struct rq *rq) { +struct task_struct *p, *n; + rq->scx.flags &= ~SCX_RQ_ONLINE ; + +/* sched domain rebuilds call rq_offline with the CPU staying alive */ +if (cpu_active (cpu_of (rq))) +return ; +scx_rescue_flush (rq); + +/* +* An offline CPU no longer calls ops.dispatch(). Re-enqueue its tasks +* onto the local DSQ so that they run here and balance_push() moves +* them off. +*/ +list_for_each_entry_safe_reverse (p, n, &rq->scx.runnable_list, scx.runnable_node) { +if (p->scx.dsq == &rq->scx.local_dsq) +continue ; +guard (sched_change)(p,DEQUEUE_SAVE |DEQUEUE_MOVE |DEQUEUE_NOCLOCK ); + } }static bool check_rq_for_timeouts (struct rq *rq)
kernel/sched/ext/inlines.h +7 -1
@@ -70,7 +70,13 @@ scx_dispatch_sched(struct scx_sched *sch, struct rq *rq,#endif /* CONFIG_EXT_SUB_SCHED */ } -if (unlikely (!SCX_HAS_OP (sch, dispatch)) || !scx_rq_online (rq)) +/* +* scx_rq_online() can't be used. Its cpu_active() test goes false +* before CPU hotplug waits for an RCU grace period, and +* rq_offline_scx() moves this CPU's tasks to the local DSQ only after +* the wait. The grace period can depend on those tasks running. +*/ +if (unlikely (!SCX_HAS_OP (sch, dispatch)) || !(rq->scx.flags &SCX_RQ_ONLINE ))return SCX_DSP_NONE ; dspc->rq = rq;
kernel/sched/ext/sub.c +0 -4
@@ -585,10 +585,6 @@ void scx_rescue_flush(struct rq *rq)lockdep_assert_rq_held (rq); -/* sched domain rebuilds call rq_offline with the CPU staying alive */ -if (cpu_active (cpu_of (rq))) -return ; -/* end the current rescue */ if (rq->scx.rescue.curr)scx_task_slice_ended (rq, rq->scx.rescue.curr);
kernel/sched/sched.h +3 -2
@@ -4205,8 +4205,9 @@ extern void balance_callbacks(struct rq *rq, struct balance_callback *head);* after which it is enqueued again. * * Typically this must be called while holding task_rq_lock, since most/all -* properties are serialized under those locks. There is currently one -* exception to this rule in sched/ext which only holds rq->lock. +* properties are serialized under those locks. There are currently two +* exceptions to this rule in sched/ext which only hold rq->lock: scx_bypass() +* and rq_offline_scx(). */ /*
Sasha Levin
maintainerPATCH 1/1 sched_ext: Fix CPU hotplug hang when a dying CPU's tasks sit in the BPF scheduler
From: Tejun Heo <[email protected]>
[ Upstream commit d35a535d3e3e71f92a051d94e415f43612c4edfc ]
A CPU going down has to empty its own rq. Its hotplug thread waits in sched_cpu_wait_empty() until nothing else is left, and the only thing that wakes it is balance_push(), which runs from __schedule() on the dying CPU and pushes off the migratable tasks the CPU picks.
sched_ext breaks this. A task sitting on a user DSQ or held by the BPF scheduler is still counted on its rq, but an inactive CPU no longer calls ops.dispatch() and can't pull the task back. The dying CPU goes idle with the task still counted, and one of two things happens:
- Another CPU consumes the task. The rq empties without a __schedule() on the dying CPU, so the hotplug thread is never woken and cpu_down() hangs holding cpu_hotplug_lock.
- The task is affine only to the dying CPU. Nothing can move it, and the offline stalls until the watchdog ejects the BPF scheduler.
When the rq goes offline, re-enqueue every task on it that isn't already on the local DSQ. An enqueue on an offline rq lands on the local DSQ, so the dying CPU itself picks the tasks and balance_push() pushes them off, the same as for the other sched classes. From then on no sched_ext path on another CPU can pull a task off the rq.
ops.dispatch() currently stops as soon as the CPU goes inactive, and CPU hotplug then waits for an RCU grace period before taking the rq offline. A BPF-held task affine only to the dying CPU and preempted inside an RCU read-side critical section would block that grace period, and the rq would never go offline. Test SCX_RQ_ONLINE directly so that ops.dispatch() keeps running until the rq goes offline. Only the dying CPU's own hotplug thread clears the flag during teardown, and task_can_run_on_remote_rq() still keeps other rqs' tasks off the CPU.
--- kernel/sched/ext.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
kernel/sched/ext.c +30 -3
@@ -2102,8 +2102,8 @@ static void set_task_runnable(struct rq *rq, struct task_struct *p) }/* -* list_add_tail() must be used. scx_ops_bypass() depends on tasks being -* appened to the runnable_list. +* list_add_tail() must be used. scx_ops_bypass() and rq_offline_scx() +* depend on tasks being appended to the runnable_list. */ list_add_tail (&p->scx.runnable_node, &rq->scx.runnable_list); }
@@ -2812,7 +2812,14 @@ static int balance_one(struct rq *rq, struct task_struct *prev)if (consume_global_dsq (rq)) goto has_tasks; -if (!SCX_HAS_OP (dispatch) ||scx_rq_bypassing (rq) || !scx_rq_online (rq)) +/* +* scx_rq_online() can't be used. Its cpu_active() test goes false +* before CPU hotplug waits for an RCU grace period, and +* rq_offline_scx() moves this CPU's tasks to the local DSQ only after +* the wait. The grace period can depend on those tasks running. +*/ +if (!SCX_HAS_OP (dispatch) ||scx_rq_bypassing (rq) || + !(rq->scx.flags &SCX_RQ_ONLINE )) goto no_tasks; dspc->rq = rq;
@@ -3503,7 +3510,27 @@ static void rq_online_scx(struct rq *rq)static void rq_offline_scx (struct rq *rq) { +struct task_struct *p, *n; + rq->scx.flags &= ~SCX_RQ_ONLINE ; + +/* sched domain rebuilds call rq_offline with the CPU staying alive */ +if (cpu_active (cpu_of (rq))) +return ; + +/* +* An offline CPU no longer calls ops.dispatch(). Re-enqueue its tasks +* onto the local DSQ so that they run here and balance_push() moves +* them off. +*/ +list_for_each_entry_safe_reverse (p, n, &rq->scx.runnable_list, scx.runnable_node) { +struct sched_enq_and_set_ctx ctx; + +if (p->scx.dsq == &rq->scx.local_dsq) +continue ; +sched_deq_and_put_task (p,DEQUEUE_SAVE |DEQUEUE_MOVE |DEQUEUE_NOCLOCK , &ctx); +sched_enq_and_set_task (&ctx); + } }#else /* CONFIG_SMP */
Signature · 1 line
2.53.0