Skip to content

Commit e00931c

Browse files
Yonghong SongAlexei Starovoitov
authored andcommitted
bpf: Enable private stack for eligible subprogs
If private stack is used by any subprog, set that subprog prog->aux->jits_use_priv_stack to be true so later jit can allocate private stack for that subprog properly. Also set env->prog->aux->jits_use_priv_stack to be true if any subprog uses private stack. This is a use case for a single main prog (no subprogs) to use private stack, and also a use case for later struct-ops progs where env->prog->aux->jits_use_priv_stack will enable recursion check if any subprog uses private stack. Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20241112163912.2224007-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent a76ab57 commit e00931c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ struct bpf_prog_aux {
15231523
bool exception_cb;
15241524
bool exception_boundary;
15251525
bool is_extended; /* true if extended by freplace program */
1526+
bool jits_use_priv_stack;
15261527
u64 prog_array_member_cnt; /* counts how many times as member of prog_array */
15271528
struct mutex ext_mutex; /* mutex for is_extended and prog_array_member_cnt */
15281529
struct bpf_arena *arena;

kernel/bpf/verifier.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6334,6 +6334,14 @@ static int check_max_stack_depth(struct bpf_verifier_env *env)
63346334
return ret;
63356335
}
63366336
}
6337+
6338+
for (int i = 0; i < env->subprog_cnt; i++) {
6339+
if (si[i].priv_stack_mode == PRIV_STACK_ADAPTIVE) {
6340+
env->prog->aux->jits_use_priv_stack = true;
6341+
break;
6342+
}
6343+
}
6344+
63376345
return 0;
63386346
}
63396347

@@ -20274,6 +20282,9 @@ static int jit_subprogs(struct bpf_verifier_env *env)
2027420282

2027520283
func[i]->aux->name[0] = 'F';
2027620284
func[i]->aux->stack_depth = env->subprog_info[i].stack_depth;
20285+
if (env->subprog_info[i].priv_stack_mode == PRIV_STACK_ADAPTIVE)
20286+
func[i]->aux->jits_use_priv_stack = true;
20287+
2027720288
func[i]->jit_requested = 1;
2027820289
func[i]->blinding_requested = prog->blinding_requested;
2027920290
func[i]->aux->kfunc_tab = prog->aux->kfunc_tab;

0 commit comments

Comments
 (0)