From: Yonghong Song <yonghong.song@linux.dev>
To: Jiayuan Chen <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Puranjay Mohan <puranjay@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH bpf-next v1] selftests/bpf: Guard addr_space_cast code with __BPF_FEATURE_ADDR_SPACE_CAST
Date: Wed, 22 Oct 2025 08:33:12 -0700 [thread overview]
Message-ID: <6aa7fafd-30b1-4605-8b80-4a158934218d@linux.dev> (raw)
In-Reply-To: <20251022071825.238909-1-jiayuan.chen@linux.dev>
On 10/22/25 12:18 AM, Jiayuan Chen wrote:
> When compiling the BPF selftests with Clang versions that do not support
> the addr_space_cast builtin, the build fails with assembly errors in
> "verifier_ldsx.c" [1].
>
> The root cause is that the inline assembly using addr_space_cast is
> being processed by a compiler that lacks this feature. To resolve this,
> wrap the affected code sections (specifically the arena_ldsx_* test
> functions) with #if defined(__BPF_FEATURE_ADDR_SPACE_CAST). This
> ensures the code is only compiled when the Clang supports the necessary
> feature, preventing build failures on older or incompatible compiler
> versions.
>
> This change maintains test coverage for systems with support while
> allowing the tests to build successfully in all environments.
>
> [1]:
> root:tools/testing/selftests/bpf$ make
>
> CLNG-BPF [test_progs] verifier_ldsx.bpf.o
> progs/verifier_ldsx.c:322:2: error: invalid operand for instruction
> 322 | "r1 = %[arena] ll;"
> | ^
> <inline asm>:1:52: note: instantiated into assembly here
> 1 | r1 = arena ll;r0 = 0xdeadbeef;r0 = addr_space_cast(r0,...
> | ^
I think you are using llvm18 and earlier. Why can you upgrade to llvm19 and later
which should solve the problem?
> Fixes: f61654912404 ("selftests: bpf: Add tests for signed loads from arena")
We do not need to have Fixes. compiler is also moving forward, we cannot support
really old compiler and it is no point to have __BPF_FEATURE_ADDR_SPACE_CAST
for really old compilers. So at some point, __BPF_FEATURE_ADDR_SPACE_CAST will
become default.
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
> tools/testing/selftests/bpf/progs/verifier_ldsx.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/progs/verifier_ldsx.c b/tools/testing/selftests/bpf/progs/verifier_ldsx.c
> index c8494b682c31..cefa02e417d3 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_ldsx.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_ldsx.c
> @@ -263,6 +263,7 @@ __naked void ldsx_ctx_8(void)
> : __clobber_all);
> }
>
> +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
> SEC("syscall")
> __description("Arena LDSX Disasm")
> __success
> @@ -425,6 +426,7 @@ __naked void arena_ldsx_s32(void *ctx)
> : __clobber_all
> );
> }
> +#endif
If you are really using llvm18, then I found there are some other
build failures as well, e.g.,
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/bpf_arena_common.h:47:15: error: conflicting types for 'bpf_arena_alloc_pages'
47 | void __arena* bpf_arena_alloc_pages(void *map, void __arena *addr, __u32 page_cnt,
| ^
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/include/vmlinux.h:160636:48: note: previous declaration is here
160636 | extern void __attribute__((address_space(1))) *bpf_arena_alloc_pages(void *p__map, void __attribute__((address_space(1))) *addr__ign, u32 page_cnt, int node_id, u64 flags) __weak __ksym;
| ^
In file included from progs/stream.c:8:
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/bpf_arena_common.h:49:5: error: conflicting types for 'bpf_arena_reserve_pages'
49 | int bpf_arena_reserve_pages(void *map, void __arena *addr, __u32 page_cnt) __ksym __weak;
| ^
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/include/vmlinux.h:160638:12: note: previous declaration is here
160638 | extern int bpf_arena_reserve_pages(void *p__map, void __attribute__((address_space(1))) *ptr__ign, u32 page_cnt) __weak __ksym;
| ^
In file included from progs/stream.c:8:
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/bpf_arena_common.h:50:6: error: conflicting types for 'bpf_arena_free_pages'
50 | void bpf_arena_free_pages(void *map, void __arena *ptr, __u32 page_cnt) __ksym __weak;
| ^
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/include/vmlinux.h:160637:13: note: previous declaration is here
160637 | extern void bpf_arena_free_pages(void *p__map, void __attribute__((address_space(1))) *ptr__ign, u32 page_cnt) __weak __ksym;
| ^
Please cover all build failures at once.
>
> /* to retain debug info for BTF generation */
> void kfunc_root(void)
next prev parent reply other threads:[~2025-10-22 15:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 7:18 [PATCH bpf-next v1] selftests/bpf: Guard addr_space_cast code with __BPF_FEATURE_ADDR_SPACE_CAST Jiayuan Chen
2025-10-22 15:33 ` Yonghong Song [this message]
2025-10-22 16:48 ` Alexei Starovoitov
2025-10-23 3:33 ` Jiayuan Chen
2025-10-23 3:42 ` Yonghong Song
2025-10-23 7:49 ` Jiayuan Chen
2025-10-23 15:42 ` pahole next->master. Was: " Alexei Starovoitov
2025-10-27 14:58 ` Arnaldo Carvalho de Melo
2025-10-27 15:09 ` Arnaldo Carvalho de Melo
2025-10-27 21:56 ` Arnaldo Carvalho de Melo
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=6aa7fafd-30b1-4605-8b80-4a158934218d@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=justinstitt@google.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=martin.lau@linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@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