From: Emil Tsalapatis Date: Sun, 26 Apr 2026 19:03:31 +0000 (-0400) Subject: selftests/bpf: Add ifdef guard for WRITE_ONCE macro in bpf_atomic.h X-Git-Tag: v7.2-rc1~142^2~106^2~7 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=1fb8e9b32e19f7fa444863a251a5310c54585172;p=thirdparty%2Fkernel%2Flinux.git selftests/bpf: Add ifdef guard for WRITE_ONCE macro in bpf_atomic.h The WRITE_ONCE macro is identically defined both in bpf_atomic.h and in bpf_arena_common.h. However, the bpf_atomic.h definition has no ifdef guard. If bpf_atomic.h is included after bpf_arena.common.h, compilation fails because of the duplicate definition. Guard the definiton in bpf_atomic.h with and ifdef to let programs include the two headers in any order. Duplicating the definition is the simplest solution out of all the alternatives: - Keeping one of the two existing definitions is not possible because both BPF atomics and arena programs need the macro, and the two features are independent. Using one should not require the header for the other. - Factoring out the definition into a new header that only includes it is more churn than just duplicating it. - Factoring out the definition into bpf_experimental.h requires all users of WRITE_ONCE to include the header. However, the arena library introduced in subsequent commits must be self-contained, while bpf_experimental.h is in the base selftests/bpf directory. Both headers are moved to the arena library in a subsequent patch. Signed-off-by: Emil Tsalapatis Reviewed-by: Matt Bobrowski Link: https://lore.kernel.org/r/20260426190338.4615-2-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov --- diff --git a/tools/testing/selftests/bpf/bpf_atomic.h b/tools/testing/selftests/bpf/bpf_atomic.h index c550e57119677..d89a22d63c1c0 100644 --- a/tools/testing/selftests/bpf/bpf_atomic.h +++ b/tools/testing/selftests/bpf/bpf_atomic.h @@ -42,7 +42,9 @@ extern bool CONFIG_X86_64 __kconfig __weak; #define READ_ONCE(x) (*(volatile typeof(x) *)&(x)) +#ifndef WRITE_ONCE #define WRITE_ONCE(x, val) ((*(volatile typeof(x) *)&(x)) = (val)) +#endif #define cmpxchg(p, old, new) __sync_val_compare_and_swap((p), old, new)