Skip to content

Commit 63fb3ec

Browse files
committed
sched_ext: Allow only user DSQs for scx_bpf_consume(), scx_bpf_dsq_nr_queued() and bpf_iter_scx_dsq_new()
SCX_DSQ_GLOBAL is special in that it can't be used as a priority queue and is consumed implicitly, but all BPF DSQ related kfuncs could be used on it. SCX_DSQ_GLOBAL will be split per-node for scalability and those operations won't make sense anymore. Disallow SCX_DSQ_GLOBAL on scx_bpf_consume(), scx_bpf_dsq_nr_queued() and bpf_iter_scx_dsq_new(). This means that SCX_DSQ_GLOBAL can only be used as a dispatch target from BPF schedulers. With scx_flatcg, which was using SCX_DSQ_GLOBAL as the fallback DSQ, updated, this shouldn't affect any schedulers. This leaves find_dsq_for_dispatch() the only user of find_non_local_dsq(). Open code and remove find_non_local_dsq(). Signed-off-by: tejun heo <[email protected]> Acked-by: David Vernet <[email protected]>
1 parent c9c809f commit 63fb3ec

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

kernel/sched/ext.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,16 +1808,6 @@ static struct scx_dispatch_q *find_user_dsq(u64 dsq_id)
18081808
return rhashtable_lookup_fast(&dsq_hash, &dsq_id, dsq_hash_params);
18091809
}
18101810

1811-
static struct scx_dispatch_q *find_non_local_dsq(u64 dsq_id)
1812-
{
1813-
lockdep_assert(rcu_read_lock_any_held());
1814-
1815-
if (dsq_id == SCX_DSQ_GLOBAL)
1816-
return &scx_dsq_global;
1817-
else
1818-
return find_user_dsq(dsq_id);
1819-
}
1820-
18211811
static struct scx_dispatch_q *find_dsq_for_dispatch(struct rq *rq, u64 dsq_id,
18221812
struct task_struct *p)
18231813
{
@@ -1835,7 +1825,11 @@ static struct scx_dispatch_q *find_dsq_for_dispatch(struct rq *rq, u64 dsq_id,
18351825
return &cpu_rq(cpu)->scx.local_dsq;
18361826
}
18371827

1838-
dsq = find_non_local_dsq(dsq_id);
1828+
if (dsq_id == SCX_DSQ_GLOBAL)
1829+
dsq = &scx_dsq_global;
1830+
else
1831+
dsq = find_user_dsq(dsq_id);
1832+
18391833
if (unlikely(!dsq)) {
18401834
scx_ops_error("non-existent DSQ 0x%llx for %s[%d]",
18411835
dsq_id, p->comm, p->pid);
@@ -6176,7 +6170,7 @@ __bpf_kfunc bool scx_bpf_consume(u64 dsq_id)
61766170

61776171
flush_dispatch_buf(dspc->rq);
61786172

6179-
dsq = find_non_local_dsq(dsq_id);
6173+
dsq = find_user_dsq(dsq_id);
61806174
if (unlikely(!dsq)) {
61816175
scx_ops_error("invalid DSQ ID 0x%016llx", dsq_id);
61826176
return false;
@@ -6497,7 +6491,7 @@ __bpf_kfunc s32 scx_bpf_dsq_nr_queued(u64 dsq_id)
64976491
goto out;
64986492
}
64996493
} else {
6500-
dsq = find_non_local_dsq(dsq_id);
6494+
dsq = find_user_dsq(dsq_id);
65016495
if (dsq) {
65026496
ret = READ_ONCE(dsq->nr);
65036497
goto out;
@@ -6546,7 +6540,7 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id,
65466540
if (flags & ~__SCX_DSQ_ITER_USER_FLAGS)
65476541
return -EINVAL;
65486542

6549-
kit->dsq = find_non_local_dsq(dsq_id);
6543+
kit->dsq = find_user_dsq(dsq_id);
65506544
if (!kit->dsq)
65516545
return -ENOENT;
65526546

0 commit comments

Comments
 (0)