bpf: struct_ops supports more than one page for trampolines.
authorKui-Feng Lee <thinker.li@gmail.com>
Sat, 24 Feb 2024 22:34:17 +0000 (14:34 -0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 4 Mar 2024 22:09:20 +0000 (14:09 -0800)
commit187e2af05abe6bf80581490239c449456627d17a
tree573c922b888bd957230d958b50a0756ce457262b
parent73e4f9e615d7b99f39663d4722dc73e8fa5db5f9
bpf: struct_ops supports more than one page for trampolines.

The BPF struct_ops previously only allowed one page of trampolines.
Each function pointer of a struct_ops is implemented by a struct_ops
bpf program. Each struct_ops bpf program requires a trampoline.
The following selftest patch shows each page can hold a little more
than 20 trampolines.

While one page is more than enough for the tcp-cc usecase,
the sched_ext use case shows that one page is not always enough and hits
the one page limit. This patch overcomes the one page limit by allocating
another page when needed and it is limited to a total of
MAX_IMAGE_PAGES (8) pages which is more than enough for
reasonable usages.

The variable st_map->image has been changed to st_map->image_pages, and
its type has been changed to an array of pointers to pages.

Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240224223418.526631-3-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
include/linux/bpf.h
kernel/bpf/bpf_struct_ops.c
net/bpf/bpf_dummy_struct_ops.c