Re: [PATCH 10/15] sched_ext: Add per-CPU data to DSQs

From: Andrea Righi

Date: Fri Mar 06 2026 - 17:55:52 EST


Hi Tejun,

On Fri, Mar 06, 2026 at 09:06:18AM -1000, Tejun Heo wrote:
> Add per-CPU data structure to dispatch queues. Each DSQ now has a percpu
> scx_dsq_pcpu which contains a back-pointer to the DSQ. This will be used by
> future changes to implement per-CPU reenqueue tracking for user DSQs.
>
> init_dsq() now allocates the percpu data and can fail, so it returns an
> error code. All callers are updated to handle failures. exit_dsq() is added
> to free the percpu data and is called from all DSQ cleanup paths.
>
> In scx_bpf_create_dsq(), init_dsq() is called before rcu_read_lock() since
> alloc_percpu() requires GFP_KERNEL context, and dsq->sched is set
> afterwards.
>
> Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
> ---
...
> @@ -5849,8 +5884,11 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops,
> goto err_free_pnode;
> }
>
> - for_each_possible_cpu(cpu)
> - init_dsq(bypass_dsq(sch, cpu), SCX_DSQ_BYPASS, sch);
> + for_each_possible_cpu(cpu) {
> + ret = init_dsq(bypass_dsq(sch, cpu), SCX_DSQ_BYPASS, sch);
> + if (ret)
> + goto err_free_pcpu;

If we fail here...

> + }
>
> for_each_possible_cpu(cpu) {
> struct scx_sched_pcpu *pcpu = per_cpu_ptr(sch->pcpu, cpu);
> @@ -5932,6 +5970,10 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops,
> err_stop_helper:
> kthread_destroy_worker(sch->helper);
> err_free_pcpu:
> + for_each_possible_cpu(cpu) {
> + if (bypass_dsq(sch, cpu))
> + exit_dsq(bypass_dsq(sch, cpu));
> + }

...we are still calling exit_dsq() for all the CPUs. We should probably
call it only on the initialized ones, or we may touch uninitialized mem.

Thanks,
-Andrea