eBPF JIT for PPC64
Subsystems (5)
cover eBPF JIT for PPC64
Implement extended BPF JIT for ppc64. We retain the classic BPF JIT for ppc32 and move ppc64 BE/LE to use the new JIT. Classic BPF filters will be converted to extended BPF (see convert_filter()) and JIT'ed with the new compiler.
Most of the existing macros are retained and fixed/enhanced where appropriate. Patches 1-4 are geared towards this.
Patch 5 breaks out the classic BPF JIT specifics into a separate bpf_jit32.h header file, while retaining all the generic instruction macros in bpf_jit.h. Most of these macros can potentially be generalized and moved to more common code (tagged with a TODO in patch 6).
Patch 6 implements eBPF JIT for ppc64.
This is still *early* *RFC* and there are still a few instruction classes to be JIT'ed. I am posting this in advance so as to get early feedback. Kindly review the same and if possible, try it out and let me know how it goes!
- Naveen
Naveen N. Rao (6):
ppc: bpf/jit: Fix/enhance 32-bit Load Immediate implementation
ppc: bpf/jit: Optimize 64-bit Immediate loads
ppc: bpf/jit: Introduce rotate immediate instructions
ppc: bpf/jit: A few cleanups
ppc: bpf/jit: Isolate classic BPF JIT specifics into a separate header
ppc: ebpf/jit: Implement JIT compiler for extended BPF
arch/powerpc/include/asm/ppc-opcode.h | 21 +- arch/powerpc/net/Makefile | 4 + arch/powerpc/net/bpf_jit.h | 251 +++++------ arch/powerpc/net/bpf_jit32.h | 140 ++++++ arch/powerpc/net/bpf_jit64.h | 58 +++ arch/powerpc/net/bpf_jit_asm.S | 2 +- arch/powerpc/net/bpf_jit_comp.c | 10 +- arch/powerpc/net/bpf_jit_comp64.c | 828 ++++++++++++++++++++++++++++++++++ 8 files changed, 1163 insertions(+), 151 deletions(-) create mode 100644 arch/powerpc/net/bpf_jit32.h create mode 100644 arch/powerpc/net/bpf_jit64.h create mode 100644 arch/powerpc/net/bpf_jit_comp64.c
Signature · 1 line
2.7.4
RFC PATCH 1/6 ppc: bpf/jit: Fix/enhance 32-bit Load Immediate implementation
The existing LI32() macro can sometimes result in a sign-extended 32-bit load that does not clear the top 32-bits properly. As an example, loading 0x7fffffff results in the register containing 0xffffffff7fffffff. While this does not impact classic BPF JIT implementation (since that only uses the lower word for all operations), we would like to share this macro between classic BPF JIT and extended BPF JIT, wherein the entire 64-bit value in the register matters. Fix this by first doing a shifted LI followed by ORI.
An additional optimization is with loading values between -32768 to -1, where we now only need a single LI.
The new implementation now generates the same or less number of instructions.
--- arch/powerpc/net/bpf_jit.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
arch/powerpc/net/bpf_jit.h +10 -3
@@ -232,10 +232,17 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh); (((cond) & 0x3ff) << 16) | \ (((dest) - (ctx->idx * 4)) & \ 0xfffc)) -#define PPC_LI32 (d, i) do { PPC_LI(d, IMM_L(i)); \ - if ((u32)(uintptr_t)(i) >= 32768) { \ - PPC_ADDIS(d, d, IMM_HA(i)); \ +/* Sign-extended 32-bit immediate load */ +#define PPC_LI32 (d, i) do { \ + if ((int)(uintptr_t)(i) >= -32768 && \ + (int)(uintptr_t)(i) < 32768) \ + PPC_LI(d, i); \ + else { \ + PPC_LIS(d, IMM_H(i)); \ + if (IMM_L(i)) \ + PPC_ORI(d, d, IMM_L(i)); \ } } while(0) +#define PPC_LI64 (d, i) do { \ if (!((uintptr_t)(i) & 0xffffffff00000000ULL)) \ PPC_LI32(d, i); \
Signature · 1 line
2.7.4
RFC PATCH 2/6 ppc: bpf/jit: Optimize 64-bit Immediate loads
In reply to Naveen N. RaoSimilar to the LI32() optimization, if the value can be represented in 32-bits, use LI32(). Also handle loading a few specific forms of immediate values in an optimum manner.
While at it, remove the semicolon at the end of the macro!
--- arch/powerpc/net/bpf_jit.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
arch/powerpc/net/bpf_jit.h +11 -6
@@ -244,20 +244,25 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh); } } while(0)#define PPC_LI64 (d, i) do { \ - if (!((uintptr_t)(i) & 0xffffffff00000000ULL)) \ + if ((long)(i) >= -2147483648 && \ + (long)(i) < 2147483648) \ PPC_LI32(d, i); \ else { \ - PPC_LIS(d, ((uintptr_t)(i) >> 48)); \ - if ((uintptr_t)(i) & 0x0000ffff00000000ULL) \ - PPC_ORI(d, d, \ - ((uintptr_t)(i) >> 32) & 0xffff); \ + if (!((uintptr_t)(i) & 0xffff800000000000ULL)) \ + PPC_LI(d, ((uintptr_t)(i) >> 32) & 0xffff); \ + else { \ + PPC_LIS(d, ((uintptr_t)(i) >> 48)); \ + if ((uintptr_t)(i) & 0x0000ffff00000000ULL) \ + PPC_ORI(d, d, \ + ((uintptr_t)(i) >> 32) & 0xffff); \ + } \ PPC_SLDI(d, d, 32); \ if ((uintptr_t)(i) & 0x00000000ffff0000ULL) \ PPC_ORIS(d, d, \ ((uintptr_t)(i) >> 16) & 0xffff); \ if ((uintptr_t)(i) & 0x000000000000ffffULL) \ PPC_ORI(d, d, (uintptr_t)(i) & 0xffff); \ - } } while (0); + } } while (0)#ifdef CONFIG_PPC64 #define PPC_FUNC_ADDR (d,i) do { PPC_LI64(d, i); } while(0)
Signature · 1 line
2.7.4
RFC PATCH 3/6 ppc: bpf/jit: Introduce rotate immediate instructions
In reply to Naveen N. RaoSince we will be using the rotate immediate instructions for extended BPF JIT, let's introduce macros for the same. And since the shift immediate operations use the rotate immediate instructions, let's redo those macros to use the newly introduced instructions.
--- arch/powerpc/include/asm/ppc-opcode.h | 2 ++ arch/powerpc/net/bpf_jit.h | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/ppc-opcode.h +2 -0
@@ -271,6 +271,8 @@#define __PPC_SH (s) __PPC_WS(s)#define __PPC_MB (s) (((s) & 0x1f) << 6)#define __PPC_ME (s) (((s) & 0x1f) << 1) +#define __PPC_MB64 (s) (__PPC_MB(s) | ((s) & 0x20)) +#define __PPC_ME64 (s) __PPC_MB64(s)#define __PPC_BI (s) (((s) & 0x1f) << 16)#define __PPC_CT (t) (((t) & 0x0f) << 21)
arch/powerpc/net/bpf_jit.h +11 -9
@@ -210,18 +210,20 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh); ___PPC_RS(a) | ___PPC_RB(s))#define PPC_SRW (d, a, s) EMIT(PPC_INST_SRW | ___PPC_RA(d) | \ ___PPC_RS(a) | ___PPC_RB(s)) +#define PPC_RLWINM (d, a, i, mb, me) EMIT(PPC_INST_RLWINM | ___PPC_RA(d) | \ + ___PPC_RS(a) | __PPC_SH(i) | \ + __PPC_MB(mb) | __PPC_ME(me)) +#define PPC_RLDICR (d, a, i, me) EMIT(PPC_INST_RLDICR | ___PPC_RA(d) | \ + ___PPC_RS(a) | __PPC_SH(i) | \ + __PPC_ME64(me) | (((i) & 0x20) >> 4)) +/* slwi = rlwinm Rx, Ry, n, 0, 31-n */ -#define PPC_SLWI (d, a, i) EMIT(PPC_INST_RLWINM | ___PPC_RA(d) | \ - ___PPC_RS(a) | __PPC_SH(i) | \ - __PPC_MB(0) | __PPC_ME(31-(i))) +#define PPC_SLWI (d, a, i) PPC_RLWINM(d, a, i, 0, 31-(i))/* srwi = rlwinm Rx, Ry, 32-n, n, 31 */ -#define PPC_SRWI (d, a, i) EMIT(PPC_INST_RLWINM | ___PPC_RA(d) | \ - ___PPC_RS(a) | __PPC_SH(32-(i)) | \ - __PPC_MB(i) | __PPC_ME(31)) +#define PPC_SRWI (d, a, i) PPC_RLWINM(d, a, 32-(i), i, 31)/* sldi = rldicr Rx, Ry, n, 63-n */ -#define PPC_SLDI (d, a, i) EMIT(PPC_INST_RLDICR | ___PPC_RA(d) | \ - ___PPC_RS(a) | __PPC_SH(i) | \ - __PPC_MB(63-(i)) | (((i) & 0x20) >> 4)) +#define PPC_SLDI (d, a, i) PPC_RLDICR(d, a, i, 63-(i)) +#define PPC_NEG (d, a) EMIT(PPC_INST_NEG | ___PPC_RT(d) | ___PPC_RA(a))/* Long jump; (unconditional 'branch') */
Signature · 1 line
2.7.4
RFC PATCH 4/6 ppc: bpf/jit: A few cleanups
In reply to Naveen N. Rao1. Per the ISA, ADDIS actually uses RT, rather than RS. Though the result is the same, make the usage clear.
2. The multiply instruction used is a 32-bit multiply. Rename PPC_MUL() to PPC_MULW() to make the same clear.
3. PPC_STW[U] take the entire 16-bit immediate value and do not require word-alignment, per the ISA. Change the macros to use IMM_L().
4. A few white-space cleanups to satisfy checkpatch.pl.
--- arch/powerpc/net/bpf_jit.h | 13 +++++++------ arch/powerpc/net/bpf_jit_comp.c | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-)
arch/powerpc/net/bpf_jit.h +7 -6
@@ -83,7 +83,7 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);*/ #define IMM_H (i) ((uintptr_t)(i)>>16)#define IMM_HA (i) (((uintptr_t)(i)>>16) + \ - (((uintptr_t)(i) & 0x8000) >> 15)) + (((uintptr_t)(i) & 0x8000) >> 15))#define IMM_L (i) ((uintptr_t)(i) & 0xffff)#define PLANT_INSTR (d, idx, instr) \
@@ -99,16 +99,16 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);#define PPC_MR (d, a) PPC_OR(d, a, a)#define PPC_LI (r, i) PPC_ADDI(r, 0, i)#define PPC_ADDIS (d, a, i) EMIT(PPC_INST_ADDIS | \ - ___PPC_RS(d) | ___PPC_RA(a) | IMM_L(i)) + ___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i))#define PPC_LIS (r, i) PPC_ADDIS(r, 0, i)#define PPC_STD (r, base, i) EMIT(PPC_INST_STD | ___PPC_RS(r) | \ ___PPC_RA(base) | ((i) & 0xfffc))#define PPC_STDU (r, base, i) EMIT(PPC_INST_STDU | ___PPC_RS(r) | \ ___PPC_RA(base) | ((i) & 0xfffc))#define PPC_STW (r, base, i) EMIT(PPC_INST_STW | ___PPC_RS(r) | \ - ___PPC_RA(base) | ((i) & 0xfffc)) + ___PPC_RA(base) | IMM_L(i))#define PPC_STWU (r, base, i) EMIT(PPC_INST_STWU | ___PPC_RS(r) | \ - ___PPC_RA(base) | ((i) & 0xfffc)) + ___PPC_RA(base) | IMM_L(i))#define PPC_LBZ (r, base, i) EMIT(PPC_INST_LBZ | ___PPC_RT(r) | \ ___PPC_RA(base) | IMM_L(i))
@@ -174,13 +174,14 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);#define PPC_CMPWI (a, i) EMIT(PPC_INST_CMPWI | ___PPC_RA(a) | IMM_L(i))#define PPC_CMPDI (a, i) EMIT(PPC_INST_CMPDI | ___PPC_RA(a) | IMM_L(i))#define PPC_CMPLWI (a, i) EMIT(PPC_INST_CMPLWI | ___PPC_RA(a) | IMM_L(i)) -#define PPC_CMPLW (a, b) EMIT(PPC_INST_CMPLW | ___PPC_RA(a) | ___PPC_RB(b)) +#define PPC_CMPLW (a, b) EMIT(PPC_INST_CMPLW | ___PPC_RA(a) | \ + ___PPC_RB(b))#define PPC_SUB (d, a, b) EMIT(PPC_INST_SUB | ___PPC_RT(d) | \ ___PPC_RB(a) | ___PPC_RA(b))#define PPC_ADD (d, a, b) EMIT(PPC_INST_ADD | ___PPC_RT(d) | \ ___PPC_RA(a) | ___PPC_RB(b)) -#define PPC_MUL (d, a, b) EMIT(PPC_INST_MULLW | ___PPC_RT(d) | \ +#define PPC_MULW (d, a, b) EMIT(PPC_INST_MULLW | ___PPC_RT(d) | \ ___PPC_RA(a) | ___PPC_RB(b))#define PPC_MULHWU (d, a, b) EMIT(PPC_INST_MULHWU | ___PPC_RT(d) | \ ___PPC_RA(a) | ___PPC_RB(b))
arch/powerpc/net/bpf_jit_comp.c +4 -4
@@ -161,14 +161,14 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,break ;case BPF_ALU |BPF_MUL |BPF_X :/* A *= X; */ ctx->seen |=SEEN_XREG ; -PPC_MUL (r_A, r_A, r_X); +PPC_MULW (r_A, r_A, r_X);break ;case BPF_ALU |BPF_MUL |BPF_K :/* A *= K */ if (K <32768 )PPC_MULI (r_A, r_A,K );else {PPC_LI32 (r_scratch1,K ); -PPC_MUL (r_A, r_A, r_scratch1); +PPC_MULW (r_A, r_A, r_scratch1); }break ;case BPF_ALU |BPF_MOD |BPF_X :/* A %= X; */
@@ -184,7 +184,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, }if (code == (BPF_ALU |BPF_MOD |BPF_X )) {PPC_DIVWU (r_scratch1, r_A, r_X); -PPC_MUL (r_scratch1, r_X, r_scratch1); +PPC_MULW (r_scratch1, r_X, r_scratch1);PPC_SUB (r_A, r_A, r_scratch1); }else {PPC_DIVWU (r_A, r_A, r_X);
@@ -193,7 +193,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,case BPF_ALU |BPF_MOD |BPF_K :/* A %= K; */ PPC_LI32 (r_scratch2,K );PPC_DIVWU (r_scratch1, r_A, r_scratch2); -PPC_MUL (r_scratch1, r_scratch2, r_scratch1); +PPC_MULW (r_scratch1, r_scratch2, r_scratch1);PPC_SUB (r_A, r_A, r_scratch1);break ;case BPF_ALU |BPF_DIV |BPF_K :/* A /= K */
Signature · 1 line
2.7.4
RFC PATCH 5/6 ppc: bpf/jit: Isolate classic BPF JIT specifics into a separate header
In reply to Naveen N. RaoBreak out classic BPF JIT specifics into a separate header in preparation for eBPF JIT implementation. Note that ppc32 will still need the classic BPF JIT.
--- arch/powerpc/net/bpf_jit.h | 122 +--------------------------------- arch/powerpc/net/bpf_jit32.h | 140 ++++++++++++++++++++++++++++++++++++++++ arch/powerpc/net/bpf_jit_asm.S | 2 +- arch/powerpc/net/bpf_jit_comp.c | 2 +- 4 files changed, 145 insertions(+), 121 deletions(-) create mode 100644 arch/powerpc/net/bpf_jit32.h
arch/powerpc/net/bpf_jit.h +3 -119
@@ -1,6 +1,8 @@ -/* bpf_jit.h: BPF JIT compiler for PPC64 +/* +* bpf_jit.h: BPF JIT compiler for PPC * * Copyright 2011 Matt Evans <[email protected]>, IBM Corporation +* 2016 Naveen N. Rao <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License
@@ -10,66 +12,8 @@#ifndef _BPF_JIT_H#define _BPF_JIT_H -#ifdef CONFIG_PPC64 -#define BPF_PPC_STACK_R3_OFF 48 -#define BPF_PPC_STACK_LOCALS 32 -#define BPF_PPC_STACK_BASIC (48+64) -#define BPF_PPC_STACK_SAVE (18*8) -#define BPF_PPC_STACKFRAME (BPF_PPC_STACK_BASIC+BPF_PPC_STACK_LOCALS+ \ - BPF_PPC_STACK_SAVE) -#define BPF_PPC_SLOWPATH_FRAME (48+64) -#else -#define BPF_PPC_STACK_R3_OFF 24 -#define BPF_PPC_STACK_LOCALS 16 -#define BPF_PPC_STACK_BASIC (24+32) -#define BPF_PPC_STACK_SAVE (18*4) -#define BPF_PPC_STACKFRAME (BPF_PPC_STACK_BASIC+BPF_PPC_STACK_LOCALS+ \ - BPF_PPC_STACK_SAVE) -#define BPF_PPC_SLOWPATH_FRAME (24+32) -#endif - -#define REG_SZ (BITS_PER_LONG/8) - -/* -* Generated code register usage: -* -* As normal PPC C ABI (e.g. r1=sp, r2=TOC), with: -* -* skb r3 (Entry parameter) -* A register r4 -* X register r5 -* addr param r6 -* r7-r10 scratch -* skb->data r14 -* skb headlen r15 (skb->len - skb->data_len) -* m[0] r16 -* m[...] ... -* m[15] r31 -*/ -#define r_skb 3 -#define r_ret 3 -#define r_A 4 -#define r_X 5 -#define r_addr 6 -#define r_scratch1 7 -#define r_scratch2 8 -#define r_D 14 -#define r_HL 15 -#define r_M 16 -#ifndef __ASSEMBLY__ -/* -* Assembly helpers from arch/powerpc/net/bpf_jit.S: -*/ -#define DECLARE_LOAD_FUNC (func) \ - extern u8 func[], func##_negative_offset[], func##_positive_offset[] - -DECLARE_LOAD_FUNC (sk_load_word); -DECLARE_LOAD_FUNC (sk_load_half); -DECLARE_LOAD_FUNC (sk_load_byte); -DECLARE_LOAD_FUNC (sk_load_byte_msh); -#ifdef CONFIG_PPC64 #define FUNCTION_DESCR_SIZE 24#else
@@ -131,46 +75,6 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);#define PPC_BPF_STLU (r, base, i) do { PPC_STWU(r, base, i); } while(0)#endif -/* Convenience helpers for the above with 'far' offsets: */ -#define PPC_LBZ_OFFS (r, base, i) do { if ((i) < 32768) PPC_LBZ(r, base, i); \ - else { PPC_ADDIS(r, base, IMM_HA(i)); \ - PPC_LBZ(r, r, IMM_L(i)); } } while(0) - -#define PPC_LD_OFFS (r, base, i) do { if ((i) < 32768) PPC_LD(r, base, i); \ - else { PPC_ADDIS(r, base, IMM_HA(i)); \ - PPC_LD(r, r, IMM_L(i)); } } while(0) - -#define PPC_LWZ_OFFS (r, base, i) do { if ((i) < 32768) PPC_LWZ(r, base, i); \ - else { PPC_ADDIS(r, base, IMM_HA(i)); \ - PPC_LWZ(r, r, IMM_L(i)); } } while(0) - -#define PPC_LHZ_OFFS (r, base, i) do { if ((i) < 32768) PPC_LHZ(r, base, i); \ - else { PPC_ADDIS(r, base, IMM_HA(i)); \ - PPC_LHZ(r, r, IMM_L(i)); } } while(0) - -#ifdef CONFIG_PPC64 -#define PPC_LL_OFFS (r, base, i) do { PPC_LD_OFFS(r, base, i); } while(0) -#else -#define PPC_LL_OFFS (r, base, i) do { PPC_LWZ_OFFS(r, base, i); } while(0) -#endif - -#ifdef CONFIG_SMP -#ifdef CONFIG_PPC64 -#define PPC_BPF_LOAD_CPU (r) \ - do { BUILD_BUG_ON(FIELD_SIZEOF(struct paca_struct, paca_index) != 2); \ - PPC_LHZ_OFFS(r, 13, offsetof(struct paca_struct, paca_index)); \ - } while (0) -#else -#define PPC_BPF_LOAD_CPU (r) \ - do { BUILD_BUG_ON(FIELD_SIZEOF(struct thread_info, cpu) != 4); \ - PPC_LHZ_OFFS(r, (1 & ~(THREAD_SIZE - 1)), \ - offsetof(struct thread_info, cpu)); \ - } while(0) -#endif -#else -#define PPC_BPF_LOAD_CPU (r) do { PPC_LI(r, 0); } while(0) -#endif -#define PPC_CMPWI (a, i) EMIT(PPC_INST_CMPWI | ___PPC_RA(a) | IMM_L(i))#define PPC_CMPDI (a, i) EMIT(PPC_INST_CMPDI | ___PPC_RA(a) | IMM_L(i))#define PPC_CMPLWI (a, i) EMIT(PPC_INST_CMPLWI | ___PPC_RA(a) | IMM_L(i))
@@ -273,14 +177,6 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);#define PPC_FUNC_ADDR (d,i) do { PPC_LI32(d, i); } while(0)#endif -#define PPC_LHBRX_OFFS (r, base, i) \ - do { PPC_LI32(r, i); PPC_LHBRX(r, r, base); } while(0) -#ifdef __LITTLE_ENDIAN__ -#define PPC_NTOHS_OFFS (r, base, i) PPC_LHBRX_OFFS(r, base, i) -#else -#define PPC_NTOHS_OFFS (r, base, i) PPC_LHZ_OFFS(r, base, i) -#endif -static inline bool is_nearbranch (int offset) {return (offset <32768 ) && (offset >=-32768 );
@@ -317,18 +213,6 @@ static inline bool is_nearbranch(int offset)#define COND_NE (CR0_EQ | COND_CMP_FALSE)#define COND_LT (CR0_LT | COND_CMP_TRUE) -#define SEEN_DATAREF 0x10000/* might call external helpers */ -#define SEEN_XREG 0x20000/* X reg is used */ -#define SEEN_MEM 0x40000/* SEEN_MEM+(1<<n) = use mem[n] for temporary -* storage */ -#define SEEN_MEM_MSK 0x0ffff - -struct codegen_context { -unsigned int seen; -unsigned int idx; -int pc_ret0;/* bpf index of first RET #0 instruction (if any) */ -}; -#endif #endif
arch/powerpc/net/bpf_jit32.h new file +140 -0
140 lines not on this page · raw message
arch/powerpc/net/bpf_jit_asm.S +1 -1
@@ -10,7 +10,7 @@ */ #include <asm/ppc_asm.h> -#include "bpf_jit.h" +#include "bpf_jit32.h" /* * All of these routines are called directly from generated code,
arch/powerpc/net/bpf_jit_comp.c +1 -1
@@ -16,7 +16,7 @@#include <linux/filter.h> #include <linux/if_vlan.h> -#include "bpf_jit.h" +#include "bpf_jit32.h" int bpf_jit_enable__read_mostly ;
Signature · 1 line
2.7.4
RFC PATCH 6/6 ppc: ebpf/jit: Implement JIT compiler for extended BPF
In reply to Naveen N. RaoPPC64 eBPF JIT compiler. Works for both ABIv1 and ABIv2.
Enable with:
echo 1 > /proc/sys/net/core/bpf_jit_enable
or
echo 2 > /proc/sys/net/core/bpf_jit_enable
... to see the generated JIT code. This can further be processed with tools/net/bpf_jit_disasm.
With CONFIG_TEST_BPF=m and 'modprobe test_bpf':test_bpf: Summary: 291 PASSED, 0 FAILED, [234/283 JIT'ed]
... on both ppc64 BE and LE.
The details of the approach are documented through various comments in the code, as are the TODOs. Some of the prominent TODOs include implementing BPF tail calls and skb loads.
--- arch/powerpc/include/asm/ppc-opcode.h | 19 +- arch/powerpc/net/Makefile | 4 + arch/powerpc/net/bpf_jit.h | 66 ++- arch/powerpc/net/bpf_jit64.h | 58 +++ arch/powerpc/net/bpf_jit_comp64.c | 828 ++++++++++++++++++++++++++++++++++ 5 files changed, 973 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/net/bpf_jit64.h create mode 100644 arch/powerpc/net/bpf_jit_comp64.c
arch/powerpc/include/asm/ppc-opcode.h +18 -1
@@ -141,9 +141,11 @@#define PPC_INST_ISEL 0x7c00001e#define PPC_INST_ISEL_MASK 0xfc00003e#define PPC_INST_LDARX 0x7c0000a8 +#define PPC_INST_STDCX 0x7c0001ad#define PPC_INST_LSWI 0x7c0004aa#define PPC_INST_LSWX 0x7c00042a#define PPC_INST_LWARX 0x7c000028 +#define PPC_INST_STWCX 0x7c00012d#define PPC_INST_LWSYNC 0x7c2004ac#define PPC_INST_SYNC 0x7c0004ac#define PPC_INST_SYNC_MASK 0xfc0007fe
@@ -210,8 +212,11 @@#define PPC_INST_LBZ 0x88000000#define PPC_INST_LD 0xe8000000#define PPC_INST_LHZ 0xa0000000 -#define PPC_INST_LHBRX 0x7c00062c#define PPC_INST_LWZ 0x80000000 +#define PPC_INST_LHBRX 0x7c00062c +#define PPC_INST_LDBRX 0x7c000428 +#define PPC_INST_STB 0x98000000 +#define PPC_INST_STH 0xb0000000#define PPC_INST_STD 0xf8000000#define PPC_INST_STDU 0xf8000001#define PPC_INST_STW 0x90000000
@@ -220,22 +225,34 @@#define PPC_INST_MTLR 0x7c0803a6#define PPC_INST_CMPWI 0x2c000000#define PPC_INST_CMPDI 0x2c200000 +#define PPC_INST_CMPW 0x7c000000 +#define PPC_INST_CMPD 0x7c200000#define PPC_INST_CMPLW 0x7c000040 +#define PPC_INST_CMPLD 0x7c200040#define PPC_INST_CMPLWI 0x28000000 +#define PPC_INST_CMPLDI 0x28200000#define PPC_INST_ADDI 0x38000000#define PPC_INST_ADDIS 0x3c000000#define PPC_INST_ADD 0x7c000214#define PPC_INST_SUB 0x7c000050#define PPC_INST_BLR 0x4e800020#define PPC_INST_BLRL 0x4e800021 +#define PPC_INST_MULLD 0x7c0001d2#define PPC_INST_MULLW 0x7c0001d6#define PPC_INST_MULHWU 0x7c000016#define PPC_INST_MULLI 0x1c000000#define PPC_INST_DIVWU 0x7c000396 +#define PPC_INST_DIVD 0x7c0003d2#define PPC_INST_RLWINM 0x54000000 +#define PPC_INST_RLWIMI 0x50000000 +#define PPC_INST_RLDICL 0x78000000#define PPC_INST_RLDICR 0x78000004#define PPC_INST_SLW 0x7c000030 +#define PPC_INST_SLD 0x7c000036#define PPC_INST_SRW 0x7c000430 +#define PPC_INST_SRD 0x7c000436 +#define PPC_INST_SRAD 0x7c000634 +#define PPC_INST_SRADI 0x7c000674#define PPC_INST_AND 0x7c000038#define PPC_INST_ANDDOT 0x7c000039#define PPC_INST_OR 0x7c000378
arch/powerpc/net/Makefile +4 -0
@@ -1,4 +1,8 @@ # # Arch-specific network modules # +ifeq ($(CONFIG_PPC64),y) +obj-$(CONFIG_BPF_JIT) += bpf_jit_comp64.o +else obj-$(CONFIG_BPF_JIT) += bpf_jit_asm.o bpf_jit_comp.o +endif
arch/powerpc/net/bpf_jit.h +65 -1
127 lines not on this page · raw message
arch/powerpc/net/bpf_jit64.h new file +58 -0
58 lines not on this page · raw message
arch/powerpc/net/bpf_jit_comp64.c new file +828 -0
828 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH 6/6] ppc: ebpf/jit: Implement JIT compiler for extended BPF
Quoted 35 lines · Naveen N. Rao
PPC64 eBPF JIT compiler. Works for both ABIv1 and ABIv2.
Enable with:
echo 1 >/proc/sys/net/core/bpf_jit_enable
or
echo 2 >/proc/sys/net/core/bpf_jit_enable... to see the generated JIT code. This can further be processed with
tools/net/bpf_jit_disasm.With
CONFIG_TEST_BPF=mand 'modprobetest_bpf':test_bpf: Summary: 291 PASSED, 0 FAILED, [234/283 JIT'ed]... on both ppc64 BE and LE.
The details of the approach are documented through various comments in the code, as are the TODOs. Some of the prominent TODOs include implementing BPF tail calls and skb loads.
Cc Matt Evans <[email protected]>Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc "David S. Miller" <[email protected]>Cc Ananth N Mavinakayanahalli <[email protected]>Signed-off-by Naveen N. Rao <[email protected]>--- arch/powerpc/include/asm/ppc-opcode.h | 19 +- arch/powerpc/net/Makefile | 4 + arch/powerpc/net/bpf_jit.h | 66 ++- arch/powerpc/net/bpf_jit64.h | 58 +++ arch/powerpc/net/bpf_jit_comp64.c | 828 ++++++++++++++++++++++++++++++++++ 5 files changed, 973 insertions(+), 2 deletions(-)create mode 100644
arch/powerpc/net/bpf_jit64.hcreate mode 100644arch/powerpc/net/bpf_jit_comp64.c
...
arch/powerpc/net/bpf_jit.h line 17
Quoted 2 lines
arch/powerpc/net/bpf_jit.h +1
-1-#ifdef CONFIG_PPC64 +#if defined(CONFIG_PPC64 ) && (!defined(_CALL_ELF) || _CALL_ELF !=2 )
impressive stuff!
Everything nicely documented. Could you add few words for the above condition as well ?
Or may be a new macro, since it occurs many times?
What are these _CALL_ELF == 2 and != 2 conditions mean? ppc ABIs ? Will there ever be v3 ?
So far most of the bpf jits were going via net-next tree, but if in this case no changes to the core is necessary then I guess it's fine to do it via powerpc tree. What's your plan?
Daniel Borkmann
maintainerRe: [RFC PATCH 6/6] ppc: ebpf/jit: Implement JIT compiler for extended BPF
Quoted 36 lines · Alexei Starovoitov
Quoted 33 lines · Naveen N. Rao
PPC64 eBPF JIT compiler. Works for both ABIv1 and ABIv2.
Enable with:
echo 1 >/proc/sys/net/core/bpf_jit_enable
or
echo 2 >/proc/sys/net/core/bpf_jit_enable... to see the generated JIT code. This can further be processed with
tools/net/bpf_jit_disasm.With
CONFIG_TEST_BPF=mand 'modprobetest_bpf':test_bpf: Summary: 291 PASSED, 0 FAILED, [234/283 JIT'ed]... on both ppc64 BE and LE.
The details of the approach are documented through various comments in the code, as are the TODOs. Some of the prominent TODOs include implementing BPF tail calls and skb loads.
Cc Matt Evans <[email protected]>Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc "David S. Miller" <[email protected]>Cc Ananth N Mavinakayanahalli <[email protected]>Signed-off-by Naveen N. Rao <[email protected]>--- arch/powerpc/include/asm/ppc-opcode.h | 19 +- arch/powerpc/net/Makefile | 4 + arch/powerpc/net/bpf_jit.h | 66 ++- arch/powerpc/net/bpf_jit64.h | 58 +++ arch/powerpc/net/bpf_jit_comp64.c | 828 ++++++++++++++++++++++++++++++++++ 5 files changed, 973 insertions(+), 2 deletions(-)Quoted 2 lines
create mode 100644
arch/powerpc/net/bpf_jit64.hcreate mode 100644arch/powerpc/net/bpf_jit_comp64.c
Quoted 5 lines
...
arch/powerpc/net/bpf_jit.h line 17
Quoted 2 lines
arch/powerpc/net/bpf_jit.h +1
-1-#ifdef CONFIG_PPC64 +#if defined(CONFIG_PPC64 ) && (!defined(_CALL_ELF) || _CALL_ELF !=2 )impressive stuff!
+1, awesome to see another one!
Quoted 5 lines
Everything nicely documented. Could you add few words for the above condition as well ?
Or may be a new macro, since it occurs many times?
What are these_CALL_ELF== 2 and != 2 conditions mean? ppc ABIs ? Will there ever be v3 ?
Minor TODO would also be to convert to use bpf_jit_binary_alloc() and bpf_jit_binary_free() API for the image, which is done by other eBPF jits, too.
Quoted 4 lines
So far most of the bpf jits were going via net-next tree, but if in this case no changes to the core is necessary then I guess it's fine to do it via powerpc tree. What's your plan?
Re: [RFC PATCH 6/6] ppc: ebpf/jit: Implement JIT compiler for extended BPF
Quoted 37 lines · Daniel Borkmann
Quoted 36 lines · Alexei Starovoitov
Quoted 35 lines · Naveen N. Rao
PPC64 eBPF JIT compiler. Works for both ABIv1 and ABIv2.
Enable with:
echo 1 >/proc/sys/net/core/bpf_jit_enable
or
echo 2 >/proc/sys/net/core/bpf_jit_enable... to see the generated JIT code. This can further be processed with
tools/net/bpf_jit_disasm.With
CONFIG_TEST_BPF=mand 'modprobetest_bpf':test_bpf: Summary: 291 PASSED, 0 FAILED, [234/283 JIT'ed]... on both ppc64 BE and LE.
The details of the approach are documented through various comments in the code, as are the TODOs. Some of the prominent TODOs include implementing BPF tail calls and skb loads.
Cc Matt Evans <[email protected]>Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc "David S. Miller" <[email protected]>Cc Ananth N Mavinakayanahalli <[email protected]>Signed-off-by Naveen N. Rao <[email protected]>--- arch/powerpc/include/asm/ppc-opcode.h | 19 +- arch/powerpc/net/Makefile | 4 + arch/powerpc/net/bpf_jit.h | 66 ++- arch/powerpc/net/bpf_jit64.h | 58 +++ arch/powerpc/net/bpf_jit_comp64.c | 828 ++++++++++++++++++++++++++++++++++ 5 files changed, 973 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/net/bpf_jit64.h create mode 100644 arch/powerpc/net/bpf_jit_comp64.c
Quoted 7 lines
Quoted 5 lines
...
arch/powerpc/net/bpf_jit.h line 17
Quoted 2 lines
arch/powerpc/net/bpf_jit.h +1
-1-#ifdef CONFIG_PPC64 +#if defined(CONFIG_PPC64 ) && (!defined(_CALL_ELF) || _CALL_ELF !=2 )impressive stuff!
+1, awesome to see another one!
Thanks!
Quoted 5 lines
Quoted 5 lines
Everything nicely documented. Could you add few words for the above condition as well ?
Or may be a new macro, since it occurs many times?
What are these_CALL_ELF== 2 and != 2 conditions mean? ppc ABIs ?
Yes, there are 2 ABIs: ppc64 (ABIv1) -- big endian and the recently introduced ppc64le (ABIv2) which is currently only little endian. There is also ppc32...
Good suggestion about using a macro. I will put out a patch for that.
Quoted 1 line
Quoted 1 line
Will there ever be v3 ?
Hope not! ;)
Quoted 4 lines
Minor TODO would also be to convert to use
bpf_jit_binary_alloc()andbpf_jit_binary_free()API for the image, which is done by other eBPF jits, too.
Sure. I will make that change.
Quoted 4 lines
Quoted 4 lines
So far most of the bpf jits were going via net-next tree, but if in this case no changes to the core is necessary then I guess it's fine to do it via powerpc tree. What's your plan?
I initially thought this has to go through the powerpc tree. I don't really have a preference and I'll allow the maintainers to take a call on that. I do however need a review of the JIT code from Michael Ellerman/Paul Mackerras.
- Naveen
Quoted 8 lines · Naveen N Rao
Implement extended BPF JIT for ppc64. We retain the classic BPF JIT for ppc32 and move ppc64 BE/LE to use the new JIT. Classic BPF filters will be converted to extended BPF (see
convert_filter()) and JIT'ed with the new compiler.Most of the existing macros are retained and fixed/enhanced where appropriate. Patches 1-4 are geared towards this.
Quoted 6 lines
Patch 5 breaks out the classic BPF JIT specifics into a separate
bpf_jit32.hheader file, while retaining all the generic instruction macros inbpf_jit.h. Most of these macros can potentially be generalized and moved to more common code (tagged with a TODO in patch 6).Patch 6 implements eBPF JIT for ppc64.
As a comparison, here are the test results with the BPF test suite kernel module:
With the classic BPF JIT:test_bpf: Summary: 291 PASSED, 0 FAILED, [85/283 JIT'ed]
and with the extended BPF JIT:test_bpf: Summary: 291 PASSED, 0 FAILED, [234/283 JIT'ed]
As noted in patch 6, there are still a few more instructions to be JIT'ed.
- Naveen