* [PATCH v3 1/4] powerpc/bpf: Add support for instruction array
2026-04-01 15:21 [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump adubey
@ 2026-04-01 15:21 ` adubey
2026-04-01 15:21 ` [PATCH v3 2/4] selftest/bpf: Enable instruction array test for powerpc adubey
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: adubey @ 2026-04-01 15:21 UTC (permalink / raw)
To: linuxppc-dev
Cc: hbathini, bpf, maddy, ast, andrii, daniel, shuah, linux-kselftest,
Abhishek Dubey
From: Abhishek Dubey <adubey@linux.ibm.com>
On loading the BPF program, the verifier might adjust/omit some
instructions. The adjusted instruction offset is accounted in the
map containing original instruction -> xlated mapping. This patch
add ppc64 JIT support to additionally build the xlated->jitted
mapping for every instruction present in instruction array. This
change is needed to enable support for indirect jumps, added in a
subsequent patch.
Invoke bpf_prog_update_insn_ptrs() with offset pair of xlated_offset
and jited_offset. The offset mapping is already available, which is
being used for bpf_prog_fill_jited_linfo() and can be directly used
for bpf_prog_update_insn_ptrs() as well.
Additional details present at:
commit b4ce5923e780 ("bpf, x86: add new map type: instructions array")
Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
---
arch/powerpc/net/bpf_jit_comp.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index b2fdf8ff9c60..50103b3794fb 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -373,6 +373,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
goto out_addrs;
}
bpf_prog_fill_jited_linfo(fp, addrs);
+ /*
+ * On ABI V1, executable code starts after the function
+ * descriptor, so adjust base accordingly.
+ */
+ bpf_prog_update_insn_ptrs(fp, addrs,
+ (void *)fimage + FUNCTION_DESCR_SIZE);
+
out_addrs:
if (!image && priv_stack_ptr) {
fp->aux->priv_stack_ptr = NULL;
--
2.52.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v3 2/4] selftest/bpf: Enable instruction array test for powerpc
2026-04-01 15:21 [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump adubey
2026-04-01 15:21 ` [PATCH v3 1/4] powerpc/bpf: Add support for instruction array adubey
@ 2026-04-01 15:21 ` adubey
2026-04-01 15:21 ` [PATCH v3 3/4] powerpc64/bpf: Add support for indirect jump adubey
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: adubey @ 2026-04-01 15:21 UTC (permalink / raw)
To: linuxppc-dev
Cc: hbathini, bpf, maddy, ast, andrii, daniel, shuah, linux-kselftest,
Abhishek Dubey, Venkat Rao Bagalkote
From: Abhishek Dubey <adubey@linux.ibm.com>
With instruction array now supported, enable corresponding bpf
selftest for powerpc.
Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
---
tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
index 269870bec941..482d38b9c29e 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
@@ -3,7 +3,7 @@
#include <bpf/bpf.h>
#include <test_progs.h>
-#ifdef __x86_64__
+#if defined(__x86_64__) || defined(__powerpc__)
static int map_create(__u32 map_type, __u32 max_entries)
{
const char *map_name = "insn_array";
--
2.52.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v3 3/4] powerpc64/bpf: Add support for indirect jump
2026-04-01 15:21 [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump adubey
2026-04-01 15:21 ` [PATCH v3 1/4] powerpc/bpf: Add support for instruction array adubey
2026-04-01 15:21 ` [PATCH v3 2/4] selftest/bpf: Enable instruction array test for powerpc adubey
@ 2026-04-01 15:21 ` adubey
2026-04-01 15:21 ` [PATCH v3 4/4] selftest/bpf: Enable gotox tests for powerpc64 adubey
2026-04-08 4:28 ` [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump Madhavan Srinivasan
4 siblings, 0 replies; 6+ messages in thread
From: adubey @ 2026-04-01 15:21 UTC (permalink / raw)
To: linuxppc-dev
Cc: hbathini, bpf, maddy, ast, andrii, daniel, shuah, linux-kselftest,
Abhishek Dubey
From: Abhishek Dubey <adubey@linux.ibm.com>
Add support for a new instruction
BPF_JMP|BPF_X|BPF_JA, SRC=0, DST=Rx, off=0, imm=0
which does an indirect jump to a location stored in Rx. The
register Rx should have type PTR_TO_INSN. This new type ensures
that the Rx register contains a value (or a range of values)
loaded from a correct jump table – map of type instruction array.
Support indirect jump to all registers in powerpc64 JIT using
the ctr register. Move Rx content to ctr register, then invoke
bctr instruction to branch to address stored in ctr register.
Skip save and restore of TOC as the jump is always within the
program context.
Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
---
arch/powerpc/net/bpf_jit_comp64.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c
index d9038c468af6..db364d9083e7 100644
--- a/arch/powerpc/net/bpf_jit_comp64.c
+++ b/arch/powerpc/net/bpf_jit_comp64.c
@@ -1708,6 +1708,14 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct code
addrs[++i] = ctx->idx * 4;
break;
+ /*
+ * JUMP reg
+ */
+ case BPF_JMP | BPF_JA | BPF_X:
+ EMIT(PPC_RAW_MTCTR(dst_reg));
+ EMIT(PPC_RAW_BCTR());
+ break;
+
/*
* Return/Exit
*/
--
2.52.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 4/4] selftest/bpf: Enable gotox tests for powerpc64
2026-04-01 15:21 [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump adubey
` (2 preceding siblings ...)
2026-04-01 15:21 ` [PATCH v3 3/4] powerpc64/bpf: Add support for indirect jump adubey
@ 2026-04-01 15:21 ` adubey
2026-04-08 4:28 ` [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump Madhavan Srinivasan
4 siblings, 0 replies; 6+ messages in thread
From: adubey @ 2026-04-01 15:21 UTC (permalink / raw)
To: linuxppc-dev
Cc: hbathini, bpf, maddy, ast, andrii, daniel, shuah, linux-kselftest,
Abhishek Dubey, Venkat Rao Bagalkote
From: Abhishek Dubey <adubey@linux.ibm.com>
With gotox instruction and jumptable now supported,
enable corresponding bpf selftest on powerpc.
Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
---
tools/testing/selftests/bpf/progs/verifier_gotox.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/verifier_gotox.c b/tools/testing/selftests/bpf/progs/verifier_gotox.c
index 607dad058ca1..0f43b56ec2bc 100644
--- a/tools/testing/selftests/bpf/progs/verifier_gotox.c
+++ b/tools/testing/selftests/bpf/progs/verifier_gotox.c
@@ -6,7 +6,7 @@
#include "bpf_misc.h"
#include "../../../include/linux/filter.h"
-#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)
+#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_powerpc)
#define DEFINE_SIMPLE_JUMP_TABLE_PROG(NAME, SRC_REG, OFF, IMM, OUTCOME) \
\
@@ -384,6 +384,6 @@ jt0_%=: \
: __clobber_all);
}
-#endif /* __TARGET_ARCH_x86 || __TARGET_ARCH_arm64 */
+#endif /* __TARGET_ARCH_x86 || __TARGET_ARCH_arm64 || __TARGET_ARCH_powerpc*/
char _license[] SEC("license") = "GPL";
--
2.52.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump
2026-04-01 15:21 [PATCH v3 0/4] powerpc/bpf: Add support for instruction array and indirect jump adubey
` (3 preceding siblings ...)
2026-04-01 15:21 ` [PATCH v3 4/4] selftest/bpf: Enable gotox tests for powerpc64 adubey
@ 2026-04-08 4:28 ` Madhavan Srinivasan
4 siblings, 0 replies; 6+ messages in thread
From: Madhavan Srinivasan @ 2026-04-08 4:28 UTC (permalink / raw)
To: linuxppc-dev, adubey
Cc: hbathini, bpf, ast, andrii, daniel, shuah, linux-kselftest
On Wed, 01 Apr 2026 11:21:29 -0400, adubey@linux.ibm.com wrote:
> The first 2 patch enable support for instruction array. Now, the
> instruction offset map maintain the mapping:
> original inst -> xlated inst -> jited inst
>
> The last two patch enable support for indirect jump. Any eligile
> register can store jump target address for control flow to jump.
>
> [...]
Applied to powerpc/next.
[1/4] powerpc/bpf: Add support for instruction array
https://git.kernel.org/powerpc/c/1e4bac7eb95a5a1aed5b39971ef77dca5b0f8a9f
[2/4] selftest/bpf: Enable instruction array test for powerpc
https://git.kernel.org/powerpc/c/66cad93ad325b332868c062bbd0de65ca4e59657
[3/4] powerpc64/bpf: Add support for indirect jump
https://git.kernel.org/powerpc/c/a32325c0e623d594992c4e4616fa685c0e765a33
[4/4] selftest/bpf: Enable gotox tests for powerpc64
https://git.kernel.org/powerpc/c/e1f7a0e196e293c223a882788c6d1a884d06d6d8
cheers
^ permalink raw reply [flat|nested] 6+ messages in thread