Skip to contentSkip to conversation

arm64 BPF JIT updates

PATCH Superseded Zi Shen Lim 2 participants 5 messages Jun 7, 2016 – Jun 8, 2016

Subsystems (6)
Networking Network drivers BPF arm64 +2 more subsystems

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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);
         ^

...

Fixes 0fc174dea545 ("ebpf: make internal bpf API independent of CONFIG_BPF_SYSCALL ifdefs")
---
 include/linux/bpf.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/bpf.h +1 -0
index 8ee27b8..1bcae82 100644
@@ -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
#2 lore raw

PATCH v2 3/4 arm64: bpf: optimize JMP_CALL

In reply to Zi Shen Lim

Remove 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
index 51abc97..7ae304e 100644
@@ -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
#3 lore raw

PATCH v2 4/4 arm64: bpf: optimize LD_ABS, LD_IND

In reply to Zi Shen Lim

Remove 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
index 7ae304e..b2fc97a 100644
@@ -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
maintainer
#4 lore raw
In reply to Zi Shen Lim

From: 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 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.

Quoted 5 lines

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

I only see patches 1, 3, and 4 on the list.

Please resubmit.