bpf: Use arch_bpf_trampoline_size
authorSong Liu <song@kernel.org>
Wed, 6 Dec 2023 22:40:53 +0000 (14:40 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 7 Dec 2023 01:17:20 +0000 (17:17 -0800)
commit26ef208c209a0e6eed8942a5d191b39dccfa6e38
tree8db20d8a07885449ac7805d3c8829d1d4697773f
parent96d1b7c081c0c96cbe8901045f4ff15a2e9974a2
bpf: Use arch_bpf_trampoline_size

Instead of blindly allocating PAGE_SIZE for each trampoline, check the size
of the trampoline with arch_bpf_trampoline_size(). This size is saved in
bpf_tramp_image->size, and used for modmem charge/uncharge. The fallback
arch_alloc_bpf_trampoline() still allocates a whole page because we need to
use set_memory_* to protect the memory.

struct_ops trampoline still uses a whole page for multiple trampolines.

With this size check at caller (regular trampoline and struct_ops
trampoline), remove arch_bpf_trampoline_size() from
arch_prepare_bpf_trampoline() in archs.

Also, update bpf_image_ksym_add() to handle symbol of different sizes.

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>
Acked-by: Björn Töpel <bjorn@rivosinc.com>
Tested-by: Björn Töpel <bjorn@rivosinc.com> # on riscv
Link: https://lore.kernel.org/r/20231206224054.492250-7-song@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/arm64/net/bpf_jit_comp.c
arch/riscv/net/bpf_jit_comp64.c
include/linux/bpf.h
kernel/bpf/bpf_struct_ops.c
kernel/bpf/dispatcher.c
kernel/bpf/trampoline.c