Skip to content

Commit 69afcfb

Browse files
committed
selftests/bpf: fix test_spin_lock_fail.c's global vars usage
JIRA: https://issues.redhat.com/browse/RHEL-85485 commit 1b2bfc2 Author: Andrii Nakryiko <andrii@kernel.org> Date: Tue Oct 22 21:39:06 2024 -0700 selftests/bpf: fix test_spin_lock_fail.c's global vars usage Global variables of special types (like `struct bpf_spin_lock`) make underlying ARRAY maps non-mmapable. To make this work with libbpf's mmaping logic, application is expected to declare such special variables as static, so libbpf doesn't even attempt to mmap() such ARRAYs. test_spin_lock_fail.c didn't follow this rule, but given it relied on this test to trigger failures, this went unnoticed, as we never got to the step of mmap()'ing these ARRAY maps. It is fragile and relies on specific sequence of libbpf steps, which are an internal implementation details. Fix the test by marking lockA and lockB as static. Fixes: c48748a ("selftests/bpf: Add failure test cases for spin lock pairing") Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20241023043908.3834423-2-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Viktor Malik <vmalik@redhat.com>
1 parent 7e4b23a commit 69afcfb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/testing/selftests/bpf/progs/test_spin_lock_fail.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ struct {
2828
},
2929
};
3030

31-
SEC(".data.A") struct bpf_spin_lock lockA;
32-
SEC(".data.B") struct bpf_spin_lock lockB;
31+
static struct bpf_spin_lock lockA SEC(".data.A");
32+
static struct bpf_spin_lock lockB SEC(".data.B");
3333

3434
SEC("?tc")
3535
int lock_id_kptr_preserve(void *ctx)

0 commit comments

Comments
 (0)