From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399420; b=BJDX/jC8XGfIyY6cnUORw2Ptk0bHnAHQ7JNEwfxK5w9Dqe3nE2WTVG+DreqVEqAmLJPQ uYhbWCCf0qndBEAnAMyji5WbMpBzsTLet0lnRyPZzcv5EcrrCizD1EWq/lrsqLLsd4NYf 0bhGgrSrqV78tas2h9iqZjX74PPNWhHSGJQ0i9ILDzKz+ADyf6Sk+1tJZ2Oz1Mp4A0TbF 0rkgWFx1Uwo0d5/HJ7QoegOgS8vHikl5Lsz0/3ftu7J6pplMqDEhzkjt1oSIIjkTePU7g W/LjX1neD5+D01GNqEqSmilviAB/2UeOZ3Wdl/CKVasIbTgwi2x/VgriD+raKmKJFZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399420; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=7WitMghBlIHsdZPHhrTg1xUV1rUEBPtd9JGe9uFhYMw=; b=5ZBuziHqwCsSuVgmIvVIDhXUOUmkbfiJbo7uz7bW/9RcrbbUVnzQPdJognxmTmYp5nPE oGkQ1LBRWk0rUBmDyXr+74KO0NkuQ7U/AjfYhxyOLQzXcSTPEvjDZT0rpee3To1W9vMKr JLV/cSylWKkE7+yH5U1N9tpQsBaOHOCa5VPmgmEhOrE1PGeCdwsOMJtDJNusqB6Qkd4cs cF0QfC5Z4yf6d5fK46WuWizIxO3BPFlhf+VbjymQcbP9a6lv48yVb5/VtxqTleAvUtKzf Hj9Jp+aXxbDsYlPM/UuWVvTUy8GEO9jIvJtMJBwokAnuAB+CDxWb9YEGdIrZ6xNgHvQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="a/LZN7R3"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09422606A322 for ; Fri, 4 Dec 2026 15:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a/LZN7R3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 879E41F000CE; Fri, 4 Dec 2026 15:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796399419; bh=7WitMghBlIHsdZPHhrTg1xUV1rUEBPtd9JGe9uFhYMw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=a/LZN7R3nlvaivCkwJ4HPiomIY5Tz86K6nIfXIZsL+321C51iyaznt1mkTaPLrylw bp8aJ7J5WdE98YGceVGdwiq2QXEmviH+H9H+jN/GxjhwlnA3ssxXub/EZXJNNA6m6S ruu6d/hJaXuOGqX650x59ZWxN9qjar2mlLA6A1ZpIULeIb+RWx+y4312azyudQ3YQp p9OxdLo1iafCCdhzpZ4GsWZ48T8XKKpTbXSGziNqGY8MJZ28u/uiBdsSxMpNo85i11 8QH65wFjKYxEwkMSj/1r33Mh8f7Np4ZtSirK33Gg9wGFyon2hnporJ5P1kkfy1M+h0 /wH+zRVA9ZeGw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next v2] selftests/bpf: Fix flaky refcount asserts in map_kptr_race Reply-To: sashiko-reviews@lists.linux.dev To: "Maxim Khmelevskii" Cc: bpf@vger.kernel.org In-Reply-To: <20261204153138.31801-2-max@linux.ibm.com> References: <20261204153138.31801-2-max@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 15:50:19 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Low] bpf: non-conforming multi-line comment style in wait_for_refs() - [Low] bpf: missing Fixes trailer referencing commit 2939d7b3b0e5 - [Low] bpf: unnecessary fexit program in wait_for_refs() vs polling read_refs() - [Low] bpf: ignored read_refs() error return stalls wait_for_refs() for 5 seconds - [Low] bpf: lost wakeup in wait_for_refs() from fexit recursion suppression -- commit 671d94475461ae9179f227fbd592ac3b5f77db64 Author: Maxim Khmelevskii > selftests/bpf: Fix flaky refcount asserts in map_kptr_race > > 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. > Add a new test prog which attaches to bpf_kfunc_call_test_release and > checks the reference counter. If the ref counter is 1, it indicates > that all references were released. Use the new prog to wait until the > references are released. > > Fixed tests: > - test_htab_leak > - test_percpu_htab_leak > - test_sk_ls_leak > > Reported-by: Ilya Leoshkevich > Reviewed-by: Ilya Leoshkevich > Signed-off-by: Maxim Khmelevskii [Severity: Low] This fixes flaky refcount assertions in map_kptr_race. Should it include: Fixes: 2939d7b3b0e5 ("selftests/bpf: Add tests for special fields races") > diff --git a/tools/testing/selftests/bpf/prog_tests/map_kptr_race.c b/too= ls/testing/selftests/bpf/prog_tests/map_kptr_race.c > index 506ed55e85289..e6dd71c80a739 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,22 @@ static int read_refs(struct map_kptr_race *skel) > return skel->bss->num_of_refs; > } > =20 > +static void wait_for_refs(struct map_kptr_race *skel) > +{ > + __u64 timeout =3D 5ULL * 1000 * 1000 * 1000; > + __u64 start =3D get_time_ns(); > + > + /* At least one bpf_kfunc_call_test_release call is needed after > + * kfunc_test_release is attached, otherwise refs_settled > + * might never be set. > + */ [Severity: Low] This isn't a bug, but BPF code uses the modern kernel multi-line comment style with the opening /* on its own line. > + read_refs(skel); > + while (!READ_ONCE(skel->bss->refs_settled) && > + get_time_ns() - start < timeout) { > + usleep(1000); > + } > +} [Severity: Low] Should wait_for_refs() return early if read_refs(skel) fails? read_refs() returns -1 when bpf_prog_test_run_opts() fails or count_ref() returns non-zero, without running bpf_kfunc_call_test_release(). Ignoring that return value lets the loop sleep for the full 5-second timeout before returning to the caller. [ ... ] > diff --git a/tools/testing/selftests/bpf/progs/map_kptr_race.c b/tools/te= sting/selftests/bpf/progs/map_kptr_race.c > index f6f136cd8f609..fafe4dc88b395 100644 > --- a/tools/testing/selftests/bpf/progs/map_kptr_race.c > +++ b/tools/testing/selftests/bpf/progs/map_kptr_race.c [ ... ] > @@ -178,6 +179,14 @@ int BPF_PROG(sk_map_free, struct bpf_map *map) > return 0; > } > =20 > +SEC("fexit/bpf_kfunc_call_test_release") > +int BPF_PROG(kfunc_test_release, struct prog_test_ref_kfunc *p) > +{ > + if (p->cnt.refs.counter =3D=3D 1) > + refs_settled =3D 1; > + return 0; > +} [Severity: Low] Can wait_for_refs() miss the final 2 -> 1 transition and stall for the full 5-second timeout if an RCU softirq nests inside kfunc_test_release()? read_refs() invokes count_ref() via bpf_prog_run_pin_on_cpu(), which leaves softirqs enabled. If one deferred release is still pending when kfunc_test_release() runs, a nested RCU softirq on the same CPU can drop the last reference while kfunc_test_release() is still on current->bpf_ctx: read_refs() -> count_ref() bpf_kfunc_call_test_release() (refs: 3 -> 2) __bpf_prog_enter_recur() (sets current->bpf_ctx) kfunc_test_release() (reads refs =3D=3D 2) ... -> bpf_obj_free_fields() bpf_kfunc_call_test_release() (refs: 2 -> 1) __bpf_prog_enter_recur() <-- skipped, prog already in bpf_ctx bpf_prog_exit_run_ctx() (refs_settled remains 0) Because wait_for_refs() calls read_refs() only once before the loop, refs_settled stays 0 until the 5-second timeout expires. [Severity: Low] Is the kfunc_test_release fexit program needed here instead of polling read_refs(skel) directly in wait_for_refs()? Because test_sk_ls_leak() calls map_kptr_race__attach(skel), adding an auto-attachable fexit program also attaches it to skel in addition to the three manual attaches on watcher. Polling read_refs(skel) in the existing timeout loop until it returns 2 or < 0 (similar to wait_for_map_release() in tools/testing/selftests/bpf/prog_tests/map_kptr.c) would avoid the extra fexit program, refs_settled flag, and attachment boilerplate, and also avoids the lost-notification race above. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204153138.3180= 1-2-max@linux.ibm.com?part=3D1