]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/bpf: Test getting associated struct_ops in timer callback
authorAmery Hung <ameryhung@gmail.com>
Wed, 3 Dec 2025 23:37:48 +0000 (15:37 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Sat, 6 Dec 2025 00:17:58 +0000 (16:17 -0800)
commit0e841d19263ab6e1ca2b280109832f57624e48d1
tree0c9f7ea1f63bfa3a178c7d9383fefb6dff62c43d
parent04fd12df4e05dd6fd3017b637f6fbc9da10b4e65
selftests/bpf: Test getting associated struct_ops in timer callback

Make sure 1) a timer callback can also reference the associated
struct_ops, and then make sure 2) the timer callback cannot get a
dangled pointer to the struct_ops when the map is freed.

The test schedules a timer callback from a struct_ops program since
struct_ops programs do not pin the map. It is possible for the timer
callback to run after the map is freed. The timer callback calls a
kfunc that runs .test_1() of the associated struct_ops, which should
return MAP_MAGIC when the map is still alive or -1 when the map is
gone.

The first subtest added in this patch schedules the timer callback to
run immediately, while the map is still alive. The second subtest added
schedules the callback to run 500ms after syscall_prog runs and then
frees the map right after syscall_prog runs. Both subtests then wait
until the callback runs to check the return of the kfunc.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20251203233748.668365-7-ameryhung@gmail.com
tools/testing/selftests/bpf/prog_tests/test_struct_ops_assoc.c
tools/testing/selftests/bpf/progs/struct_ops_assoc_in_timer.c [new file with mode: 0644]