]> git.ipfire.org Git - thirdparty/linux.git/commit
scx: Allow calling sleepable kfuncs from BPF_PROG_TYPE_SYSCALL
authorDavid Vernet <void@manifault.com>
Wed, 31 Jul 2024 05:14:36 +0000 (00:14 -0500)
committerTejun Heo <tj@kernel.org>
Wed, 31 Jul 2024 17:45:28 +0000 (07:45 -1000)
commit298dec19bdeb6e33ac220502504d969272b50cf6
treeae6cc05c39b7f8af51c28947a2f6532850b3fcff
parentc8faf11cd192214e231626c3ee973a35d8fc33f2
scx: Allow calling sleepable kfuncs from BPF_PROG_TYPE_SYSCALL

We currently only allow calling sleepable scx kfuncs (i.e.
scx_bpf_create_dsq()) from BPF_PROG_TYPE_STRUCT_OPS progs. The idea here
was that we'd never have to call scx_bpf_create_dsq() outside of a
sched_ext struct_ops callback, but that might not actually be true. For
example, a scheduler could do something like the following:

1. Open and load (not yet attach) a scheduler skel

2. Synchronously call into a BPF_PROG_TYPE_SYSCALL prog from user space.
   For example, to initialize an LLC domain, or some other global,
   read-only state.

3. Attach the skel, which actually enables the scheduler

The advantage of doing this is that it can preclude having to do pretty
ugly boilerplate like initializing a read-only, statically sized array of
u64[]'s which the kernel consumes literally once at init time to then
create struct bpf_cpumask objects which are actually queried at runtime.

Doing the above is already possible given that we can invoke core BPF
kfuncs, such as bpf_cpumask_create(), from BPF_PROG_TYPE_SYSCALL progs. We
already allow many scx kfuncs to be called from BPF_PROG_TYPE_SYSCALL progs
(e.g. scx_bpf_kick_cpu()). Let's allow the sleepable kfuncs as well.

Signed-off-by: David Vernet <void@manifault.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/sched/ext.h
kernel/sched/ext.c