@@ -69,6 +69,7 @@ struct jit_ctx {
69
69
int epilogue_offset ;
70
70
int * offset ;
71
71
u32 * image ;
72
+ u32 stack_size ;
72
73
};
73
74
74
75
static 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
146
/* Stack must be multiples of 16B */
146
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
149
#define PROLOGUE_OFFSET 8
155
150
156
151
static int build_prologue (struct jit_ctx * ctx )
157
152
{
153
+ const struct bpf_prog * prog = ctx -> prog ;
158
154
const u8 r6 = bpf2a64 [BPF_REG_6 ];
159
155
const u8 r7 = bpf2a64 [BPF_REG_7 ];
160
156
const u8 r8 = bpf2a64 [BPF_REG_8 ];
@@ -176,9 +172,9 @@ static int build_prologue(struct jit_ctx *ctx)
176
172
* | |
177
173
* | ... | BPF prog stack
178
174
* | |
179
- * +-----+ <= (BPF_FP - MAX_BPF_STACK )
175
+ * +-----+ <= (BPF_FP - prog->aux->stack_depth )
180
176
* |RSVD | JIT scratchpad
181
- * current A64_SP => +-----+ <= (BPF_FP - STACK_SIZE )
177
+ * current A64_SP => +-----+ <= (BPF_FP - ctx->stack_size )
182
178
* | |
183
179
* | ... | Function call stack
184
180
* | |
@@ -202,8 +198,12 @@ static int build_prologue(struct jit_ctx *ctx)
202
198
/* Initialize tail_call_cnt */
203
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
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
208
cur_offset = ctx -> idx - idx0 ;
209
209
if (cur_offset != PROLOGUE_OFFSET ) {
@@ -288,7 +288,7 @@ static void build_epilogue(struct jit_ctx *ctx)
288
288
const u8 fp = bpf2a64 [BPF_REG_FP ];
289
289
290
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
293
/* Restore fs (x25) and x26 */
294
294
emit (A64_POP (fp , A64_R (26 ), A64_SP ), ctx );
@@ -732,7 +732,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
732
732
return - EINVAL ;
733
733
}
734
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
736
emit_a64_mov_i64 (r5 , (unsigned long )bpf_load_pointer , ctx );
737
737
emit (A64_BLR (r5 ), ctx );
738
738
emit (A64_MOV (1 , r0 , A64_R (0 )), ctx );
0 commit comments