]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
powerpc64/bpf: Add support for indirect jump
authorAbhishek Dubey <adubey@linux.ibm.com>
Wed, 1 Apr 2026 15:21:32 +0000 (11:21 -0400)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Fri, 3 Apr 2026 08:44:25 +0000 (14:14 +0530)
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>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20260401152133.42544-4-adubey@linux.ibm.com
arch/powerpc/net/bpf_jit_comp64.c

index d9038c468af6ec996a6e12785d2ffb8b9e2c39b9..db364d9083e7255019344067177c9eb3b53a89b4 100644 (file)
@@ -1708,6 +1708,14 @@ emit_clear:
                        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
                 */