Re: [PATCH v5 8/8] slub_kunit: extend the test for kfree_rcu_nolock()

[email protected] Wed, 29 Jul 2026 08:39:44 +0000
Newsgroups dev.linux.lists.linux-rt-devel,org.kernel.vger.bpf,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(=
s) to consider:
- [Medium] Missing synchronization for deferred RCU frees causes KUnit test=
 suite contamination and false negatives.
--

--- Patch [8]: [PATCH v5 8/8] slub_kunit: extend the test for kfree_rcu_nol=
ock() ---
commit 975207c355ab3b2db3420df72699cb12e4769b5e
Author: Harry Yoo (Oracle) <[email protected]>

slub_kunit: extend the test for kfree_rcu_nolock()
   =20
When slub_kunit is not built-in, call kfree_rcu() and kfree_rcu_nolock()
to test kfree_rcu_nolock() in slub_kunit.
   =20
Rename the test case as the test covers more _nolock() APIs.

> diff --git a/lib/tests/slub_kunit.c b/lib/tests/slub_kunit.c
> index 8c2b9911471eb..e3b63f0338d5f 100644
> --- a/lib/tests/slub_kunit.c
> +++ b/lib/tests/slub_kunit.c
[ ... ]
> @@ -397,14 +410,14 @@ static void disable_perf_events(struct test_nolock_=
context *ctx)
>  	perf_event_release_kernel(ctx->event);
>  }
> =20
> -static void test_kmalloc_kfree_nolock_perf(struct kunit *test)
> +static void test_kmalloc_nolock_and_friends_perf(struct kunit *test)
>  {
>  	struct test_nolock_context ctx =3D { .test =3D test };
> =20
>  	if (!enable_perf_events(&ctx))
>  		kunit_skip(test, "Failed to enable perf event, skipping");
> =20
> -	test_kmalloc_kfree();
> +	test_kmalloc_and_friends();
> =20
>  	disable_perf_events(&ctx);
>  	KUNIT_EXPECT_EQ(test, 0, slab_errors);

[Severity: Medium]
Will this evaluate slab_errors before all asynchronous frees complete?

Since test_kmalloc_and_friends() queues objects via kfree_rcu() and
kfree_rcu_nolock(), the callbacks could execute in softirq context later.
If they interrupt a subsequent KUnit test, slab_add_kunit_errors() could
attribute any SLUB errors from these deferred frees to the next test, causi=
ng
it to falsely fail while causing this test to falsely pass.

Should we add a synchronization call like kvfree_rcu_barrier() before
checking slab_errors?

[ ... ]
> @@ -438,14 +451,14 @@ static void unregister_slab_kprobes(struct test_nol=
ock_context *ctx)
>  	unregister_kprobe(&ctx->kprobe);
>  }
> =20
> -static void test_kmalloc_kfree_nolock_kprobe(struct kunit *test)
> +static void test_kmalloc_nolock_and_friends_kprobe(struct kunit *test)
>  {
>  	struct test_nolock_context ctx =3D { .test =3D test };
> =20
>  	if (!register_slab_kprobes(&ctx))
>  		kunit_skip(test, "Failed to register kprobe, skipping");
> =20
> -	test_kmalloc_kfree();
> +	test_kmalloc_and_friends();
> =20
>  	unregister_slab_kprobes(&ctx);
>  	KUNIT_EXPECT_EQ(test, 0, slab_errors);

[Severity: Medium]
Does this test case need synchronization for the same reason?

Without a barrier before evaluating slab_errors, deferred RCU frees from
test_kmalloc_and_friends() might leak into the next KUnit test and cause
false test failures.

--=20
Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260729-kfree_rcu_=
[email protected]?part=3D8