Commit b6349fd3 authored by Ilya Leoshkevich's avatar Ilya Leoshkevich Committed by Daniel Borkmann

selftests/bpf: Introduce __arena_global

While clang uses __attribute__((address_space(1))) both for defining
arena pointers and arena globals, GCC requires different syntax for
both. While __arena covers the first use case, introduce __arena_global
to cover the second one.
Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240701234304.14336-11-iii@linux.ibm.com
parent 2f946948
...@@ -34,10 +34,12 @@ ...@@ -34,10 +34,12 @@
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) && !defined(BPF_ARENA_FORCE_ASM) #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) && !defined(BPF_ARENA_FORCE_ASM)
#define __arena __attribute__((address_space(1))) #define __arena __attribute__((address_space(1)))
#define __arena_global __attribute__((address_space(1)))
#define cast_kern(ptr) /* nop for bpf prog. emitted by LLVM */ #define cast_kern(ptr) /* nop for bpf prog. emitted by LLVM */
#define cast_user(ptr) /* nop for bpf prog. emitted by LLVM */ #define cast_user(ptr) /* nop for bpf prog. emitted by LLVM */
#else #else
#define __arena #define __arena
#define __arena_global SEC(".addr_space.1")
#define cast_kern(ptr) bpf_addr_space_cast(ptr, 0, 1) #define cast_kern(ptr) bpf_addr_space_cast(ptr, 0, 1)
#define cast_user(ptr) bpf_addr_space_cast(ptr, 1, 0) #define cast_user(ptr) bpf_addr_space_cast(ptr, 1, 0)
#endif #endif
......
...@@ -25,20 +25,13 @@ bool skip_tests = true; ...@@ -25,20 +25,13 @@ bool skip_tests = true;
__u32 pid = 0; __u32 pid = 0;
#undef __arena __u64 __arena_global add64_value = 1;
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) __u64 __arena_global add64_result = 0;
#define __arena __attribute__((address_space(1))) __u32 __arena_global add32_value = 1;
#else __u32 __arena_global add32_result = 0;
#define __arena SEC(".addr_space.1") __u64 __arena_global add_stack_value_copy = 0;
#endif __u64 __arena_global add_stack_result = 0;
__u64 __arena_global add_noreturn_value = 1;
__u64 __arena add64_value = 1;
__u64 __arena add64_result = 0;
__u32 __arena add32_value = 1;
__u32 __arena add32_result = 0;
__u64 __arena add_stack_value_copy = 0;
__u64 __arena add_stack_result = 0;
__u64 __arena add_noreturn_value = 1;
SEC("raw_tp/sys_enter") SEC("raw_tp/sys_enter")
int add(const void *ctx) int add(const void *ctx)
...@@ -58,13 +51,13 @@ int add(const void *ctx) ...@@ -58,13 +51,13 @@ int add(const void *ctx)
return 0; return 0;
} }
__s64 __arena sub64_value = 1; __s64 __arena_global sub64_value = 1;
__s64 __arena sub64_result = 0; __s64 __arena_global sub64_result = 0;
__s32 __arena sub32_value = 1; __s32 __arena_global sub32_value = 1;
__s32 __arena sub32_result = 0; __s32 __arena_global sub32_result = 0;
__s64 __arena sub_stack_value_copy = 0; __s64 __arena_global sub_stack_value_copy = 0;
__s64 __arena sub_stack_result = 0; __s64 __arena_global sub_stack_result = 0;
__s64 __arena sub_noreturn_value = 1; __s64 __arena_global sub_noreturn_value = 1;
SEC("raw_tp/sys_enter") SEC("raw_tp/sys_enter")
int sub(const void *ctx) int sub(const void *ctx)
...@@ -84,8 +77,8 @@ int sub(const void *ctx) ...@@ -84,8 +77,8 @@ int sub(const void *ctx)
return 0; return 0;
} }
__u64 __arena and64_value = (0x110ull << 32); __u64 __arena_global and64_value = (0x110ull << 32);
__u32 __arena and32_value = 0x110; __u32 __arena_global and32_value = 0x110;
SEC("raw_tp/sys_enter") SEC("raw_tp/sys_enter")
int and(const void *ctx) int and(const void *ctx)
...@@ -101,8 +94,8 @@ int and(const void *ctx) ...@@ -101,8 +94,8 @@ int and(const void *ctx)
return 0; return 0;
} }
__u32 __arena or32_value = 0x110; __u32 __arena_global or32_value = 0x110;
__u64 __arena or64_value = (0x110ull << 32); __u64 __arena_global or64_value = (0x110ull << 32);
SEC("raw_tp/sys_enter") SEC("raw_tp/sys_enter")
int or(const void *ctx) int or(const void *ctx)
...@@ -117,8 +110,8 @@ int or(const void *ctx) ...@@ -117,8 +110,8 @@ int or(const void *ctx)
return 0; return 0;
} }
__u64 __arena xor64_value = (0x110ull << 32); __u64 __arena_global xor64_value = (0x110ull << 32);
__u32 __arena xor32_value = 0x110; __u32 __arena_global xor32_value = 0x110;
SEC("raw_tp/sys_enter") SEC("raw_tp/sys_enter")
int xor(const void *ctx) int xor(const void *ctx)
...@@ -133,12 +126,12 @@ int xor(const void *ctx) ...@@ -133,12 +126,12 @@ int xor(const void *ctx)
return 0; return 0;
} }
__u32 __arena cmpxchg32_value = 1; __u32 __arena_global cmpxchg32_value = 1;
__u32 __arena cmpxchg32_result_fail = 0; __u32 __arena_global cmpxchg32_result_fail = 0;
__u32 __arena cmpxchg32_result_succeed = 0; __u32 __arena_global cmpxchg32_result_succeed = 0;
__u64 __arena cmpxchg64_value = 1; __u64 __arena_global cmpxchg64_value = 1;
__u64 __arena cmpxchg64_result_fail = 0; __u64 __arena_global cmpxchg64_result_fail = 0;
__u64 __arena cmpxchg64_result_succeed = 0; __u64 __arena_global cmpxchg64_result_succeed = 0;
SEC("raw_tp/sys_enter") SEC("raw_tp/sys_enter")
int cmpxchg(const void *ctx) int cmpxchg(const void *ctx)
...@@ -156,10 +149,10 @@ int cmpxchg(const void *ctx) ...@@ -156,10 +149,10 @@ int cmpxchg(const void *ctx)
return 0; return 0;
} }
__u64 __arena xchg64_value = 1; __u64 __arena_global xchg64_value = 1;
__u64 __arena xchg64_result = 0; __u64 __arena_global xchg64_result = 0;
__u32 __arena xchg32_value = 1; __u32 __arena_global xchg32_value = 1;
__u32 __arena xchg32_result = 0; __u32 __arena_global xchg32_result = 0;
SEC("raw_tp/sys_enter") SEC("raw_tp/sys_enter")
int xchg(const void *ctx) int xchg(const void *ctx)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment