The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH sched_ext/for-7.3] sched_ext: Set up ops.sub_ecaps_updated() dispatch context on the executing CPU
@ 2026-08-14 17:46 Tejun Heo
  2026-08-14 18:33 ` Tejun Heo
  2026-08-14 18:52 ` Andrea Righi
  0 siblings, 2 replies; 3+ messages in thread
From: Tejun Heo @ 2026-08-14 17:46 UTC (permalink / raw)
  To: David Vernet, Andrea Righi, Changwoo Min
  Cc: David Carlier, Emil Tsalapatis, sched-ext, linux-kernel

scx_process_sync_ecaps() sets up the dispatch context for
ops.sub_ecaps_updated() in the target cpu's pcpu context recovered from the
llist node. However, the context is per executing cpu: the dispatch kfuncs
resolve it with this_cpu_ptr() and the dispatch buffer lives in it. What the
dispatches target is determined by the rq recorded in the context, not by
which cpu's context it is. Under core scheduling the pick runs balance_one()
for sibling rqs, so a sync processed for a sibling invokes the op with the
executing cpu's context not set up and its dispatch kfuncs misoperate on a
NULL or stale rq.

Set up the executing cpu's dsp_ctx instead, matching scx_dispatch_sched().
The recorded rq keeps the dispatches targeting the synced cpu.

Fixes: b81a6c018cde ("sched_ext: Add sub_ecaps_updated() effective-cap change notifier")
Reported-by: David Carlier <devnexen@gmail.com>
Link: https://lore.kernel.org/all/20260813045931.8691-1-devnexen@gmail.com/
Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/sched/ext/sub.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -1017,11 +1017,15 @@ void scx_process_sync_ecaps(struct rq *r
 		 * invocation is equivalent to the dispatch path and may drop
 		 * and re-acquire the rq lock temporarily while the rest of
 		 * @batch is held privately, see scx_discard_ecaps_to_sync().
+		 * The dispatch kfuncs resolve their context on the executing
+		 * cpu, which under core scheduling can differ from @rq's cpu,
+		 * so the context is set up there. The rq recorded in it keeps
+		 * the dispatches targeting @rq.
 		 */
 		if (ecaps != pcpu->reported_ecaps &&
 		    SCX_HAS_OP(pcpu->sch, sub_ecaps_updated) &&
 		    !scx_bypassing(pcpu->sch, cpu)) {
-			struct scx_dsp_ctx *dspc = &pcpu->dsp_ctx;
+			struct scx_dsp_ctx *dspc = &this_cpu_ptr(pcpu->sch->pcpu)->dsp_ctx;
 
 			dspc->rq = rq;
 			/* stash @prev so nested dispatches can access it */

-- 
2.55.0

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

* Re: [PATCH sched_ext/for-7.3] sched_ext: Set up ops.sub_ecaps_updated() dispatch context on the executing CPU
  2026-08-14 17:46 [PATCH sched_ext/for-7.3] sched_ext: Set up ops.sub_ecaps_updated() dispatch context on the executing CPU Tejun Heo
@ 2026-08-14 18:33 ` Tejun Heo
  2026-08-14 18:52 ` Andrea Righi
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-08-14 18:33 UTC (permalink / raw)
  To: David Vernet, Andrea Righi, Changwoo Min
  Cc: David Carlier, Emil Tsalapatis, sched-ext, linux-kernel

Applied to sched_ext/for-7.3.

Thanks.

--
tejun

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

* Re: [PATCH sched_ext/for-7.3] sched_ext: Set up ops.sub_ecaps_updated() dispatch context on the executing CPU
  2026-08-14 17:46 [PATCH sched_ext/for-7.3] sched_ext: Set up ops.sub_ecaps_updated() dispatch context on the executing CPU Tejun Heo
  2026-08-14 18:33 ` Tejun Heo
@ 2026-08-14 18:52 ` Andrea Righi
  1 sibling, 0 replies; 3+ messages in thread
From: Andrea Righi @ 2026-08-14 18:52 UTC (permalink / raw)
  To: Tejun Heo
  Cc: David Vernet, Changwoo Min, David Carlier, Emil Tsalapatis,
	sched-ext, linux-kernel

Hi Tejun,

On Fri, Aug 14, 2026 at 07:46:46AM -1000, Tejun Heo wrote:
> scx_process_sync_ecaps() sets up the dispatch context for
> ops.sub_ecaps_updated() in the target cpu's pcpu context recovered from the
> llist node. However, the context is per executing cpu: the dispatch kfuncs
> resolve it with this_cpu_ptr() and the dispatch buffer lives in it. What the
> dispatches target is determined by the rq recorded in the context, not by
> which cpu's context it is. Under core scheduling the pick runs balance_one()
> for sibling rqs, so a sync processed for a sibling invokes the op with the
> executing cpu's context not set up and its dispatch kfuncs misoperate on a
> NULL or stale rq.
> 
> Set up the executing cpu's dsp_ctx instead, matching scx_dispatch_sched().
> The recorded rq keeps the dispatches targeting the synced cpu.
> 
> Fixes: b81a6c018cde ("sched_ext: Add sub_ecaps_updated() effective-cap change notifier")
> Reported-by: David Carlier <devnexen@gmail.com>
> Link: https://lore.kernel.org/all/20260813045931.8691-1-devnexen@gmail.com/
> Signed-off-by: Tejun Heo <tj@kernel.org>

Everything looks correct to me.

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

Thanks,
-Andrea

> ---
>  kernel/sched/ext/sub.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> --- a/kernel/sched/ext/sub.c
> +++ b/kernel/sched/ext/sub.c
> @@ -1017,11 +1017,15 @@ void scx_process_sync_ecaps(struct rq *r
>  		 * invocation is equivalent to the dispatch path and may drop
>  		 * and re-acquire the rq lock temporarily while the rest of
>  		 * @batch is held privately, see scx_discard_ecaps_to_sync().
> +		 * The dispatch kfuncs resolve their context on the executing
> +		 * cpu, which under core scheduling can differ from @rq's cpu,
> +		 * so the context is set up there. The rq recorded in it keeps
> +		 * the dispatches targeting @rq.
>  		 */
>  		if (ecaps != pcpu->reported_ecaps &&
>  		    SCX_HAS_OP(pcpu->sch, sub_ecaps_updated) &&
>  		    !scx_bypassing(pcpu->sch, cpu)) {
> -			struct scx_dsp_ctx *dspc = &pcpu->dsp_ctx;
> +			struct scx_dsp_ctx *dspc = &this_cpu_ptr(pcpu->sch->pcpu)->dsp_ctx;
>  
>  			dspc->rq = rq;
>  			/* stash @prev so nested dispatches can access it */
> 
> -- 
> 2.55.0

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

end of thread, other threads:[~2026-08-14 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 17:46 [PATCH sched_ext/for-7.3] sched_ext: Set up ops.sub_ecaps_updated() dispatch context on the executing CPU Tejun Heo
2026-08-14 18:33 ` Tejun Heo
2026-08-14 18:52 ` Andrea Righi

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