mirror of
https://github.com/torvalds/linux.git
synced 2026-08-01 03:59:40 +02:00
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 <emil@etsalapatis.com> Reviewed-by: Matt Bobrowski <mattbobrowski@google.com> Link: https://lore.kernel.org/r/20260426190338.4615-2-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
fbb5ba99e2
commit
1fb8e9b32e
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user