arm64 BPF JIT updates
Subsystems (6)
v2 cover arm64 BPF JIT updates
Updates for arm64 eBPF JIT.
The main addition here is implementation of bpf_tail_call.
#1: Fix missing header inclusion in linux/bpf.h.
#2: Add bpf_tail_call for arm64.
#3,4: Optimizations to reduce instruction count for jitted code.
Changes since v1:
- Added patch #1 to address build error due to missing header inclusion in linux/bpf.h. (Thanks to suggestion and ack by Daniel Borkmann) Ordered it ahead of bpf_tail_call patch #2 so build error is not triggered.
Zi Shen Lim (4):
bpf: fix missing header inclusion
arm64: bpf: implement bpf_tail_call() helper
arm64: bpf: optimize JMP_CALL
arm64: bpf: optimize LD_ABS, LD_IND
arch/arm64/net/bpf_jit.h | 3 +- arch/arm64/net/bpf_jit_comp.c | 111 ++++++++++++++++++++++++++++++++++++------ include/linux/bpf.h | 1 + 3 files changed, 99 insertions(+), 16 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/4 bpf: fix missing header inclusion
Commit 0fc174dea545 ("ebpf: make internal bpf API independent of CONFIG_BPF_SYSCALL ifdefs") introduced usage of ERR_PTR() in bpf_prog_get(), however did not include linux/err.h.
Without this patch, when compiling arm64 BPF without CONFIG_BPF_SYSCALL:
...
In file included from arch/arm64/net/bpf_jit_comp.c:21:0:include/linux/bpf.h: In function 'bpf_prog_get':include/linux/bpf.h:235:9: error: implicit declaration of function 'ERR_PTR' [-Werror=implicit-function-declaration]
return ERR_PTR(-EOPNOTSUPP);
^
include/linux/bpf.h:235:9: warning: return makes pointer from integer without a cast [-Wint-conversion]
In file included from include/linux/rwsem.h:17:0,
from include/linux/mm_types.h:10,
from include/linux/sched.h:27,
from arch/arm64/include/asm/compat.h:25,
from arch/arm64/include/asm/stat.h:23,
from include/linux/stat.h:5,
from include/linux/compat.h:12,
from include/linux/filter.h:10,
from arch/arm64/net/bpf_jit_comp.c:22:
include/linux/err.h: At top level:
include/linux/err.h:23:35: error: conflicting types for 'ERR_PTR'
static inline void * __must_check ERR_PTR(long error)
^
In file included from arch/arm64/net/bpf_jit_comp.c:21:0:
include/linux/bpf.h:235:9: note: previous implicit declaration of 'ERR_PTR' was here
return ERR_PTR(-EOPNOTSUPP);
^...
--- include/linux/bpf.h | 1 + 1 file changed, 1 insertion(+)
include/linux/bpf.h +1 -0
@@ -11,6 +11,7 @@#include <linux/workqueue.h> #include <linux/file.h> #include <linux/percpu.h> +#include <linux/err.h> struct bpf_map ;
Signature · 1 line
1.9.1
PATCH v2 3/4 arm64: bpf: optimize JMP_CALL
In reply to Zi Shen LimRemove superfluous stack frame, saving us 3 instructions for every JMP_CALL.
--- arch/arm64/net/bpf_jit_comp.c | 3 --- 1 file changed, 3 deletions(-)
arch/arm64/net/bpf_jit_comp.c +0 -3
@@ -578,11 +578,8 @@ emit_cond_jmp:const u64 func = (u64 )__bpf_call_base + imm;emit_a64_mov_i64 (tmp, func, ctx); -emit (A64_PUSH (A64_FP ,A64_LR ,A64_SP ), ctx); -emit (A64_MOV (1 ,A64_FP ,A64_SP ), ctx);emit (A64_BLR (tmp), ctx);emit (A64_MOV (1 , r0,A64_R (0 )), ctx); -emit (A64_POP (A64_FP ,A64_LR ,A64_SP ), ctx);break ; }/* tail call */
Signature · 1 line
1.9.1
PATCH v2 4/4 arm64: bpf: optimize LD_ABS, LD_IND
In reply to Zi Shen LimRemove superfluous stack frame, saving us 3 instructions for every LD_ABS or LD_IND.
--- arch/arm64/net/bpf_jit_comp.c | 3 --- 1 file changed, 3 deletions(-)
arch/arm64/net/bpf_jit_comp.c +0 -3
@@ -731,11 +731,8 @@ emit_cond_jmp:emit_a64_mov_i64 (r3, size, ctx);emit (A64_SUB_I (1 , r4, fp,STACK_SIZE ), ctx);emit_a64_mov_i64 (r5, (unsigned long )bpf_load_pointer, ctx); -emit (A64_PUSH (A64_FP ,A64_LR ,A64_SP ), ctx); -emit (A64_MOV (1 ,A64_FP ,A64_SP ), ctx);emit (A64_BLR (r5), ctx);emit (A64_MOV (1 , r0,A64_R (0 )), ctx); -emit (A64_POP (A64_FP ,A64_LR ,A64_SP ), ctx); jmp_offset =epilogue_offset (ctx);check_imm19 (jmp_offset);
Signature · 1 line
1.9.1
David Miller
maintainerFrom: Zi Shen Lim <[email protected]>
Date: Mon, 6 Jun 2016 22:22:55 -0700
Quoted 13 lines
Updates for arm64 eBPF JIT.
The main addition here is implementation ofbpf_tail_call.#1: Fix missing header inclusion in
linux/bpf.h.
#2: Addbpf_tail_callfor arm64.
#3,4: Optimizations to reduce instruction count for jitted code.Changes since v1:
- Added patch #1 to address build error due to missing header inclusion inlinux/bpf.h. (Thanks to suggestion and ack by Daniel Borkmann) Ordered it ahead ofbpf_tail_callpatch #2 so build error is not triggered.
Quoted 5 lines
Zi Shen Lim (4):
bpf: fix missing header inclusion
arm64: bpf: implementbpf_tail_call()helper
arm64: bpf: optimizeJMP_CALL
arm64: bpf: optimizeLD_ABS,LD_IND
I only see patches 1, 3, and 4 on the list.
Please resubmit.