mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH sched_ext/for-7.3-fixes] sched_ext: Derive SCX_RQ_IN_WAKEUP from the core enqueue flags
@ 2026-09-16 22:00 Tejun Heo
  2026-09-17  5:49 ` Andrea Righi
  2026-09-17 16:51 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Tejun Heo @ 2026-09-16 22:00 UTC (permalink / raw)
  To: David Vernet, Andrea Righi, Changwoo Min
  Cc: Emil Tsalapatis, Cheng-Yang Chou, sched-ext, linux-kernel

schedule_deferred_locked() skips scheduling a deferred action while
SCX_RQ_IN_WAKEUP is set and relies on the task_woken_scx() call that follows
a wakeup enqueue to run it. enqueue_task_scx() sets the flag from the merged
enqueue flags, which include the flags stashed for a remote activation.
move_remote_task_to_local_dsq() thus sets SCX_RQ_IN_WAKEUP on the
destination rq when the moved task was woken up, although no
task_woken_scx() follows that activation.

An IMMED insert into a busy destination requests a local reenqueue during
that enqueue. The request gets linked but not scheduled and stays pending
until an unrelated wakeup or preemption on that CPU runs the deferred
actions. The IMMED task sits behind the running task in the meantime. If
nothing runs them before the scheduler is disabled, the request outlives the
scheduler and points into its freed per-cpu area, which the next scheduler
dereferences from run_deferred().

Test the core enqueue flags for the wakeup bit. Only the core's wakeup path
is followed by task_woken_scx().

Fixes: 57ccf5ccdc56 ("sched_ext: Fix enqueue_task_scx() truncation of upper enqueue flags")
Cc: stable@vger.kernel.org # v7.1+
Reported-by: Andrea Righi <arighi@nvidia.com>
Link: https://lore.kernel.org/all/20260916145807.3250167-1-arighi@nvidia.com/
Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/sched/ext/ext.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -2141,7 +2141,12 @@ static void enqueue_task_scx(struct rq *
 	int sticky_cpu = p->scx.sticky_cpu;
 	u64 enq_flags = core_enq_flags | rq->scx.remote_activate_enq_flags;
 
-	if (enq_flags & ENQUEUE_WAKEUP)
+	/*
+	 * SCX_RQ_IN_WAKEUP promises a task_woken_scx() call once this enqueue
+	 * returns. Only the core's wakeup path delivers one. The flags stashed
+	 * for a remote activation may carry the wakeup bit without it.
+	 */
+	if (core_enq_flags & ENQUEUE_WAKEUP)
 		rq->scx.flags |= SCX_RQ_IN_WAKEUP;
 
 	/*

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH sched_ext/for-7.3-fixes] sched_ext: Derive SCX_RQ_IN_WAKEUP from the core enqueue flags
  2026-09-16 22:00 [PATCH sched_ext/for-7.3-fixes] sched_ext: Derive SCX_RQ_IN_WAKEUP from the core enqueue flags Tejun Heo
@ 2026-09-17  5:49 ` Andrea Righi
  2026-09-17 16:51 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Andrea Righi @ 2026-09-17  5:49 UTC (permalink / raw)
  To: Tejun Heo
  Cc: David Vernet, Changwoo Min, Emil Tsalapatis, Cheng-Yang Chou,
	sched-ext, linux-kernel

Hi Tejun,

On Wed, Sep 16, 2026 at 12:00:24PM -1000, Tejun Heo wrote:
> schedule_deferred_locked() skips scheduling a deferred action while
> SCX_RQ_IN_WAKEUP is set and relies on the task_woken_scx() call that follows
> a wakeup enqueue to run it. enqueue_task_scx() sets the flag from the merged
> enqueue flags, which include the flags stashed for a remote activation.
> move_remote_task_to_local_dsq() thus sets SCX_RQ_IN_WAKEUP on the
> destination rq when the moved task was woken up, although no
> task_woken_scx() follows that activation.
> 
> An IMMED insert into a busy destination requests a local reenqueue during
> that enqueue. The request gets linked but not scheduled and stays pending
> until an unrelated wakeup or preemption on that CPU runs the deferred
> actions. The IMMED task sits behind the running task in the meantime. If
> nothing runs them before the scheduler is disabled, the request outlives the
> scheduler and points into its freed per-cpu area, which the next scheduler
> dereferences from run_deferred().
> 
> Test the core enqueue flags for the wakeup bit. Only the core's wakeup path
> is followed by task_woken_scx().
> 
> Fixes: 57ccf5ccdc56 ("sched_ext: Fix enqueue_task_scx() truncation of upper enqueue flags")
> Cc: stable@vger.kernel.org # v7.1+
> Reported-by: Andrea Righi <arighi@nvidia.com>
> Link: https://lore.kernel.org/all/20260916145807.3250167-1-arighi@nvidia.com/
> Signed-off-by: Tejun Heo <tj@kernel.org>

This looks better than my fix.

Reviewed-by: Andrea Righi <arighi@nvidia.com>

Thanks,
-Andrea

> ---
>  kernel/sched/ext/ext.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -2141,7 +2141,12 @@ static void enqueue_task_scx(struct rq *
>  	int sticky_cpu = p->scx.sticky_cpu;
>  	u64 enq_flags = core_enq_flags | rq->scx.remote_activate_enq_flags;
>  
> -	if (enq_flags & ENQUEUE_WAKEUP)
> +	/*
> +	 * SCX_RQ_IN_WAKEUP promises a task_woken_scx() call once this enqueue
> +	 * returns. Only the core's wakeup path delivers one. The flags stashed
> +	 * for a remote activation may carry the wakeup bit without it.
> +	 */
> +	if (core_enq_flags & ENQUEUE_WAKEUP)
>  		rq->scx.flags |= SCX_RQ_IN_WAKEUP;
>  
>  	/*

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH sched_ext/for-7.3-fixes] sched_ext: Derive SCX_RQ_IN_WAKEUP from the core enqueue flags
  2026-09-16 22:00 [PATCH sched_ext/for-7.3-fixes] sched_ext: Derive SCX_RQ_IN_WAKEUP from the core enqueue flags Tejun Heo
  2026-09-17  5:49 ` Andrea Righi
@ 2026-09-17 16:51 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-09-17 16:51 UTC (permalink / raw)
  To: David Vernet, Andrea Righi, Changwoo Min
  Cc: Tejun Heo, Emil Tsalapatis, Cheng-Yang Chou, sched-ext, linux-kernel

Applied to sched_ext/for-7.3-fixes.

Thanks.

--
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-17 16:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 22:00 [PATCH sched_ext/for-7.3-fixes] sched_ext: Derive SCX_RQ_IN_WAKEUP from the core enqueue flags Tejun Heo
2026-09-17  5:49 ` Andrea Righi
2026-09-17 16:51 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®