bpf, x86: Avoid repeated usage of bpf_prog->aux->stack_depth
authorYonghong Song <yonghong.song@linux.dev>
Tue, 12 Nov 2024 16:39:17 +0000 (08:39 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 13 Nov 2024 00:26:24 +0000 (16:26 -0800)
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>
Link: https://lore.kernel.org/r/20241112163917.2224189-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/x86/net/bpf_jit_comp.c

index 06b080b..3ff638c 100644 (file)
@@ -1425,14 +1425,17 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, u8 *rw_image
        int i, excnt = 0;
        int ilen, proglen = 0;
        u8 *prog = temp;
+       u32 stack_depth;
        int err;
 
+       stack_depth = bpf_prog->aux->stack_depth;
+
        arena_vm_start = bpf_arena_get_kern_vm_start(bpf_prog->aux->arena);
        user_vm_start = bpf_arena_get_user_vm_start(bpf_prog->aux->arena);
 
        detect_reg_usage(insn, insn_cnt, callee_regs_used);
 
-       emit_prologue(&prog, bpf_prog->aux->stack_depth,
+       emit_prologue(&prog, stack_depth,
                      bpf_prog_was_classic(bpf_prog), tail_call_reachable,
                      bpf_is_subprog(bpf_prog), bpf_prog->aux->exception_cb);
        /* Exception callback will clobber callee regs for its own use, and
@@ -2128,7 +2131,7 @@ populate_extable:
 
                        func = (u8 *) __bpf_call_base + imm32;
                        if (tail_call_reachable) {
-                               LOAD_TAIL_CALL_CNT_PTR(bpf_prog->aux->stack_depth);
+                               LOAD_TAIL_CALL_CNT_PTR(stack_depth);
                                ip += 7;
                        }
                        if (!imm32)
@@ -2145,13 +2148,13 @@ populate_extable:
                                                          &bpf_prog->aux->poke_tab[imm32 - 1],
                                                          &prog, image + addrs[i - 1],
                                                          callee_regs_used,
-                                                         bpf_prog->aux->stack_depth,
+                                                         stack_depth,
                                                          ctx);
                        else
                                emit_bpf_tail_call_indirect(bpf_prog,
                                                            &prog,
                                                            callee_regs_used,
-                                                           bpf_prog->aux->stack_depth,
+                                                           stack_depth,
                                                            image + addrs[i - 1],
                                                            ctx);
                        break;