powerpc64/bpf: Add support for instruction array and indirect jump
Subsystems (5)
v2 cover powerpc64/bpf: Add support for instruction array and indirect jump
From: Abhishek Dubey <[email protected]>
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.
The features will be enabled on ppc32 in a separate series.
The patch series is rebased over:
https://lore.kernel.org/bpf/[email protected]
All selftest related to instruction array and indirect jump are passing.
./test_progs-cpuv4 -n 20
#21/1 bpf_insn_array/one2one:OK
#21/2 bpf_insn_array/simple:OK
#21/3 bpf_insn_array/deletions:OK
#21/4 bpf_insn_array/deletions-with-functions:OK #21/5 bpf_insn_array/blindness:OK
#21/6 bpf_insn_array/incorrect-index:OK #21/7 bpf_insn_array/load-unfrozen-map:OK #21/8 bpf_insn_array/no-map-reuse:OK #21/9 bpf_insn_array/bpf-side-ops:OK
#21 bpf_insn_array:OK
Summary: 1/9 PASSED, 0 SKIPPED, 0 FAILED
./test_progs-cpuv4 -n 21
#20/1 bpf_gotox/one-switch:OK
#20/2 bpf_gotox/one-switch-non-zero-sec-offset:OK #20/3 bpf_gotox/two-switches:OK
#20/4 bpf_gotox/big-jump-table:OK
#20/5 bpf_gotox/static-global:OK
#20/6 bpf_gotox/nonstatic-global:OK
#20/7 bpf_gotox/other-sec:OK
#20/8 bpf_gotox/static-global-other-sec:OK #20/9 bpf_gotox/nonstatic-global-other-sec:OK #20/10 bpf_gotox/one-jump-two-maps:OK #20/11 bpf_gotox/one-map-two-jumps:OK
#20 bpf_gotox:OK
Summary: 1/11 PASSED, 0 SKIPPED, 0 FAILED
v1->v2:
Handle image offset for ABIv1
[v1]: https://lore.kernel.org/bpf/[email protected]
Abhishek Dubey (4):
powerpc64/bpf: Add support for instruction array selftest/bpf: Enable instruction array test for powerpc64 powerpc64/bpf: Add support for indirect jump selftest/bpf: Enable gotox tests for powerpc64
arch/powerpc/net/bpf_jit_comp.c | 10 ++++++++++ arch/powerpc/net/bpf_jit_comp64.c | 8 ++++++++ .../testing/selftests/bpf/prog_tests/bpf_insn_array.c | 2 +- tools/testing/selftests/bpf/progs/verifier_gotox.c | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-)
Signature · 1 line
2.52.0
PATCH v2 1/4 powerpc64/bpf: Add support for instruction array
From: Abhishek Dubey <[email protected]>
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")
--- arch/powerpc/net/bpf_jit_comp.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/powerpc/net/bpf_jit_comp.c +10 -0
@@ -373,6 +373,16 @@ 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. +*/ +#ifdef CONFIG_PPC64_ELF_ABI_V1 +bpf_prog_update_insn_ptrs (fp, addrs, + (void *)fimage +FUNCTION_DESCR_SIZE ); +#else +bpf_prog_update_insn_ptrs (fp, addrs, fimage); +#endif out_addrs:if (!image && priv_stack_ptr) { fp->aux->priv_stack_ptr =NULL ;
Signature · 1 line
2.52.0
Re: [PATCH v2 1/4] powerpc64/bpf: Add support for instruction array
Quoted 10 lines · On 27/02/26 7:13 am, [email protected] wrote:
From: Abhishek Dubey <[email protected]>
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->jittedmapping for every instruction present in instruction array. This change is needed to enable support for indirect jumps, added in a subsequent patch.
Quoted 9 lines
Invoke
bpf_prog_update_insn_ptrs()with offset pair ofxlated_offsetandjited_offset. The offset mapping is already available, which is being used forbpf_prog_fill_jited_linfo()and can be directly used forbpf_prog_update_insn_ptrs()as well.Additional details present at:
commit
b4ce5923e780("bpf, x86: add new map type: instructions array")
Looks good to me. Except for a minor nit below..
Quoted 14 lines
Signed-off-by Abhishek Dubey <[email protected]>--- arch/powerpc/net/bpf_jit_comp.c | 10 ++++++++++ 1 file changed, 10 insertions(+)arch/powerpc/net/bpf_jit_comp.c +1
-0@@ -373,6 +373,16 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) goto out_addrs; }bpf_prog_fill_jited_linfo (fp, addrs); +/*
arch/powerpc/net/bpf_jit_comp.c struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) · line 386
Quoted 10 lines
arch/powerpc/net/bpf_jit_comp.c +9
-0+* On ABI V1, executable code starts after the function +* descriptor, so adjust base accordingly. +*/ +#ifdef CONFIG_PPC64_ELF_ABI_V1 +bpf_prog_update_insn_ptrs (fp, addrs, + (void *)fimage +FUNCTION_DESCR_SIZE ); +#else +bpf_prog_update_insn_ptrs (fp, addrs, fimage); +#endif
You don't need this ifdeffery as FUNCTION_DESCR_SIZE is already defined based on this CONFIG option.
- Hari
PATCH v2 2/4 selftest/bpf: Enable instruction array test for powerpc64
In reply to [email protected]From: Abhishek Dubey <[email protected]>
With instruction array now supported, enable corresponding bpf selftest for powerpc.
--- tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c +1 -1
@@ -3,7 +3,7 @@#include <bpf/bpf.h> #include <test_progs.h> -#if defined(__x86_64__) || defined(__aarch64__) +#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__)static int map_create (__u32 map_type,__u32 max_entries) {const char *map_name ="insn_array" ;
Signature · 1 line
2.52.0
PATCH v2 3/4 powerpc64/bpf: Add support for indirect jump
In reply to [email protected]From: Abhishek Dubey <[email protected]>
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.
--- arch/powerpc/net/bpf_jit_comp64.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/powerpc/net/bpf_jit_comp64.c +8 -0
@@ -1627,6 +1627,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 */
Signature · 1 line
2.52.0
Re: [PATCH v2 3/4] powerpc64/bpf: Add support for indirect jump
Quoted 11 lines · On 27/02/26 7:13 am, [email protected] wrote:
From: Abhishek Dubey <[email protected]>
Add support for a new instruction
BPF_JMP|BPF_X|BPF_JA, SRC=0, DST=Rx, off=0, imm=0which 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.
Quoted 6 lines
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.
Looks good to me.
Quoted 24 lines
Signed-off-by Abhishek Dubey <[email protected]>--- arch/powerpc/net/bpf_jit_comp64.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/powerpc/net/bpf_jit_comp64.c +8
-0@@ -1627,6 +1627,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 */
PATCH v2 4/4 selftest/bpf: Enable gotox tests for powerpc64
In reply to [email protected]From: Abhishek Dubey <[email protected]>
With gotox instruction and jumptable now supported, enable corresponding bpf selftest on powerpc.
--- tools/testing/selftests/bpf/progs/verifier_gotox.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/verifier_gotox.c +2 -2
@@ -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";
Signature · 1 line
2.52.0
Quoted 60 lines · On 27 Feb 2026, at 7:13 AM, [email protected] wrote:
From: Abhishek Dubey <[email protected]>
The first 2 patch enable support for instruction array. Now, the instruction offset map maintain the mapping:
original inst -> xlated inst -> jited instThe last two patch enable support for indirect jump. Any eligile register can store jump target address for control flow to jump.
The features will be enabled on ppc32 in a separate series.
The patch series is rebased over:
https://lore.kernel.org/bpf/[email protected]All selftest related to instruction array and indirect jump are passing.
./test_progs-cpuv4 -n 20
#21/1Â Â Â bpf_insn_array/one2one:OK #21/2Â Â Â bpf_insn_array/simple:OK #21/3Â Â Â bpf_insn_array/deletions:OK #21/4Â Â Â bpf_insn_array/deletions-with-functions:OK #21/5Â Â Â bpf_insn_array/blindness:OK #21/6Â Â Â bpf_insn_array/incorrect-index:OK #21/7Â Â Â bpf_insn_array/load-unfrozen-map:OK #21/8Â Â Â bpf_insn_array/no-map-reuse:OK #21/9Â Â Â bpf_insn_array/bpf-side-ops:OK#21Â Â Â Â Â bpf_insn_array:OK
Summary: 1/9 PASSED, 0 SKIPPED, 0 FAILED./test_progs-cpuv4 -n 21
#20/1Â Â Â bpf_gotox/one-switch:OK #20/2Â Â Â bpf_gotox/one-switch-non-zero-sec-offset:OK #20/3Â Â Â bpf_gotox/two-switches:OK #20/4Â Â Â bpf_gotox/big-jump-table:OK #20/5Â Â Â bpf_gotox/static-global:OK #20/6Â Â Â bpf_gotox/nonstatic-global:OK #20/7Â Â Â bpf_gotox/other-sec:OK #20/8Â Â Â bpf_gotox/static-global-other-sec:OK #20/9Â Â Â bpf_gotox/nonstatic-global-other-sec:OK#20/10Â Â bpf_gotox/one-jump-two-maps:OK
#20/11Â Â bpf_gotox/one-map-two-jumps:OK
#20Â Â Â Â Â bpf_gotox:OK
Summary: 1/11 PASSED, 0 SKIPPED, 0 FAILED
v1->v2:
Handle image offset for ABIv1[v1]: https://lore.kernel.org/bpf/[email protected]
Abhishek Dubey (4):
powerpc64/bpf: Add support for instruction array selftest/bpf: Enable instruction array test for powerpc64 powerpc64/bpf: Add support for indirect jump selftest/bpf: Enable gotox tests for powerpc64
Quoted 8 lines
arch/powerpc/net/bpf_jit_comp.c | 10 ++++++++++ arch/powerpc/net/bpf_jit_comp64.c | 8 ++++++++ .../testing/selftests/bpf/prog_tests/bpf_insn_array.c | 2 +- tools/testing/selftests/bpf/progs/verifier_gotox.c | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-)Signature · 1 line
2.52.0
Tested this series and below are the results.
./test_progs-cpuv4 -n 21
#21/1 bpf_insn_array/one2one:OK #21/2 bpf_insn_array/simple:OK #21/3 bpf_insn_array/deletions:OK #21/4 bpf_insn_array/deletions-with-functions:OK #21/5 bpf_insn_array/blindness:OK #21/6 bpf_insn_array/incorrect-index:OK #21/7 bpf_insn_array/load-unfrozen-map:OK #21/8 bpf_insn_array/no-map-reuse:OK #21/9 bpf_insn_array/bpf-side-ops:OK #21 bpf_insn_array:OK
Summary: 1/9 PASSED, 0 SKIPPED, 0 FAILED
./test_progs-cpuv4 -n 20
#20/1 bpf_gotox/one-switch:SKIP #20/2 bpf_gotox/one-switch-non-zero-sec-offset:SKIP #20/3 bpf_gotox/two-switches:SKIP #20/4 bpf_gotox/big-jump-table:SKIP #20/5 bpf_gotox/static-global:SKIP #20/6 bpf_gotox/nonstatic-global:SKIP #20/7 bpf_gotox/other-sec:SKIP #20/8 bpf_gotox/static-global-other-sec:SKIP #20/9 bpf_gotox/nonstatic-global-other-sec:SKIP #20/10 bpf_gotox/one-jump-two-maps:SKIP #20/11 bpf_gotox/one-map-two-jumps:SKIP #20/12 bpf_gotox/check-ldimm64-off:SKIP #20/13 bpf_gotox/check-ldimm64-off-gotox:SKIP #20 bpf_gotox:SKIP
Summary: 1/0 PASSED, 13 SKIPPED, 0 FAILED
Regards,
Venkat.
Venkat Rao Bagalkote
Tested-byQuoted 59 lines · Venkat
Quoted 59 lines · On 27 Feb 2026, at 7:13 AM, [email protected] wrote:
From: Abhishek Dubey <[email protected]>
The first 2 patch enable support for instruction array. Now, the instruction offset map maintain the mapping:
original inst -> xlated inst -> jited instThe last two patch enable support for indirect jump. Any eligile register can store jump target address for control flow to jump.
The features will be enabled on ppc32 in a separate series.
The patch series is rebased over:
https://lore.kernel.org/bpf/[email protected]All selftest related to instruction array and indirect jump are passing.
./test_progs-cpuv4 -n 20
#21/1Â Â Â bpf_insn_array/one2one:OK #21/2Â Â Â bpf_insn_array/simple:OK #21/3Â Â Â bpf_insn_array/deletions:OK #21/4Â Â Â bpf_insn_array/deletions-with-functions:OK #21/5Â Â Â bpf_insn_array/blindness:OK #21/6Â Â Â bpf_insn_array/incorrect-index:OK #21/7Â Â Â bpf_insn_array/load-unfrozen-map:OK #21/8Â Â Â bpf_insn_array/no-map-reuse:OK #21/9Â Â Â bpf_insn_array/bpf-side-ops:OK#21Â Â Â Â Â bpf_insn_array:OK
Summary: 1/9 PASSED, 0 SKIPPED, 0 FAILED./test_progs-cpuv4 -n 21
#20/1Â Â Â bpf_gotox/one-switch:OK #20/2Â Â Â bpf_gotox/one-switch-non-zero-sec-offset:OK #20/3Â Â Â bpf_gotox/two-switches:OK #20/4Â Â Â bpf_gotox/big-jump-table:OK #20/5Â Â Â bpf_gotox/static-global:OK #20/6Â Â Â bpf_gotox/nonstatic-global:OK #20/7Â Â Â bpf_gotox/other-sec:OK #20/8Â Â Â bpf_gotox/static-global-other-sec:OK #20/9Â Â Â bpf_gotox/nonstatic-global-other-sec:OK#20/10Â Â bpf_gotox/one-jump-two-maps:OK
#20/11Â Â bpf_gotox/one-map-two-jumps:OK
#20Â Â Â Â Â bpf_gotox:OK
Summary: 1/11 PASSED, 0 SKIPPED, 0 FAILED
v1->v2:
Handle image offset for ABIv1[v1]: https://lore.kernel.org/bpf/[email protected]
Abhishek Dubey (4):
powerpc64/bpf: Add support for instruction array selftest/bpf: Enable instruction array test for powerpc64 powerpc64/bpf: Add support for indirect jump selftest/bpf: Enable gotox tests for powerpc64
Quoted 8 lines
Quoted 8 lines
arch/powerpc/net/bpf_jit_comp.c | 10 ++++++++++ arch/powerpc/net/bpf_jit_comp64.c | 8 ++++++++ .../testing/selftests/bpf/prog_tests/bpf_insn_array.c | 2 +- tools/testing/selftests/bpf/progs/verifier_gotox.c | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-)Signature · 1 line
2.52.0
Please ignore my last results. Refer the below.
# ./test_progs-cpuv4 -n 21 #21/1 bpf_insn_array/one2one:OK #21/2 bpf_insn_array/simple:OK #21/3 bpf_insn_array/deletions:OK #21/4 bpf_insn_array/deletions-with-functions:OK #21/5 bpf_insn_array/blindness:OK #21/6 bpf_insn_array/incorrect-index:OK #21/7 bpf_insn_array/load-unfrozen-map:OK #21/8 bpf_insn_array/no-map-reuse:OK #21/9 bpf_insn_array/bpf-side-ops:OK #21 bpf_insn_array:OK Summary: 1/9 PASSED, 0 SKIPPED, 0 FAILED
# ./test_progs-cpuv4 -n 20 #20/1 bpf_gotox/one-switch:OK #20/2 bpf_gotox/one-switch-non-zero-sec-offset:OK #20/3 bpf_gotox/two-switches:OK #20/4 bpf_gotox/big-jump-table:OK #20/5 bpf_gotox/static-global:OK #20/6 bpf_gotox/nonstatic-global:OK #20/7 bpf_gotox/other-sec:OK #20/8 bpf_gotox/static-global-other-sec:OK #20/9 bpf_gotox/nonstatic-global-other-sec:OK #20/10 bpf_gotox/one-jump-two-maps:OK #20/11 bpf_gotox/one-map-two-jumps:OK #20/12 bpf_gotox/check-ldimm64-off:OK #20/13 bpf_gotox/check-ldimm64-off-gotox:OK #20 bpf_gotox:OK Summary: 1/13 PASSED, 0 SKIPPED, 0 FAILED
Regards,
Venkat.
Quoted 39 lines
Tested-by Venkat Rao Bagalkote <[email protected]>Tested this series and below are the results.
./test_progs-cpuv4 -n 21
#21/1 bpf_insn_array/one2one:OK #21/2 bpf_insn_array/simple:OK #21/3 bpf_insn_array/deletions:OK #21/4 bpf_insn_array/deletions-with-functions:OK #21/5 bpf_insn_array/blindness:OK #21/6 bpf_insn_array/incorrect-index:OK #21/7 bpf_insn_array/load-unfrozen-map:OK #21/8 bpf_insn_array/no-map-reuse:OK #21/9 bpf_insn_array/bpf-side-ops:OK #21 bpf_insn_array:OKSummary: 1/9 PASSED, 0 SKIPPED, 0 FAILED
./test_progs-cpuv4 -n 20
#20/1 bpf_gotox/one-switch:SKIP #20/2 bpf_gotox/one-switch-non-zero-sec-offset:SKIP #20/3 bpf_gotox/two-switches:SKIP #20/4 bpf_gotox/big-jump-table:SKIP #20/5 bpf_gotox/static-global:SKIP #20/6 bpf_gotox/nonstatic-global:SKIP #20/7 bpf_gotox/other-sec:SKIP #20/8 bpf_gotox/static-global-other-sec:SKIP #20/9 bpf_gotox/nonstatic-global-other-sec:SKIP #20/10 bpf_gotox/one-jump-two-maps:SKIP #20/11 bpf_gotox/one-map-two-jumps:SKIP #20/12 bpf_gotox/check-ldimm64-off:SKIP #20/13 bpf_gotox/check-ldimm64-off-gotox:SKIP #20 bpf_gotox:SKIPSummary: 1/0 PASSED, 13 SKIPPED, 0 FAILED
Regards,
Venkat.