From e2c8568eb3075a187de5130fae6a9b3b664766a6 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 17 Jun 2024 10:31:16 -1000 Subject: [PATCH] scx: Fix error condition check in __scx_bpf_consume_task() __scx_bpf_consume_task() should test whether the task is still on the DSQ that's being iterated before erroring out if it's on a local DSQ. Otherwise, another racing consumer can move the task to a local DSQ triggering a spurious error. Relocate the error condition. --- kernel/sched/ext.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 2cf7dd5d5db1..0e46697efe77 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -6092,14 +6092,14 @@ __bpf_kfunc bool __scx_bpf_consume_task(unsigned long it, struct task_struct *p) */ dsq = READ_ONCE(p->scx.dsq); + if (unlikely(!dsq || dsq != kit_dsq)) + return false; + if (unlikely(dsq->id == SCX_DSQ_LOCAL)) { scx_ops_error("local DSQ not allowed"); return false; } - if (unlikely(!dsq || dsq != kit_dsq)) - return false; - if (!scx_kf_allowed(SCX_KF_DISPATCH)) return false;