Re: [PATCH 1/3] sched_ext: Fix ops_state and ops.dequeue() locking races in dispatch
From: Kuba Piecuch
Date: Wed Nov 25 2026 - 06:07:34 EST
Hi Tejun,
On Wed, 25 Nov 2026 00:18, Tejun Heo wrote:
> On Mon, Nov 23, 2026 at 05:10:32PM +0000, Kuba Piecuch wrote:
>> @@ -1871,8 +1884,10 @@ static void scx_dispatch_enqueue(struct scx_sched *sch, struct rq *rq,
>>
>> if (unlikely(dsq->id == SCX_DSQ_INVALID)) {
>> scx_error(sch, "attempting to dispatch to a destroyed dsq");
>> - /* fall back to the global dsq */
>> raw_spin_unlock(&dsq->lock);
>> + if (rq != task_rq(p))
>> + return false;
>> + /* fall back to the global dsq */
>> dsq = find_global_dsq(sch, task_cpu(p));
>> raw_spin_lock(&dsq->lock);
>
> I don't think the task needs to go to the global DSQ here. The scheduler
> is being ejected at this point and bypass is going to cycle all its
> runnable tasks. Maybe we can just let go of the task and return, for both
> the local and remote cases, and let the abort path recover it? What the
> BPF scheduler sees after scx_error() doesn't matter as long as the
> scheduler can be ejected and all the tasks are recovered. That'd get rid
> of the bool return and the retry in finish_dispatch().
Good point. Every caller that can pass a user DSQ here (direct_dispatch(),
finish_dispatch(), and move_task_between_dsqs()) has @p on its rq's
runnable_list and can't run on an rq that scx_bypass() has already walked,
so clearing ops_state (when SCX_ENQ_CLEAR_OPSS is set) and returning after
scx_error() leaves @p to be recovered by bypass just like
SCX_EXIT_ERROR_REENQ. Will change this in v2.
> Also, can you please factor out release_dispatching_and_lock_task_rq()
> from dispatch_to_local_dsq() in a separate prep patch?
Sure, will split that out into a prep patch in v2.
Thanks!