Skip to content

Commit 00c9e07

Browse files
htejungregkh
authored andcommitted
sched_ext: Use dsq->first_task instead of list_empty() in dispatch_enqueue() FIFO-tail
commit 2f2ea77 upstream. dispatch_enqueue()'s FIFO-tail path used list_empty(&dsq->list) to decide whether to set dsq->first_task on enqueue. dsq->list can contain parked BPF iterator cursors (SCX_DSQ_LNODE_ITER_CURSOR), so list_empty() is not a reliable "no real task" check. If the last real task is unlinked while a cursor is parked, first_task becomes NULL; the next FIFO-tail enqueue then sees list_empty() == false and skips the first_task update, leaving scx_bpf_dsq_peek() returning NULL for a non-empty DSQ. Test dsq->first_task directly, which already tracks only real tasks and is maintained under dsq->lock. Fixes: 44f5c8e ("sched_ext: Add lockless peek operation for DSQs") Cc: stable@vger.kernel.org # v6.19+ Reported-by: Chris Mason <clm@meta.com> Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Andrea Righi <arighi@nvidia.com> Cc: Ryan Newton <newton@meta.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dd6fc40 commit 00c9e07

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

kernel/sched/ext.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,11 +1093,13 @@ static void dispatch_enqueue(struct scx_sched *sch, struct scx_dispatch_q *dsq,
10931093
if (!(dsq->id & SCX_DSQ_FLAG_BUILTIN))
10941094
rcu_assign_pointer(dsq->first_task, p);
10951095
} else {
1096-
bool was_empty;
1097-
1098-
was_empty = list_empty(&dsq->list);
1096+
/*
1097+
* dsq->list can contain parked BPF iterator cursors, so
1098+
* list_empty() here isn't a reliable proxy for "no real
1099+
* task in the DSQ". Test dsq->first_task directly.
1100+
*/
10991101
list_add_tail(&p->scx.dsq_list.node, &dsq->list);
1100-
if (was_empty && !(dsq->id & SCX_DSQ_FLAG_BUILTIN))
1102+
if (!dsq->first_task && !(dsq->id & SCX_DSQ_FLAG_BUILTIN))
11011103
rcu_assign_pointer(dsq->first_task, p);
11021104
}
11031105
}

0 commit comments

Comments
 (0)