bpf: Add helpers for trampoline image management
authorSong Liu <song@kernel.org>
Wed, 6 Dec 2023 22:40:50 +0000 (14:40 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 7 Dec 2023 01:17:20 +0000 (17:17 -0800)
commit82583daa2efc2e336962b231a46bad03a280b3e0
tree2d4dbd41a6b3f940756a29355ecda952753beff1
parent7a3d9a159b178e87306a6e989071ed9a114a1a31
bpf: Add helpers for trampoline image management

As BPF trampoline of different archs moves from bpf_jit_[alloc|free]_exec()
to bpf_prog_pack_[alloc|free](), we need to use different _alloc, _free for
different archs during the transition. Add the following helpers for this
transition:

void *arch_alloc_bpf_trampoline(unsigned int size);
void arch_free_bpf_trampoline(void *image, unsigned int size);
void arch_protect_bpf_trampoline(void *image, unsigned int size);
void arch_unprotect_bpf_trampoline(void *image, unsigned int size);

The fallback version of these helpers require size <= PAGE_SIZE, but they
are only called with size == PAGE_SIZE. They will be called with size <
PAGE_SIZE when arch_bpf_trampoline_size() helper is introduced later.

Signed-off-by: Song Liu <song@kernel.org>
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> # on s390x
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20231206224054.492250-4-song@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/bpf_struct_ops.c
kernel/bpf/trampoline.c
net/bpf/bpf_dummy_struct_ops.c