]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
selftests/bpf: fix test_spin_lock_fail.c's global vars usage
authorAndrii Nakryiko <andrii@kernel.org>
Wed, 23 Oct 2024 04:39:06 +0000 (21:39 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 12:53:17 +0000 (13:53 +0100)
commit9bb1c0c79cbb91f69dbe42bcd6e577064c762252
tree6a82ea14ff7e4151f0e516ceb0fff2d04eaf10ba
parent54e8b501b3ea9371e4a9aa639c75b681fa5680f0
selftests/bpf: fix test_spin_lock_fail.c's global vars usage

[ Upstream commit 1b2bfc29695d273492c3dd8512775261f3272686 ]

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: c48748aea4f8 ("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: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/bpf/progs/test_spin_lock_fail.c