Skip to contentSkip to conversation

sched_ext: Don't request private stacks the JIT can't provide

PATCH In review Cheng-Yang Chou 2 participants 2 messages Nov 23 – Nov 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching")

---
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
index 10de6bd865e8..3248ed57c2bb 100644
@@ -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
index d2a20114eaa2..7c069a289766 100644
@@ -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
reviewer Reviewed-by on v1 1/1
#1 lore raw

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 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.

Quoted 5 lines
Fixes 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching")

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_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
index 10de6bd865e8..3248ed57c2bb 100644
@@ -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
index d2a20114eaa2..7c069a289766 100644
@@ -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