From: "Emil Tsalapatis" <emil@etsalapatis.com>
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
"Emil Tsalapatis" <emil@etsalapatis.com>
Cc: "bpf" <bpf@vger.kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Eduard" <eddyz87@gmail.com>, "Emil Tsalapatis" <etsal@meta.com>
Subject: Re: [PATCH bpf-next v3 2/9] selftests/bpf: Add test for scalar/arena pointer addition
Date: Sat, 04 Apr 2026 15:00:22 -0400 [thread overview]
Message-ID: <DHKLOPTK8IW9.KVASSDNT9UQJ@etsalapatis.com> (raw)
In-Reply-To: <CAADnVQLGfsEsMp=yhn6wk03AwXkWgGf3KF9UL6U0-SbuhtbzJw@mail.gmail.com>
On Fri Apr 3, 2026 at 4:25 PM EDT, Alexei Starovoitov wrote:
> On Thu, Apr 2, 2026 at 9:27 PM Emil Tsalapatis <emil@etsalapatis.com> wrote:
>>
>> From: Emil Tsalapatis <etsal@meta.com>
>>
>> Add a selftest that ensures scalar += ptr_to_arena instructions
>> are accepted by the verifier.
>>
>> Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
>> ---
>> .../selftests/bpf/progs/verifier_arena.c | 29 +++++++++++++++++++
>> 1 file changed, 29 insertions(+)
>>
>> diff --git a/tools/testing/selftests/bpf/progs/verifier_arena.c b/tools/testing/selftests/bpf/progs/verifier_arena.c
>> index c4b8daac4388..450e8f1181cd 100644
>> --- a/tools/testing/selftests/bpf/progs/verifier_arena.c
>> +++ b/tools/testing/selftests/bpf/progs/verifier_arena.c
>> @@ -477,4 +477,33 @@ int arena_kfuncs_under_bpf_lock(void *ctx)
>>
>> return 0;
>> }
>> +/*
>> + * Test that scalar += PTR_TO_ARENA correctly upgrades the
>> + * destination register to a PTR_TO_ARENA.
>> + */
>> +SEC("syscall")
>> +__success __retval(0)
>> +int scalar_add_arena_ptr(void *ctx)
>> +{
>> +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
>
> I think the #if can be removed, since the whole test is in asm?
With Clang 18 the assembly fails to load for me with "Invalid operand for
instruction". AFAICT this is because addr_space_cast is only recognized as a
valid instruction from the BPF backend starting Clang >= 19, which is
also the first version that defines the feature flag.
>
>> + int __arena *result, *arena_ptr;
>> +
>> + /* Needed for the verifier to link the arena to the subprog. */
>> + volatile char __arena *base = arena_base(&arena);
>> +
>> + /* Passing base here to avoid optimizing it out during compilation. */
>> + asm volatile (
>> + "%[arena_ptr] = 8192;"
>> + "%[arena_ptr] = addr_space_cast(%[arena_ptr], 0x0, 0x1);"
>> + "%[result] = 12;"
>> + "%[result] += %[arena_ptr];"
>> + : [result] "=r"(result),
>> + [arena_ptr] "=&r"(arena_ptr)
>> + : "r"(base)
>> + :
>> + );
>> +#endif
>> + return 0;
>> +}
>> +
>> char _license[] SEC("license") = "GPL";
>> --
>> 2.53.0
>>
next prev parent reply other threads:[~2026-04-04 19:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 4:27 [PATCH bpf-next v3 0/9] Introduce arena library and runtime Emil Tsalapatis
2026-04-03 4:27 ` [PATCH bpf-next v3 1/9] bpf: Upgrade scalar to PTR_TO_ARENA on arena pointer addition Emil Tsalapatis
2026-04-03 5:04 ` bot+bpf-ci
2026-04-03 18:07 ` Emil Tsalapatis
2026-04-03 18:42 ` Song Liu
2026-04-03 20:24 ` Alexei Starovoitov
2026-04-04 18:24 ` Emil Tsalapatis
2026-04-03 4:27 ` [PATCH bpf-next v3 2/9] selftests/bpf: Add test for scalar/arena " Emil Tsalapatis
2026-04-03 18:43 ` Song Liu
2026-04-03 20:25 ` Alexei Starovoitov
2026-04-04 19:00 ` Emil Tsalapatis [this message]
2026-04-04 20:01 ` Alexei Starovoitov
2026-04-03 4:27 ` [PATCH bpf-next v3 3/9] selftests/bpf: Move bpf_arena_spin_lock.h to the top level Emil Tsalapatis
2026-04-03 18:44 ` Song Liu
2026-04-03 4:27 ` [PATCH bpf-next v3 4/9] selftests/bpf: Deduplicate WRITE_ONCE macro between headers Emil Tsalapatis
2026-04-03 18:44 ` Song Liu
2026-04-03 4:27 ` [PATCH bpf-next v3 5/9] selftests/bpf: Add basic libarena scaffolding Emil Tsalapatis
2026-04-03 4:27 ` [PATCH bpf-next v3 6/9] selftests/bpf: Add arena ASAN runtime to libarena Emil Tsalapatis
2026-04-03 4:27 ` [PATCH bpf-next v3 7/9] selftests/bpf: Add ASAN support for libarena selftests Emil Tsalapatis
2026-04-03 4:27 ` [PATCH bpf-next v3 8/9] selftests/bpf: Add buddy allocator for libarena Emil Tsalapatis
2026-04-03 4:27 ` [PATCH bpf-next v3 9/9] selftests/bpf: Add selftests for libarena buddy allocator Emil Tsalapatis
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=DHKLOPTK8IW9.KVASSDNT9UQJ@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=etsal@meta.com \
--cc=memxor@gmail.com \
/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