summaryrefslogtreecommitdiffstats
path: root/arch/arm64/net
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2017-06-10 21:55:27 -0400
committerDavid S. Miller <davem@davemloft.net>2017-06-11 18:18:32 -0400
commitf1c9eed7f437d0fc75b35d65bb45eab281706321 (patch)
tree311caa9372c1f59ba8e9190b51577d51cf6ac2a6 /arch/arm64/net
parent66e037ca57f967bb344fbd381fa0651a502cb1f4 (diff)
bpf, arm64: take advantage of stack_depth tracking
Make use of recently implemented stack_depth tracking for arm64 JIT, so that stack usage can be reduced heavily for programs not using tail calls at least. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/arm64/net')
-rw-r--r--arch/arm64/net/bpf_jit_comp.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 4f95873d7142..73de2c71cfb0 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -69,6 +69,7 @@ struct jit_ctx {
69 int epilogue_offset; 69 int epilogue_offset;
70 int *offset; 70 int *offset;
71 u32 *image; 71 u32 *image;
72 u32 stack_size;
72}; 73};
73 74
74static inline void emit(const u32 insn, struct jit_ctx *ctx) 75static inline void emit(const u32 insn, struct jit_ctx *ctx)
@@ -145,16 +146,11 @@ static inline int epilogue_offset(const struct jit_ctx *ctx)
145/* Stack must be multiples of 16B */ 146/* Stack must be multiples of 16B */
146#define STACK_ALIGN(sz) (((sz) + 15) & ~15) 147#define STACK_ALIGN(sz) (((sz) + 15) & ~15)
147 148
148#define _STACK_SIZE \
149 (MAX_BPF_STACK \
150 + 4 /* extra for skb_copy_bits buffer */)
151
152#define STACK_SIZE STACK_ALIGN(_STACK_SIZE)
153
154#define PROLOGUE_OFFSET 8 149#define PROLOGUE_OFFSET 8
155 150
156static int build_prologue(struct jit_ctx *ctx) 151static int build_prologue(struct jit_ctx *ctx)
157{ 152{
153 const struct bpf_prog *prog = ctx->prog;
158 const u8 r6 = bpf2a64[BPF_REG_6]; 154 const u8 r6 = bpf2a64[BPF_REG_6];
159 const u8 r7 = bpf2a64[BPF_REG_7]; 155 const u8 r7 = bpf2a64[BPF_REG_7];
160 const u8 r8 = bpf2a64[BPF_REG_8]; 156 const u8 r8 = bpf2a64[BPF_REG_8];
@@ -176,9 +172,9 @@ static int build_prologue(struct jit_ctx *ctx)
176 * | | 172 * | |
177 * | ... | BPF prog stack 173 * | ... | BPF prog stack
178 * | | 174 * | |
179 * +-----+ <= (BPF_FP - MAX_BPF_STACK) 175 * +-----+ <= (BPF_FP - prog->aux->stack_depth)
180 * |RSVD | JIT scratchpad 176 * |RSVD | JIT scratchpad
181 * current A64_SP => +-----+ <= (BPF_FP - STACK_SIZE) 177 * current A64_SP => +-----+ <= (BPF_FP - ctx->stack_size)
182 * | | 178 * | |
183 * | ... | Function call stack 179 * | ... | Function call stack
184 * | | 180 * | |
@@ -202,8 +198,12 @@ static int build_prologue(struct jit_ctx *ctx)
202 /* Initialize tail_call_cnt */ 198 /* Initialize tail_call_cnt */
203 emit(A64_MOVZ(1, tcc, 0, 0), ctx); 199 emit(A64_MOVZ(1, tcc, 0, 0), ctx);
204 200
201 /* 4 byte extra for skb_copy_bits buffer */
202 ctx->stack_size = prog->aux->stack_depth + 4;
203 ctx->stack_size = STACK_ALIGN(ctx->stack_size);
204
205 /* Set up function call stack */ 205 /* Set up function call stack */
206 emit(A64_SUB_I(1, A64_SP, A64_SP, STACK_SIZE), ctx); 206 emit(A64_SUB_I(1, A64_SP, A64_SP, ctx->stack_size), ctx);
207 207
208 cur_offset = ctx->idx - idx0; 208 cur_offset = ctx->idx - idx0;
209 if (cur_offset != PROLOGUE_OFFSET) { 209 if (cur_offset != PROLOGUE_OFFSET) {
@@ -288,7 +288,7 @@ static void build_epilogue(struct jit_ctx *ctx)
288 const u8 fp = bpf2a64[BPF_REG_FP]; 288 const u8 fp = bpf2a64[BPF_REG_FP];
289 289
290 /* We're done with BPF stack */ 290 /* We're done with BPF stack */
291 emit(A64_ADD_I(1, A64_SP, A64_SP, STACK_SIZE), ctx); 291 emit(A64_ADD_I(1, A64_SP, A64_SP, ctx->stack_size), ctx);
292 292
293 /* Restore fs (x25) and x26 */ 293 /* Restore fs (x25) and x26 */
294 emit(A64_POP(fp, A64_R(26), A64_SP), ctx); 294 emit(A64_POP(fp, A64_R(26), A64_SP), ctx);
@@ -732,7 +732,7 @@ emit_cond_jmp:
732 return -EINVAL; 732 return -EINVAL;
733 } 733 }
734 emit_a64_mov_i64(r3, size, ctx); 734 emit_a64_mov_i64(r3, size, ctx);
735 emit(A64_SUB_I(1, r4, fp, STACK_SIZE), ctx); 735 emit(A64_SUB_I(1, r4, fp, ctx->stack_size), ctx);
736 emit_a64_mov_i64(r5, (unsigned long)bpf_load_pointer, ctx); 736 emit_a64_mov_i64(r5, (unsigned long)bpf_load_pointer, ctx);
737 emit(A64_BLR(r5), ctx); 737 emit(A64_BLR(r5), ctx);
738 emit(A64_MOV(1, r0, A64_R(0)), ctx); 738 emit(A64_MOV(1, r0, A64_R(0)), ctx);