public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/1] Fix BPF struct_ops BTF cleanup race condition
@ 2026-03-10 20:21 Gregory Bell
  2026-03-10 20:21 ` [PATCH bpf-next 1/1] bpf: Fix BTF module cleanup race condition in struct_ops Gregory Bell
  0 siblings, 1 reply; 21+ messages in thread
From: Gregory Bell @ 2026-03-10 20:21 UTC (permalink / raw)
  To: bpf
  Cc: martin.lau, ast, daniel, andrii, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, Gregory Bell

This patch fixes a race condition in BPF struct_ops where consecutive
test runs fail due to a timing mismatch between BTF object cleanup and
BTF module removal.

When running BPF struct_ops tests consecutively, the second test fails
because BTF object references take longer to be released while their
associated module is removed from btf_modules list immediately
during module unload. This creates a race condition where the second
test retrieves the cached BTF object but cannot find valid module
information, causing btf_try_get_module() to return NULL.

The fix synchronizes these cleanup operations by waiting for active BTF
references to be released before completing module cleanup, eliminating
the race condition.

This issue is reproducible with any of the following tests: global_map_resize,
pro_epilogue, struct_ops_module and struct_ops_multi

	./test_progs -t global_map_resize; ./test_progs -t global_map_resize

	#134/1   global_map_resize/global_map_resize_bss:OK
	#134/2   global_map_resize/global_map_resize_data:OK
	#134/3   global_map_resize/global_map_resize_invalid:OK
	#134     global_map_resize:OK
	Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
	global_map_resize_bss_subtest:PASS:test_global_map_resize__open 0 nsec
	libbpf: map 'test_glo.bss': cannot be resized, last var must be an array
	libbpf: map 'test_glo.bss': failed to adjust resized BTF, clearing BTF key/value info: -EINVAL
	global_map_resize_bss_subtest:PASS:bpf_map__set_value_size 0 nsec
	global_map_resize_bss_subtest:PASS:resize 0 nsec
	global_map_resize_bss_subtest:PASS:percpu_arr_resize 0 nsec
	global_map_resize_bss_subtest:PASS:array_len 0 nsec
	global_map_resize_bss_subtest:PASS:bpf_map__initial_value (ptr) 0 nsec
	global_map_resize_bss_subtest:PASS:bpf_map__initial_value (size) 0 nsec
	libbpf: map 'st_ops_resize': failed to create: -EINVAL
	libbpf: failed to load BPF skeleton 'test_global_map_resize': -EINVAL
	global_map_resize_bss_subtest:FAIL:test_global_map_resize__load unexpected error: -22 (errno 22)
	#134/1   global_map_resize/global_map_resize_bss:FAIL
	global_map_resize_data_subtest:PASS:test_global_map_resize__open 0 nsec
	global_map_resize_data_subtest:PASS:bpf_map__set_value_size 0 nsec
	global_map_resize_data_subtest:PASS:resize 0 nsec
	global_map_resize_data_subtest:PASS:percpu_arr_resize 0 nsec
	global_map_resize_data_subtest:PASS:array_len 0 nsec
	global_map_resize_data_subtest:PASS:bpf_map__initial_value (ptr) 0 nsec
	global_map_resize_data_subtest:PASS:bpf_map__initial_value (size) 0 nsec
	libbpf: map 'st_ops_resize': failed to create: -EINVAL
	libbpf: failed to load BPF skeleton 'test_global_map_resize': -EINVAL
	global_map_resize_data_subtest:FAIL:test_global_map_resize__load unexpected error: -22 (errno 22)
	#134/2   global_map_resize/global_map_resize_data:FAIL
	#134/3   global_map_resize/global_map_resize_invalid:OK
	#134     global_map_resize:FAIL

After the fix, consecutive runs work reliably without requiring delays.

Gregory Bell (1):
  bpf: Fix BTF module cleanup race condition in struct_ops

 kernel/bpf/btf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2026-03-12  3:09 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 20:21 [PATCH bpf-next 0/1] Fix BPF struct_ops BTF cleanup race condition Gregory Bell
2026-03-10 20:21 ` [PATCH bpf-next 1/1] bpf: Fix BTF module cleanup race condition in struct_ops Gregory Bell
2026-03-10 20:58   ` bot+bpf-ci
2026-03-10 21:39   ` Kumar Kartikeya Dwivedi
2026-03-10 22:38     ` Amery Hung
2026-03-10 22:47       ` Kumar Kartikeya Dwivedi
2026-03-10 23:17         ` Amery Hung
2026-03-10 23:35           ` Kumar Kartikeya Dwivedi
2026-03-11  0:20             ` Martin KaFai Lau
2026-03-11  9:30               ` Kumar Kartikeya Dwivedi
2026-03-11  9:34                 ` Kumar Kartikeya Dwivedi
2026-03-11 12:21                 ` Alan Maguire
2026-03-11 13:05                   ` Kumar Kartikeya Dwivedi
2026-03-11 13:03               ` [PATCH] bpf: Release module BTF IDR before module unload Kumar Kartikeya Dwivedi
2026-03-11 13:26                 ` Kumar Kartikeya Dwivedi
2026-03-11 16:48                   ` Greg Bell
2026-03-11 13:40                 ` bot+bpf-ci
2026-03-11 19:10                 ` Martin KaFai Lau
2026-03-11 19:17                   ` Andrii Nakryiko
2026-03-11 19:55                     ` Martin KaFai Lau
2026-03-12  3:08                 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox