sched_ext: Don't request private stacks the JIT can't provide
Subsystems (3)
PATCH 1/1 sched_ext: Don't request private stacks the JIT can't provide
Since commit 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching"), bpf_scx_check_member() requests a private stack for ops.dispatch(), and later also for ops.sub_caps_updated(), whenever CONFIG_EXT_SUB_SCHED is set, which is the default.
The verifier fails the load with -EACCES if the JIT doesn't support private stacks, so on architectures whose JIT doesn't, like riscv64, no BPF scheduler that implements ops.dispatch() can be loaded.
The private stack is only needed when these operations nest, which only happens with sub-schedulers. Don't request it if the JIT can't provide it, and refuse to attach sub-schedulers in that case. Root schedulers then load as they did before sub-scheduler support was added.
---
On riscv64 in QEMU (-M virt) running for-7.4-fixes,
# echo 1 > /proc/sys/net/core/bpf_jit_enable # ./scx_simple
libbpf: prog 'simple_dispatch': BPF program load failed: -EACCES
libbpf: prog 'simple_dispatch': -- BEGIN PROG LOAD LOG -- Private stack not supported by jit
With it, scx_simple loads and runs.
kernel/sched/ext/ext.c | 3 +++ kernel/sched/ext/sub.c | 6 ++++++ 2 files changed, 9 insertions(+)
kernel/sched/ext/ext.c +3 -0
@@ -9294,6 +9294,9 @@ static int bpf_scx_check_member(const struct btf_type *t,* sub-scheds and sub-scheds themselves but I don't know how to access * struct_ops from here. */ +if (!bpf_jit_supports_private_stack ()) +return 0 ; +switch (moff) {case offsetof(struct sched_ext_ops , dispatch): prog->aux->priv_stack_requested = true;
kernel/sched/ext/sub.c +6 -0
@@ -2246,6 +2246,12 @@ void scx_sub_enable_workfn(struct kthread_work *work) goto out_unlock; } +/* nesting ops need private stacks, see bpf_scx_check_member() */ +if (!bpf_jit_supports_private_stack ()) { + ret = -EOPNOTSUPP ; + goto out_unlock; + } + cgrp =cgroup_get_from_id (ops->sub_cgroup_id);if (IS_ERR (cgrp)) { ret =PTR_ERR (cgrp);
Signature · 1 line
2.56.0
Hi Cheng-Yang,
Quoted 14 lines · Cheng-Yang Chou
Since commit
4f8b122848db("sched_ext: Add basic building blocks for nested sub-scheduler dispatching"),bpf_scx_check_member()requests a private stack forops.dispatch(), and later also forops.sub_caps_updated(), wheneverCONFIG_EXT_SUB_SCHEDis set, which is the default.The verifier fails the load with
-EACCESif the JIT doesn't support private stacks, so on architectures whose JIT doesn't, like riscv64, no BPF scheduler that implementsops.dispatch()can be loaded.The private stack is only needed when these operations nest, which only happens with sub-schedulers. Don't request it if the JIT can't provide it, and refuse to attach sub-schedulers in that case. Root schedulers then load as they did before sub-scheduler support was added.
Quoted 5 lines
Fixes 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching")Cc [email protected] # v7.1+Reported-by JaeJoon Jung <[email protected]>Signed-off-by Cheng-Yang Chou <[email protected]>
Looks good to me.
Thanks,
-Andrea
Quoted 51 lines
---
On riscv64 in QEMU (-M virt) running for-7.4-fixes,# echo 1 > /proc/sys/net/core/bpf_jit_enable # ./scx_simplelibbpf: prog '
simple_dispatch': BPF program load failed:-EACCES
libbpf: prog 'simple_dispatch': -- BEGIN PROG LOAD LOG -- Private stack not supported by jitWith it,
scx_simpleloads and runs.kernel/sched/ext/ext.c | 3 +++ kernel/sched/ext/sub.c | 6 ++++++ 2 files changed, 9 insertions(+)kernel/sched/ext/ext.c +3
-0@@ -9294,6 +9294,9 @@ static int bpf_scx_check_member(const struct btf_type *t,* sub-scheds and sub-scheds themselves but I don't know how to access * struct_ops from here. */ +if (!bpf_jit_supports_private_stack ()) +return 0 ; +switch (moff) {case offsetof(struct sched_ext_ops , dispatch): prog->aux->priv_stack_requested = true;kernel/sched/ext/sub.c +6
-0@@ -2246,6 +2246,12 @@ void scx_sub_enable_workfn(struct kthread_work *work) goto out_unlock; } +/* nesting ops need private stacks, see bpf_scx_check_member() */ +if (!bpf_jit_supports_private_stack ()) { + ret = -EOPNOTSUPP ; + goto out_unlock; + } + cgrp =cgroup_get_from_id (ops->sub_cgroup_id);if (IS_ERR (cgrp)) { ret =PTR_ERR (cgrp);Signature · 1 line
2.56.0