Skip to content

Commit ea145d5

Browse files
theihorAlexei Starovoitov
authored andcommitted
bpf: define KF_ARENA_* flags for bpf_arena kfuncs
bpf_arena_alloc_pages() and bpf_arena_free_pages() work with the bpf_arena pointers [1], which is indicated by the __arena macro in the kernel source code: #define __arena __attribute__((address_space(1))) However currently this information is absent from the debug data in the vmlinux binary. As a consequence, bpf_arena_* kfuncs declarations in vmlinux.h (produced by bpftool) do not match prototypes expected by the BPF programs attempting to use these functions. Introduce a set of kfunc flags to mark relevant types as bpf_arena pointers. The flags then can be detected by pahole when generating BTF from vmlinux's DWARF, allowing it to emit corresponding BTF type tags for the marked kfuncs. With recently proposed BTF extension [2], these type tags will be processed by bpftool when dumping vmlinux.h, and corresponding compiler attributes will be added to the declarations. [1] https://lwn.net/Articles/961594/ [2] https://lore.kernel.org/bpf/20250130201239.1429648-1-ihor.solodrai@linux.dev/ Suggested-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20250206003148.2308659-1-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 003be25 commit ea145d5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

include/linux/btf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
#define KF_ITER_DESTROY (1 << 10) /* kfunc implements BPF iter destructor */
7777
#define KF_RCU_PROTECTED (1 << 11) /* kfunc should be protected by rcu cs when they are invoked */
7878
#define KF_FASTCALL (1 << 12) /* kfunc supports bpf_fastcall protocol */
79+
#define KF_ARENA_RET (1 << 13) /* kfunc returns an arena pointer */
80+
#define KF_ARENA_ARG1 (1 << 14) /* kfunc takes an arena pointer as its first argument */
81+
#define KF_ARENA_ARG2 (1 << 15) /* kfunc takes an arena pointer as its second argument */
7982

8083
/*
8184
* Tag marking a kernel function as a kfunc. This is meant to minimize the

kernel/bpf/arena.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ __bpf_kfunc void bpf_arena_free_pages(void *p__map, void *ptr__ign, u32 page_cnt
577577
__bpf_kfunc_end_defs();
578578

579579
BTF_KFUNCS_START(arena_kfuncs)
580-
BTF_ID_FLAGS(func, bpf_arena_alloc_pages, KF_TRUSTED_ARGS | KF_SLEEPABLE)
581-
BTF_ID_FLAGS(func, bpf_arena_free_pages, KF_TRUSTED_ARGS | KF_SLEEPABLE)
580+
BTF_ID_FLAGS(func, bpf_arena_alloc_pages, KF_TRUSTED_ARGS | KF_SLEEPABLE | KF_ARENA_RET | KF_ARENA_ARG2)
581+
BTF_ID_FLAGS(func, bpf_arena_free_pages, KF_TRUSTED_ARGS | KF_SLEEPABLE | KF_ARENA_ARG2)
582582
BTF_KFUNCS_END(arena_kfuncs)
583583

584584
static const struct btf_kfunc_id_set common_kfunc_set = {

0 commit comments

Comments
 (0)