Re: [PATCH for-next v3 1/9] slub_kunit: fall back to SW perf events when HW PMU is not available

From: sashiko-bot

Date: Mon Jun 15 2026 - 07:14:42 EST


Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The test cleanup function reads and logs test context variables before disabling the asynchronous perf event, introducing a data race and causing the reported counts to be inaccurate.
--

commit 4fccf2c0f65ae8a2788eab369ec35d223d9c897d
Author: Harry Yoo (Oracle) <harry@xxxxxxxxxx>

slub_kunit: fall back to SW perf events when HW PMU is not available

This commit introduces a fallback mechanism in the slub_kunit tests to use
software perf events when a hardware PMU is unavailable. This ensures the
tests can still execute in virtualized environments that lack virtual PMUs.

> diff --git a/lib/tests/slub_kunit.c b/lib/tests/slub_kunit.c
> --- a/lib/tests/slub_kunit.c
> +++ b/lib/tests/slub_kunit.c
[ ... ]
> +static void disable_perf_events(struct test_nolock_context *ctx)
> +{
> + kunit_info(ctx->test, "%s perf events: callback_count: %d, alloc_ok: %d, alloc_fail: %d\n",
> + ctx->is_perf_type_hw ? "HW" : "SW",
> + ctx->callback_count, ctx->alloc_ok, ctx->alloc_fail);
> +
> + perf_event_disable(ctx->event);

[Severity: Medium]
Could reading the counters before disabling the perf event result in missed
counts?

Since the perf event continues to fire asynchronously in NMI or IRQ context
until perf_event_disable() is called, the variables might be incremented
after kunit_info() has already read them.

Would it be safer to disable the perf event before reading and logging the
results, restoring the original ordering from the previous cleanup block?

> + perf_event_release_kernel(ctx->event);
> +}
[ ... ]
> @@ -368,11 +412,7 @@ static void test_kmalloc_kfree_nolock(struct kunit *test)
> }
>
> cleanup:
> - perf_event_disable(ctx.event);
> - perf_event_release_kernel(ctx.event);
> -
> - kunit_info(test, "callback_count: %d, alloc_ok: %d, alloc_fail: %d\n",
> - ctx.callback_count, ctx.alloc_ok, ctx.alloc_fail);
> + disable_perf_events(&ctx);
>
> if (alloc_fail)
> kunit_skip(test, "Allocation failed");

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260615-kfree_rcu_nolock-v3-0-70a54f3775bb@xxxxxxxxxx?part=1