Skip to content

Commit 51c66ad

Browse files
chleroympe
authored andcommitted
powerpc/bpf: Implement extended BPF on PPC32
Implement Extended Berkeley Packet Filter on Powerpc 32 Test result with test_bpf module: test_bpf: Summary: 378 PASSED, 0 FAILED, [354/366 JIT'ed] Registers mapping: [BPF_REG_0] = r11-r12 /* function arguments */ [BPF_REG_1] = r3-r4 [BPF_REG_2] = r5-r6 [BPF_REG_3] = r7-r8 [BPF_REG_4] = r9-r10 [BPF_REG_5] = r21-r22 (Args 9 and 10 come in via the stack) /* non volatile registers */ [BPF_REG_6] = r23-r24 [BPF_REG_7] = r25-r26 [BPF_REG_8] = r27-r28 [BPF_REG_9] = r29-r30 /* frame pointer aka BPF_REG_10 */ [BPF_REG_FP] = r17-r18 /* eBPF jit internal registers */ [BPF_REG_AX] = r19-r20 [TMP_REG] = r31 As PPC32 doesn't have a redzone in the stack, a stack frame must always be set in order to host at least the tail count counter. The stack frame remains for tail calls, it is set by the first callee and freed by the last callee. r0 is used as temporary register as much as possible. It is referenced directly in the code in order to avoid misusing it, because some instructions interpret it as value 0 instead of register r0 (ex: addi, addis, stw, lwz, ...) The following operations are not implemented: case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */ case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */ case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += src */ The following operations are only implemented for power of two constants: case BPF_ALU64 | BPF_MOD | BPF_K: /* dst %= imm */ case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */ Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/61d8b149176ddf99e7d5cef0b6dc1598583ca202.1616430991.git.christophe.leroy@csgroup.eu
1 parent 355a8d2 commit 51c66ad

File tree

5 files changed

+1076
-3
lines changed

5 files changed

+1076
-3
lines changed

Documentation/admin-guide/sysctl/net.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ two flavors of JITs, the newer eBPF JIT currently supported on:
6464
- arm64
6565
- arm32
6666
- ppc64
67+
- ppc32
6768
- sparc64
6869
- mips64
6970
- s390x
@@ -73,7 +74,6 @@ two flavors of JITs, the newer eBPF JIT currently supported on:
7374
And the older cBPF JIT supported on the following archs:
7475

7576
- mips
76-
- ppc
7777
- sparc
7878

7979
eBPF JITs are a superset of cBPF JITs, meaning the kernel will

arch/powerpc/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ config PPC
202202
select HAVE_DEBUG_STACKOVERFLOW
203203
select HAVE_DYNAMIC_FTRACE
204204
select HAVE_DYNAMIC_FTRACE_WITH_REGS if MPROFILE_KERNEL
205-
select HAVE_EBPF_JIT if PPC64
205+
select HAVE_EBPF_JIT
206206
select HAVE_EFFICIENT_UNALIGNED_ACCESS if !(CPU_LITTLE_ENDIAN && POWER7_CPU)
207207
select HAVE_FAST_GUP
208208
select HAVE_FTRACE_MCOUNT_RECORD

arch/powerpc/net/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
#
33
# Arch-specific network modules
44
#
5-
obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_jit_comp64.o
5+
obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_jit_comp$(BITS).o

arch/powerpc/net/bpf_jit.h

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
EMIT(PPC_RAW_ORI(d, d, IMM_L(i))); \
4343
} } while(0)
4444

45+
#ifdef CONFIG_PPC32
46+
#define PPC_EX32(r, i) EMIT(PPC_RAW_LI((r), (i) < 0 ? -1 : 0))
47+
#endif
48+
4549
#define PPC_LI64(d, i) do { \
4650
if ((long)(i) >= -2147483648 && \
4751
(long)(i) < 2147483648) \

0 commit comments

Comments
 (0)