From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Maxim Khmelevskii" <max@linux.ibm.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>
Cc: <bpf@vger.kernel.org>, "Ilya Leoshkevich" <iii@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH bpf-next] selftests/bpf: Fix flaky refcount asserts in map_kptr_race
Date: Thu, 23 Jul 2026 18:34:56 +0200 [thread overview]
Message-ID: <DK63HA8KEYWH.1W1W2IJEWEVRD@gmail.com> (raw)
In-Reply-To: <20260723114042.559926-2-max@linux.ibm.com>
On Thu Jul 23, 2026 at 1:40 PM CEST, Maxim Khmelevskii wrote:
> 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>
> ---
Wouldn't this still be flaky? Could we order these tests and wait for a RCU gp
to pass before finishing each one? We have kern_sync_rcu(). Either way, I don't
think the current approach is the right way forward.
pw-bot: cr
> .../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:
prev parent reply other threads:[~2026-07-23 16:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260723114042.559926-2-max@linux.ibm.com>
2026-07-23 11:49 ` [PATCH bpf-next] selftests/bpf: Fix flaky refcount asserts in map_kptr_race sashiko-bot
2026-07-23 16:34 ` Kumar Kartikeya Dwivedi [this message]
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=DK63HA8KEYWH.1W1W2IJEWEVRD@gmail.com \
--to=memxor@gmail.com \
--cc=agordeev@linux.ibm.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=max@linux.ibm.com \
/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