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

Kumar Kartikeya Dwivedi <[email protected]>
Newsgroups org.kernel.vger.bpf
Message-ID <[email protected]>
The arena kfunc runtime tests are restricted to x86-64 and arm64, so new
JIT implementations can compile without exercising rebasing, nullable
arguments, five-register calls, or the verifier capability gate.

Run those tests on RISC-V, s390, LoongArch, and PowerPC64 as well. Teach
test_loader about PowerPC64 so it can select the newly annotated programs.

Enable the struct_ops arena tests on RISC-V, s390, and LoongArch, whose
indirect trampolines now implement the separate reverse-conversion path.
PowerPC64 remains covered only for kfunc arguments because it does not
advertise the struct_ops capability.

Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]>
---
 .../bpf/prog_tests/test_struct_ops_arena.c    | 16 ++++++---
 .../testing/selftests/bpf/progs/arena_kfunc.c | 36 +++++++++++++++++++
 tools/testing/selftests/bpf/progs/bpf_misc.h  |  1 +
 tools/testing/selftests/bpf/test_loader.c     |  5 +++
 4 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
index 7f9f54ba3fbe..7f44b00af06d 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
@@ -6,7 +6,13 @@
 #include "struct_ops_arena_attach.skel.h"
 #include "struct_ops_arena_fail.skel.h"
 
-#if defined(__x86_64__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__aarch64__) || \
+	(defined(__riscv) && __riscv_xlen == 64) || defined(__s390x__) || \
+	defined(__loongarch__)
+#define HAVE_ARENA_STRUCT_OPS_ARGS
+#endif
+
+#ifdef HAVE_ARENA_STRUCT_OPS_ARGS
 /*
  * Attach callbacks with __arena and __arena__nullable arguments and drive
  * them through the bpf_testmod_ops3_call_test_arena*() kfuncs.
@@ -111,11 +117,11 @@ static void arena_arg_attach(void)
 void serial_test_struct_ops_arena(void)
 {
 	/*
-	 * Arena struct_ops arguments need JIT support, currently x86-64 and
-	 * arm64 only. Elsewhere verification fails with "JIT does not support
-	 * arena arguments", so the programs cannot even load.
+	 * Arena struct_ops arguments need JIT support. Elsewhere verification
+	 * fails with "JIT does not support arena arguments", so the programs
+	 * cannot even load.
 	 */
-#if defined(__x86_64__) || defined(__aarch64__)
+#ifdef HAVE_ARENA_STRUCT_OPS_ARGS
 	if (test__start_subtest("arena_arg"))
 		arena_arg();
 	if (test__start_subtest("arena_arg_fail"))
diff --git a/tools/testing/selftests/bpf/progs/arena_kfunc.c b/tools/testing/selftests/bpf/progs/arena_kfunc.c
index bf0d304e0e59..8ee2bd4d6633 100644
--- a/tools/testing/selftests/bpf/progs/arena_kfunc.c
+++ b/tools/testing/selftests/bpf/progs/arena_kfunc.c
@@ -28,6 +28,10 @@ volatile u64 stash;
 SEC("syscall")
 __arch_x86_64
 __arch_arm64
+__arch_riscv64
+__arch_s390x
+__arch_loongarch
+__arch_powerpc64
 __success __retval(0)
 int arena_arg_forms(void *ctx)
 {
@@ -72,6 +76,10 @@ int arena_arg_forms(void *ctx)
 SEC("syscall")
 __arch_x86_64
 __arch_arm64
+__arch_riscv64
+__arch_s390x
+__arch_loongarch
+__arch_powerpc64
 __success __retval(0)
 int arena_arg_rebase(void *ctx)
 {
@@ -114,6 +122,10 @@ int arena_arg_rebase(void *ctx)
 SEC("syscall")
 __arch_x86_64
 __arch_arm64
+__arch_riscv64
+__arch_s390x
+__arch_loongarch
+__arch_powerpc64
 __success __retval(0)
 int arena_args5(void *ctx)
 {
@@ -146,6 +158,10 @@ int arena_args5(void *ctx)
 SEC("syscall")
 __arch_x86_64
 __arch_arm64
+__arch_riscv64
+__arch_s390x
+__arch_loongarch
+__arch_powerpc64
 __success __retval(0)
 int arena_arg_mixed(void *ctx)
 {
@@ -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)
 {
@@ -195,6 +215,10 @@ int arena_arg_unpopulated(void *ctx)
 SEC("syscall")
 __arch_x86_64
 __arch_arm64
+__arch_riscv64
+__arch_s390x
+__arch_loongarch
+__arch_powerpc64
 __failure __msg("arena pointer requires a program with an associated arena")
 int arena_arg_no_arena(void *ctx)
 {
@@ -205,6 +229,10 @@ int arena_arg_no_arena(void *ctx)
 SEC("syscall")
 __arch_x86_64
 __arch_arm64
+__arch_riscv64
+__arch_s390x
+__arch_loongarch
+__arch_powerpc64
 __failure __msg("is not a pointer to arena or scalar")
 int arena_arg_bad_reg(void *ctx)
 {
@@ -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)
 {
@@ -232,6 +264,10 @@ int arena_arg_stack(void *ctx)
 SEC("syscall")
 __arch_x86_64
 __arch_arm64
+__arch_riscv64
+__arch_s390x
+__arch_loongarch
+__arch_powerpc64
 __description("arena_arg_stack: not supported, dummy test")
 __success
 int arena_arg_stack(void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
index 5eacf1b43252..c35359c97e44 100644
--- a/tools/testing/selftests/bpf/progs/bpf_misc.h
+++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
@@ -159,6 +159,7 @@
 #define __arch_riscv64		__arch("RISCV64")
 #define __arch_s390x		__arch("s390x")
 #define __arch_loongarch	__arch("LOONGARCH")
+#define __arch_powerpc64	__arch("POWERPC64")
 #define __caps_unpriv(caps)	__test_tag("test_caps_unpriv=" EXPAND_QUOTE(caps))
 #define __load_if_JITed()	__test_tag("load_mode=jited")
 #define __load_if_no_JITed()	__test_tag("load_mode=no_jited")
diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
index 07807757b518..221393f2a8ef 100644
--- a/tools/testing/selftests/bpf/test_loader.c
+++ b/tools/testing/selftests/bpf/test_loader.c
@@ -378,6 +378,7 @@ enum arch {
 	ARCH_RISCV64	= 0x8,
 	ARCH_S390X	= 0x10,
 	ARCH_LOONGARCH	= 0x20,
+	ARCH_POWERPC64	= 0x40,
 };
 
 static int get_current_arch(void)
@@ -392,6 +393,8 @@ static int get_current_arch(void)
 	return ARCH_S390X;
 #elif defined(__loongarch__)
 	return ARCH_LOONGARCH;
+#elif defined(__powerpc64__)
+	return ARCH_POWERPC64;
 #endif
 	return ARCH_UNKNOWN;
 }
@@ -585,6 +588,8 @@ static int parse_test_spec(struct test_loader *tester,
 				arch = ARCH_S390X;
 			} else if (strcmp(val, "LOONGARCH") == 0) {
 				arch = ARCH_LOONGARCH;
+			} else if (strcmp(val, "POWERPC64") == 0) {
+				arch = ARCH_POWERPC64;
 			} else {
 				PRINT_FAIL("bad arch spec: '%s'\n", val);
 				err = -EINVAL;
-- 
2.53.0
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.