Skip to content

Commit 0769857

Browse files
puranjaymohanAlexei Starovoitov
authored andcommitted
selftests/bpf: fix implementation of smp_mb()
As BPF doesn't include any barrier instructions, smp_mb() is implemented by doing a dummy value returning atomic operation. Such an operation acts a full barrier as enforced by LKMM and also by the work in progress BPF memory model. If the returned value is not used, clang[1] can optimize the value returning atomic instruction in to a normal atomic instruction which provides no ordering guarantees. Mark the variable as volatile so the above optimization is never performed and smp_mb() works as expected. [1] https://godbolt.org/z/qzze7bG6z Fixes: 88d706b ("selftests/bpf: Introduce arena spin lock") Signed-off-by: Puranjay Mohan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent fd60aa0 commit 0769857

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/testing/selftests/bpf/bpf_atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern bool CONFIG_X86_64 __kconfig __weak;
6161

6262
#define smp_mb() \
6363
({ \
64-
unsigned long __val; \
64+
volatile unsigned long __val; \
6565
__sync_fetch_and_add(&__val, 0); \
6666
})
6767

0 commit comments

Comments
 (0)