public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Gregory Bell <grbell@redhat.com>
To: bpf@vger.kernel.org
Cc: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
	jolsa@kernel.org, Gregory Bell <grbell@redhat.com>
Subject: [PATCH bpf-next 0/1] Fix BPF struct_ops BTF cleanup race condition
Date: Tue, 10 Mar 2026 16:21:01 -0400	[thread overview]
Message-ID: <cover.1773170190.git.grbell@redhat.com> (raw)

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


             reply	other threads:[~2026-03-10 20:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 20:21 Gregory Bell [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1773170190.git.grbell@redhat.com \
    --to=grbell@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox