Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf, selftests/bpf: Adjust libbpf, bpftool, selftests to match LLVM

The selftests use
to tell LLVM about special pointers. For LLVM there is nothing "arena"
about them. They are simply pointers in a different address space.
Hence LLVM diff https://github.com/llvm/llvm-project/pull/85161 renamed:
. macro __BPF_FEATURE_ARENA_CAST -> __BPF_FEATURE_ADDR_SPACE_CAST
. global variables in __attribute__((address_space(N))) are now
placed in section named ".addr_space.N" instead of ".arena.N".

Adjust libbpf, bpftool, and selftests to match LLVM.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20240315021834.62988-3-alexei.starovoitov@gmail.com

authored by

Alexei Starovoitov and committed by
Andrii Nakryiko
10ebe835 ee498a38

+11 -11
+1 -1
tools/bpf/bpftool/gen.c
··· 121 121 int i, n; 122 122 123 123 /* recognize hard coded LLVM section name */ 124 - if (strcmp(sec_name, ".arena.1") == 0) { 124 + if (strcmp(sec_name, ".addr_space.1") == 0) { 125 125 /* this is the name to use in skeleton */ 126 126 snprintf(buf, buf_sz, "arena"); 127 127 return true;
+1 -1
tools/lib/bpf/libbpf.c
··· 498 498 #define KSYMS_SEC ".ksyms" 499 499 #define STRUCT_OPS_SEC ".struct_ops" 500 500 #define STRUCT_OPS_LINK_SEC ".struct_ops.link" 501 - #define ARENA_SEC ".arena.1" 501 + #define ARENA_SEC ".addr_space.1" 502 502 503 503 enum libbpf_map_type { 504 504 LIBBPF_MAP_UNSPEC,
+1 -1
tools/testing/selftests/bpf/bpf_arena_common.h
··· 32 32 */ 33 33 #endif 34 34 35 - #if defined(__BPF_FEATURE_ARENA_CAST) && !defined(BPF_ARENA_FORCE_ASM) 35 + #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) && !defined(BPF_ARENA_FORCE_ASM) 36 36 #define __arena __attribute__((address_space(1))) 37 37 #define cast_kern(ptr) /* nop for bpf prog. emitted by LLVM */ 38 38 #define cast_user(ptr) /* nop for bpf prog. emitted by LLVM */
+1 -1
tools/testing/selftests/bpf/progs/arena_htab.c
··· 22 22 SEC("syscall") 23 23 int arena_htab_llvm(void *ctx) 24 24 { 25 - #if defined(__BPF_FEATURE_ARENA_CAST) || defined(BPF_ARENA_FORCE_ASM) 25 + #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) || defined(BPF_ARENA_FORCE_ASM) 26 26 struct htab __arena *htab; 27 27 __u64 i; 28 28
+5 -5
tools/testing/selftests/bpf/progs/arena_list.c
··· 30 30 int cnt; 31 31 bool skip = false; 32 32 33 - #ifdef __BPF_FEATURE_ARENA_CAST 33 + #ifdef __BPF_FEATURE_ADDR_SPACE_CAST 34 34 long __arena arena_sum; 35 35 int __arena test_val = 1; 36 36 struct arena_list_head __arena global_head; 37 37 #else 38 - long arena_sum SEC(".arena.1"); 39 - int test_val SEC(".arena.1"); 38 + long arena_sum SEC(".addr_space.1"); 39 + int test_val SEC(".addr_space.1"); 40 40 #endif 41 41 42 42 int zero; ··· 44 44 SEC("syscall") 45 45 int arena_list_add(void *ctx) 46 46 { 47 - #ifdef __BPF_FEATURE_ARENA_CAST 47 + #ifdef __BPF_FEATURE_ADDR_SPACE_CAST 48 48 __u64 i; 49 49 50 50 list_head = &global_head; ··· 66 66 SEC("syscall") 67 67 int arena_list_del(void *ctx) 68 68 { 69 - #ifdef __BPF_FEATURE_ARENA_CAST 69 + #ifdef __BPF_FEATURE_ADDR_SPACE_CAST 70 70 struct elem __arena *n; 71 71 int sum = 0; 72 72
+2 -2
tools/testing/selftests/bpf/progs/verifier_arena.c
··· 19 19 __success __retval(0) 20 20 int basic_alloc1(void *ctx) 21 21 { 22 - #if defined(__BPF_FEATURE_ARENA_CAST) 22 + #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) 23 23 volatile int __arena *page1, *page2, *no_page, *page3; 24 24 25 25 page1 = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0); ··· 58 58 __success __retval(0) 59 59 int basic_alloc2(void *ctx) 60 60 { 61 - #if defined(__BPF_FEATURE_ARENA_CAST) 61 + #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) 62 62 volatile char __arena *page1, *page2, *page3, *page4; 63 63 64 64 page1 = bpf_arena_alloc_pages(&arena, NULL, 2, NUMA_NO_NODE, 0);