Re: [PATCH 2/7] kfence: kunit: skip when no pool is available

From: Marco Elver

Date: Thu May 14 2026 - 03:55:27 EST


On Thu, 14 May 2026 at 07:07, Jia He <justin.he@xxxxxxx> wrote:
>
> When KFENCE is compiled in but disabled at boot (KFENCE_SAMPLE_INTERVAL=0)
> or __kfence_pool is not allocated, every kfence kunit case fails with
> -EINVAL.
>
> Use kunit_skip() so they are reported as skipped instead.
>
> To: Alexander Potapenko <glider@xxxxxxxxxx>
> To: Marco Elver <elver@xxxxxxxxxx>
> To: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
> To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: kasan-dev@xxxxxxxxxxxxxxxx
> Cc: linux-mm@xxxxxxxxx
>
> Signed-off-by: Jia He <justin.he@xxxxxxx>

Acked-by: Marco Elver <elver@xxxxxxxxxx>

Fair enough - typically this failure was a way to know something went
wrong in the test setup. But I also understand that it's not always
possible to just not load this test if kfence is not enabled, say with
some compliance test suites or such.

> ---
> mm/kfence/kfence_test.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c
> index 5725a367246d..e376329dd621 100644
> --- a/mm/kfence/kfence_test.c
> +++ b/mm/kfence/kfence_test.c
> @@ -822,8 +822,10 @@ static int test_init(struct kunit *test)
> unsigned long flags;
> int i;
>
> - if (!__kfence_pool)
> - return -EINVAL;
> + if (!__kfence_pool) {
> + kunit_skip(test, "kfence pool not allocated or kfence not enabled");
> + return 0;
> + }
>
> spin_lock_irqsave(&observed.lock, flags);
> for (i = 0; i < ARRAY_SIZE(observed.lines); i++)
> --
> 2.34.1
>