bpf: Introduce bpf_preempt_[disable,enable] kfuncs
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 24 Apr 2024 03:13:14 +0000 (03:13 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 24 Apr 2024 16:47:49 +0000 (09:47 -0700)
commitfc7566ad0a826cdc8886c5dbbb39ce72a0dc6333
tree141b3fc7a2c4174e8d6d685a20229ffedea61846
parentdc92febf7b93da5049fe177804e6b1961fcc6bd7
bpf: Introduce bpf_preempt_[disable,enable] kfuncs

Introduce two new BPF kfuncs, bpf_preempt_disable and
bpf_preempt_enable. These kfuncs allow disabling preemption in BPF
programs. Nesting is allowed, since the intended use cases includes
building native BPF spin locks without kernel helper involvement. Apart
from that, this can be used to per-CPU data structures for cases where
programs (or userspace) may preempt one or the other. Currently, while
per-CPU access is stable, whether it will be consistent is not
guaranteed, as only migration is disabled for BPF programs.

Global functions are disallowed from being called, but support for them
will be added as a follow up not just preempt kfuncs, but rcu_read_lock
kfuncs as well. Static subprog calls are permitted. Sleepable helpers
and kfuncs are disallowed in non-preemptible regions.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20240424031315.2757363-2-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf_verifier.h
kernel/bpf/helpers.c
kernel/bpf/verifier.c