All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix flaky refcount asserts in map_kptr_race
@ 2026-07-23 11:40 Maxim Khmelevskii
  2026-07-23 11:49 ` sashiko-bot
  2026-07-23 16:34 ` Kumar Kartikeya Dwivedi
  0 siblings, 2 replies; 3+ messages in thread
From: Maxim Khmelevskii @ 2026-07-23 11:40 UTC (permalink / raw)
  To: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann
  Cc: bpf, Ilya Leoshkevich, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev

bpf_testmod shares objects across tests; prog_test_struct that holds
cnt.refs.counter is one of them. Refcounter release is deferred behind
an RCU grace period, so it may still be pending when this test asserts.
wait_for_refs prevents flaky failures when other tests have contaminated
the refcount.

Fixed tests:
 - test_htab_leak
 - test_percpu_htab_leak
 - test_sk_ls_leak

Reported-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Maxim Khmelevskii <max@linux.ibm.com>
---
 .../testing/selftests/bpf/prog_tests/map_kptr_race.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/map_kptr_race.c b/tools/testing/selftests/bpf/prog_tests/map_kptr_race.c
index 506ed55e8528..5a543b3465a8 100644
--- a/tools/testing/selftests/bpf/prog_tests/map_kptr_race.c
+++ b/tools/testing/selftests/bpf/prog_tests/map_kptr_race.c
@@ -28,6 +28,15 @@ static int read_refs(struct map_kptr_race *skel)
 	return skel->bss->num_of_refs;
 }
 
+static void wait_for_refs(struct map_kptr_race *skel)
+{
+	for (int i = 0; i < 500; i++) {
+		if (read_refs(skel) == 2)
+			return;
+		usleep(10 * 1000);
+	}
+}
+
 static void test_htab_leak(void)
 {
 	LIBBPF_OPTS(bpf_test_run_opts, opts,
@@ -73,6 +82,7 @@ static void test_htab_leak(void)
 		sched_yield();
 
 	ASSERT_EQ(watcher->bss->map_freed, 1, "map_freed");
+	wait_for_refs(watcher);
 	ASSERT_EQ(read_refs(watcher), 2, "htab refcount");
 
 out_watcher:
@@ -134,6 +144,7 @@ static void test_percpu_htab_leak(void)
 		sched_yield();
 
 	ASSERT_EQ(watcher->bss->map_freed, 1, "map_freed");
+	wait_for_refs(watcher);
 	ASSERT_EQ(read_refs(watcher), 2, "percpu_htab refcount");
 
 out_watcher:
@@ -195,6 +206,7 @@ static void test_sk_ls_leak(void)
 		sched_yield();
 
 	ASSERT_EQ(watcher->bss->map_freed, 1, "map_freed");
+	wait_for_refs(watcher);
 	ASSERT_EQ(read_refs(watcher), 2, "sk_ls refcount");
 
 out_watcher:
-- 
2.54.0


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

end of thread, other threads:[~2026-07-23 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 11:40 [PATCH bpf-next] selftests/bpf: Fix flaky refcount asserts in map_kptr_race Maxim Khmelevskii
2026-07-23 11:49 ` sashiko-bot
2026-07-23 16:34 ` Kumar Kartikeya Dwivedi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.