linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v1] selftests/bpf: Guard addr_space_cast code with __BPF_FEATURE_ADDR_SPACE_CAST
@ 2025-10-22  7:18 Jiayuan Chen
  2025-10-22 15:33 ` Yonghong Song
  0 siblings, 1 reply; 10+ messages in thread
From: Jiayuan Chen @ 2025-10-22  7:18 UTC (permalink / raw)
  To: bpf
  Cc: Jiayuan Chen, Andrii Nakryiko, Eduard Zingerman,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Shuah Khan, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Puranjay Mohan,
	linux-kselftest, linux-kernel, llvm

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,...
      |                                                           ^

Fixes: f61654912404 ("selftests: bpf: Add tests for signed loads from arena")
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
 
 /* to retain debug info for BTF generation */
 void kfunc_root(void)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-10-27 21:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).