Re: [PATCH bpf-next v1 13/14] selftests/bpf: Exercise arena arguments on every capable JIT

[email protected]
Newsgroups org.kernel.vger.bpf
Message-ID <123c22a672a6f56a6f0150ca001a35c5dcfee73375ee94492ed9799cc249d870@mail.kernel.org>
> diff --git a/tools/testing/selftests/bpf/progs/arena_kfunc.c b/tools/testing/selftests/bpf/progs/arena_kfunc.c
> index bf0d304e0e59c..8ee2bd4d66331 100644
> --- a/tools/testing/selftests/bpf/progs/arena_kfunc.c
> +++ b/tools/testing/selftests/bpf/progs/arena_kfunc.c

[ ... ]

> @@ -174,6 +190,10 @@ int arena_arg_mixed(void *ctx)
>  SEC("syscall")
>  __arch_x86_64
>  __arch_arm64
> +__arch_riscv64
> +__arch_s390x
> +__arch_loongarch
> +__arch_powerpc64
>  __success __retval(0)
>  int arena_arg_unpopulated(void *ctx)
>  {
> @@ -187,7 +207,7 @@ int arena_arg_unpopulated(void *ctx)
>  	 * and returns VM_FAULT_SIGBUS. That condition is diagnosed by
>  	 * bpf_prog_test_run_syscall() as -EFAULT propagated from ctx_access_ok().
>  	 */
> -	val = (u64 *)bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
> +	val = (u64 __arena *)bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
>  	if (!val)
>  		return 3;
>
> @@ -195,9 +215,13 @@ int arena_arg_unpopulated(void *ctx)

Can arena_arg_unpopulated run safely on the newly added architectures?

This test deliberately passes an unpopulated arena address to the kernel
(stash = (u64)val + PAGE_SIZE, then bpf_kfunc_arena_arg_test((u64 *)stash)).
The kernel dereferences this address in bpf_testmod.c:

  old = *val__arena;
  *val__arena = old + 1;

For this to work without crashing, the page fault handler must call
bpf_arena_handle_page_fault(), which installs the per-arena scratch page.

Looking at the fault handler integration, bpf_arena_handle_page_fault() is
only wired up on x86-64 (arch/x86/mm/fault.c) and arm64
(arch/arm64/mm/fault.c). The other architectures use the __weak stub that
always returns false, meaning the fault is never recovered.

Without a scratch page, the fault on an unmapped vmalloc address becomes
an unrecoverable kernel oops. The new JIT capability
(bpf_jit_supports_arena_kfunc_args) only covers rebasing the argument at
the call site, not recovering from unpopulated-page faults.

Should this test remain restricted to x86-64 and arm64, or does the
recovery path need to be implemented on the new architectures first?


[ ... ]

> @@ -221,6 +249,10 @@ int arena_arg_bad_reg(void *ctx)
>  SEC("syscall")
>  __arch_x86_64
>  __arch_arm64
> +__arch_riscv64
> +__arch_s390x
> +__arch_loongarch
> +__arch_powerpc64
>  __failure __msg("arena pointer cannot be a stack argument")
>  int arena_arg_stack(void *ctx)
>  {
> @@ -228,6 +260,10 @@ int arena_arg_stack(void *ctx)
>  	return bpf_kfunc_arena_stack_arg_test(1, 2, 3, 4, 5, (u64 *)1);
>  }

Will arena_arg_stack produce the expected failure message on the new arches?

The test expects the verifier to reject the program with "arena pointer
cannot be a stack argument". However, this message is only reachable after
the verifier checks whether the JIT supports stack arguments.

bpf_kfunc_arena_stack_arg_test() takes 6 parameters, which exceeds
MAX_BPF_FUNC_REG_ARGS (5). In kernel/bpf/verifier.c, gen_kfunc_arg_proto()
checks this first:

  if (nargs > MAX_BPF_FUNC_REG_ARGS && !bpf_jit_supports_stack_args()) {
      verbose(env, "JIT does not support kfunc %s() with %d args\n", ...);
      return -ENOTSUPP;
  }

Only after this gate does the per-argument loop inspect individual
arguments and emit "arena pointer cannot be a stack argument".

bpf_jit_supports_stack_args() returns true only on x86-64 and arm64. On
riscv64, s390, loongarch, and powerpc64, it returns false (the __weak stub
in kernel/bpf/core.c). So the program does fail to load on those arches,
but with "JIT does not support kfunc bpf_kfunc_arena_stack_arg_test() with
6 args" instead of the expected message.

test_loader's validate_msgs() will report this as a test failure since it
does not match the __msg annotation. Should this test stay limited to
x86-64 and arm64?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32538351576
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.