From: Alexei Starovoitov map_kptr_race/htab_leak fails occasionally in a complete run of test_progs: test_htab_leak:FAIL:htab refcount unexpected htab refcount: actual 6 != expected 2 This is a race between two tests. It is not a leak in the kernel. - map_kptr runs immediately before htab_leak. The two tests examine the refcount of the same test object. - The kernel frees maps asynchronously. Thus the maps drop their references some time after close(). - map_kptr waits for that after each subtest, but not after the last one. Wait after the last subtest too. Signed-off-by: Alexei Starovoitov --- tools/testing/selftests/bpf/prog_tests/map_kptr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/map_kptr.c b/tools/testing/selftests/bpf/prog_tests/map_kptr.c index 17e707dddda8..f103f8cd458b 100644 --- a/tools/testing/selftests/bpf/prog_tests/map_kptr.c +++ b/tools/testing/selftests/bpf/prog_tests/map_kptr.c @@ -225,6 +225,11 @@ void serial_test_map_kptr(void) /* Observe refcount dropping to 1 on map release. */ test_map_kptr_success(true); + + /* The next test counts the same references */ + ASSERT_OK(kern_sync_rcu_tasks_trace(skel), "sync rcu_tasks_trace"); + ASSERT_OK(kern_sync_rcu(), "sync rcu"); + wait_for_map_release(); } rcu_tasks_trace_gp__destroy(skel); -- 2.55.0