From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Emil Tsalapatis <emil@etsalapatis.com>,
kkd@meta.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v4 08/13] selftests/bpf: Add kfunc __arena and __arena__nullable argument tests
Date: Thu, 06 Aug 2026 21:44:11 -0700 [thread overview]
Message-ID: <8cb9a9537d806b3d8f9d5798d03fd290adf7e8ac.camel@gmail.com> (raw)
In-Reply-To: <20260805210427.3218326-9-memxor@gmail.com>
On Wed, 2026-08-05 at 23:04 +0200, Kumar Kartikeya Dwivedi wrote:
> From: Tejun Heo <tj@kernel.org>
>
> Add arena-argument kfuncs to bpf_testmod, which also exercises the
> argument rebasing on module kfuncs, and tests covering the accepted
> argument forms (arena pointer, low 32 bits as a scalar, full user
> address as a scalar), the exact rebase semantics via capture kfuncs
> returning the raw argument (zero low 32 bits arrive as the arena kernel
> base under __arena and as NULL under __arena__nullable), a NULL round
> trip through a nullable deref kfunc, five arena arguments in one call, a
> mixed __arena plus __arena__nullable call exercising both bitmasks on one
> call site, a kernel-side dereference of an unpopulated page recovering
> through the scratch page, and the rejections (no arena in the program,
> incompatible register type).
>
> The tests run on x86-64 and skip elsewhere, as programs with
> arena-tagged kfunc args fail verification where the JIT lacks support.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
...
> diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
> index b79bafca68f7..7eaee71783b6 100644
> --- a/tools/testing/selftests/bpf/prog_tests/verifier.c
> +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
> @@ -2,6 +2,7 @@
>
> #include <test_progs.h>
>
> +#include "arena_kfunc.skel.h"
> #include "cap_helpers.h"
> #include "verifier_align.skel.h"
> #include "verifier_and.skel.h"
> @@ -161,6 +162,13 @@ static void run_tests_aux(const char *skel_name,
>
> #define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL)
>
> +/*
> + * The test kfuncs live in bpf_testmod. Resolving kfuncs against module
> + * BTFs needs CAP_SYS_ADMIN, so run with full capabilities instead of
> + * through the verifier tests' capability-restricted runner.
> + */
Nit: useless comment.
> +void test_arena_kfunc(void) { RUN_TESTS(arena_kfunc); }
> +
> void test_verifier_align(void) { RUN(verifier_align); }
> void test_verifier_and(void) { RUN(verifier_and); }
> void test_verifier_arena(void) { RUN(verifier_arena); }
> diff --git a/tools/testing/selftests/bpf/progs/arena_kfunc.c b/tools/testing/selftests/bpf/progs/arena_kfunc.c
> new file mode 100644
> index 000000000000..d6c382ce81af
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/arena_kfunc.c
...
> +SEC("syscall")
> +__arch_x86_64
> +__success __retval(0)
> +int arena_arg_rebase(void *ctx)
> +{
> +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
> + u64 __arena *val;
> + u64 base, off;
> +
> + val = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
> + if (!val)
> + return 1;
> +
> + base = bpf_kfunc_arena_cap_test(NULL);
> + if (!base)
> + return 2;
> +
> + /* only the low 32 bits contribute */
> + stash = 0xbadc0ffe00000000;
> + if (bpf_kfunc_arena_cap_test((u64 *)stash) != base)
> + return 3;
> +
> + off = (u32)(u64)val;
> + if (bpf_kfunc_arena_cap_test((u64 *)val) != base + off)
> + return 4;
> +
> + if (bpf_kfunc_arena_cap_nullable_test(NULL) != 0)
> + return 5;
> +
> + stash = 0xbadc0ffe00000000;
> + if (bpf_kfunc_arena_cap_nullable_test((u64 *)stash) != 0)
> + return 6;
> +
> + if (bpf_kfunc_arena_cap_nullable_test((u64 *)val) != base + off)
> + return 7;
> +
> + bpf_arena_free_pages(&arena, (void __arena *)val, 1);
> +#endif
> + return 0;
> +}
> +
> +SEC("syscall")
> +__arch_x86_64
> +__success __retval(0)
> +int arena_arg_nullable(void *ctx)
Nit: This test seem to test the same thing as the group of
bpf_kfunc_arena_cap_nullable_test() in the previous test.
I'd drop the one or the other.
> +{
> +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
> + u64 __arena *val;
> + u64 ret;
> +
> + val = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
> + if (!val)
> + return 1;
> +
> + *val = 41;
> + ret = bpf_kfunc_arena_nullable_arg_test((u64 *)val);
> + if (ret != 41 || *val != 42)
> + return 2;
> +
> + if (bpf_kfunc_arena_nullable_arg_test(NULL) != 0xdeadbeef)
> + return 3;
> +
> + bpf_arena_free_pages(&arena, (void __arena *)val, 1);
> +#endif
> + return 0;
> +}
...
next prev parent reply other threads:[~2026-08-07 4:44 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 21:04 [PATCH bpf-next v4 00/13] Add arena argument support to kfuncs and struct_ops Kumar Kartikeya Dwivedi
2026-08-05 21:04 ` [PATCH bpf-next v4 01/13] bpf: Rename 'early' BTF checking as a preparation phase Kumar Kartikeya Dwivedi
2026-08-06 16:29 ` Amery Hung
2026-08-05 21:04 ` [PATCH bpf-next v4 02/13] bpf: Split subprogram and kfunc collection Kumar Kartikeya Dwivedi
2026-08-05 21:49 ` bot+bpf-ci
2026-08-06 16:31 ` Amery Hung
2026-08-05 21:04 ` [PATCH bpf-next v4 03/13] bpf: Collect kfuncs after resolving program resources Kumar Kartikeya Dwivedi
2026-08-06 16:37 ` Amery Hung
2026-08-05 21:04 ` [PATCH bpf-next v4 04/13] bpf: Support __arena and __arena__nullable kfunc argument suffixes Kumar Kartikeya Dwivedi
2026-08-06 17:22 ` Amery Hung
2026-08-06 19:20 ` Kumar Kartikeya Dwivedi
2026-08-06 19:23 ` Kumar Kartikeya Dwivedi
2026-08-06 19:31 ` Amery Hung
2026-08-07 0:51 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 05/13] bpf: Support __arena and __arena__nullable on struct_ops arguments Kumar Kartikeya Dwivedi
2026-08-05 21:18 ` sashiko-bot
2026-08-07 0:51 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 06/13] bpf, x86: JIT __arena kfunc argument rebasing Kumar Kartikeya Dwivedi
2026-08-05 21:04 ` [PATCH bpf-next v4 07/13] bpf, x86: Convert struct_ops arena arguments in the trampoline Kumar Kartikeya Dwivedi
2026-08-07 4:09 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 08/13] selftests/bpf: Add kfunc __arena and __arena__nullable argument tests Kumar Kartikeya Dwivedi
2026-08-07 4:44 ` Eduard Zingerman [this message]
2026-08-05 21:04 ` [PATCH bpf-next v4 09/13] selftests/bpf: Add JIT-sequence tests for __arena kfunc arguments Kumar Kartikeya Dwivedi
2026-08-07 4:45 ` Eduard Zingerman
2026-08-05 21:04 ` [PATCH bpf-next v4 10/13] selftests/bpf: Add struct_ops __arena and __arena__nullable argument tests Kumar Kartikeya Dwivedi
2026-08-05 21:15 ` sashiko-bot
2026-08-05 21:04 ` [PATCH bpf-next v4 11/13] bpf, x86: Fix stack-passed arguments for indirect trampolines Kumar Kartikeya Dwivedi
2026-08-05 21:15 ` sashiko-bot
2026-08-05 21:04 ` [PATCH bpf-next v4 12/13] selftests/bpf: Test stack-passed struct_ops arena arguments Kumar Kartikeya Dwivedi
2026-08-05 21:04 ` [PATCH bpf-next v4 13/13] bpf: Reject tracing progs for struct_ops with arena args Kumar Kartikeya Dwivedi
2026-08-05 22:02 ` bot+bpf-ci
2026-08-07 4:51 ` Eduard Zingerman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8cb9a9537d806b3d8f9d5798d03fd290adf7e8ac.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=emil@etsalapatis.com \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=memxor@gmail.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox