Skip to content

Commit 6ce848c

Browse files
Yonghong Songintel-lab-lkp
authored andcommitted
bpf, x86: Avoid repeated usage of bpf_prog->aux->stack_depth
Refactor the code to avoid repeated usage of bpf_prog->aux->stack_depth in do_jit() func. If the private stack is used, the stack_depth will be 0 for that prog. Refactoring make it easy to adjust stack_depth. Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
1 parent f35407e commit 6ce848c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/x86/net/bpf_jit_comp.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,14 +1425,17 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, u8 *rw_image
14251425
int i, excnt = 0;
14261426
int ilen, proglen = 0;
14271427
u8 *prog = temp;
1428+
u32 stack_depth;
14281429
int err;
14291430

1431+
stack_depth = bpf_prog->aux->stack_depth;
1432+
14301433
arena_vm_start = bpf_arena_get_kern_vm_start(bpf_prog->aux->arena);
14311434
user_vm_start = bpf_arena_get_user_vm_start(bpf_prog->aux->arena);
14321435

14331436
detect_reg_usage(insn, insn_cnt, callee_regs_used);
14341437

1435-
emit_prologue(&prog, bpf_prog->aux->stack_depth,
1438+
emit_prologue(&prog, stack_depth,
14361439
bpf_prog_was_classic(bpf_prog), tail_call_reachable,
14371440
bpf_is_subprog(bpf_prog), bpf_prog->aux->exception_cb);
14381441
/* Exception callback will clobber callee regs for its own use, and
@@ -2128,7 +2131,7 @@ st: if (is_imm8(insn->off))
21282131

21292132
func = (u8 *) __bpf_call_base + imm32;
21302133
if (tail_call_reachable) {
2131-
LOAD_TAIL_CALL_CNT_PTR(bpf_prog->aux->stack_depth);
2134+
LOAD_TAIL_CALL_CNT_PTR(stack_depth);
21322135
ip += 7;
21332136
}
21342137
if (!imm32)
@@ -2145,13 +2148,13 @@ st: if (is_imm8(insn->off))
21452148
&bpf_prog->aux->poke_tab[imm32 - 1],
21462149
&prog, image + addrs[i - 1],
21472150
callee_regs_used,
2148-
bpf_prog->aux->stack_depth,
2151+
stack_depth,
21492152
ctx);
21502153
else
21512154
emit_bpf_tail_call_indirect(bpf_prog,
21522155
&prog,
21532156
callee_regs_used,
2154-
bpf_prog->aux->stack_depth,
2157+
stack_depth,
21552158
image + addrs[i - 1],
21562159
ctx);
21572160
break;

0 commit comments

Comments
 (0)