Extend the existing BPF CALLX selftests to support PPC64.

Enable the callx_func_ptr_map and callx_rodata_lskel tests for PPC64
by adding a PPC64 ELF ABI v2 condition to their architecture checks.
The gate uses (defined(__powerpc64__) && defined(_CALL_ELF) &&
_CALL_ELF == 2) to ensure tests run only on ELF ABI v2 builds,
where JIT CALLX support is enabled, and skip cleanly on ELF ABI v1
builds.

Also enable verifier_callx and verifier_callx_rodata for the PPC64
BPF target by adding __TARGET_ARCH_powerpc to their architecture
checks. This allows the verifier tests to exercise indirect calls
through function pointers, including pointers stored in read-only
data, for the PPC64 BPF target.

Signed-off-by: Shivani Nittor <[email protected]>
---
 tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c | 3 ++-
 tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c | 3 ++-
 tools/testing/selftests/bpf/progs/verifier_callx.c          | 3 ++-
 tools/testing/selftests/bpf/progs/verifier_callx_rodata.c   | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c 
b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
index cc63b84e4d94..ddb488708b94 100644
--- a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
+++ b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
@@ -9,7 +9,8 @@
 #include <bpf/btf.h>
 
 #if defined(__x86_64__) || defined(__aarch64__) || \
-    (defined(__riscv) && __riscv_xlen == 64)
+    (defined(__riscv) && __riscv_xlen == 64) || \
+    (defined(__powerpc64__) && defined(_CALL_ELF) && _CALL_ELF == 2)
 
 #define CALLEE_INSN    6
 #define DATA           0x1234
diff --git a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c 
b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
index f6ef67c3141e..80f029f358e1 100644
--- a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
+++ b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
@@ -4,7 +4,8 @@
 #include "callx_rodata.lskel.h"
 
 #if defined(__x86_64__) || defined(__aarch64__) || \
-    (defined(__riscv) && __riscv_xlen == 64)
+    (defined(__riscv) && __riscv_xlen == 64) || \
+    (defined(__powerpc64__) && defined(_CALL_ELF) && _CALL_ELF == 2)
 
 static void run(int prog_fd, int expected, const char *name)
 {
diff --git a/tools/testing/selftests/bpf/progs/verifier_callx.c 
b/tools/testing/selftests/bpf/progs/verifier_callx.c
index a12bc421e75c..b99eab7b3725 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx.c
@@ -8,7 +8,8 @@
 
 /* gcc doesn't support indirect calls */
 #if defined(__clang__) && (defined(__TARGET_ARCH_x86) || 
defined(__TARGET_ARCH_arm64) || \
-    (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
+    (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
+    defined(__TARGET_ARCH_powerpc))
 
 #define CALLX_INSN(DST, SRC, OFF, IMM) \
        BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, DST, SRC, OFF, IMM)
diff --git a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c 
b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
index 6cf58ca9ac5b..56be21e7bbcd 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
@@ -8,7 +8,8 @@
 
 /* gcc doesn't support indirect calls */
 #if defined(__clang__) && (defined(__TARGET_ARCH_x86) || 
defined(__TARGET_ARCH_arm64) || \
-    (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
+    (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
+    defined(__TARGET_ARCH_powerpc))
 
 /*
  * Read-only data with pointers to functions, where the compiler puts tables
-- 
2.52.0


Reply via email to