Commit 23a2d70c authored by Yonghong Song's avatar Yonghong Song Committed by Alexei Starovoitov

bpf: Refactor BPF_PSEUDO_CALL checking as a helper function

There is no functionality change. This refactoring intends
to facilitate next patch change with BPF_PSEUDO_FUNC.
Signed-off-by: default avatarYonghong Song <yhs@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210204234827.1628953-1-yhs@fb.com
parent ecda49c5
...@@ -228,6 +228,12 @@ static void bpf_map_key_store(struct bpf_insn_aux_data *aux, u64 state) ...@@ -228,6 +228,12 @@ static void bpf_map_key_store(struct bpf_insn_aux_data *aux, u64 state)
(poisoned ? BPF_MAP_KEY_POISON : 0ULL); (poisoned ? BPF_MAP_KEY_POISON : 0ULL);
} }
static bool bpf_pseudo_call(const struct bpf_insn *insn)
{
return insn->code == (BPF_JMP | BPF_CALL) &&
insn->src_reg == BPF_PSEUDO_CALL;
}
struct bpf_call_arg_meta { struct bpf_call_arg_meta {
struct bpf_map *map_ptr; struct bpf_map *map_ptr;
bool raw_mode; bool raw_mode;
...@@ -1486,9 +1492,7 @@ static int check_subprogs(struct bpf_verifier_env *env) ...@@ -1486,9 +1492,7 @@ static int check_subprogs(struct bpf_verifier_env *env)
/* determine subprog starts. The end is one before the next starts */ /* determine subprog starts. The end is one before the next starts */
for (i = 0; i < insn_cnt; i++) { for (i = 0; i < insn_cnt; i++) {
if (insn[i].code != (BPF_JMP | BPF_CALL)) if (!bpf_pseudo_call(insn + i))
continue;
if (insn[i].src_reg != BPF_PSEUDO_CALL)
continue; continue;
if (!env->bpf_capable) { if (!env->bpf_capable) {
verbose(env, verbose(env,
...@@ -3074,9 +3078,7 @@ static int check_max_stack_depth(struct bpf_verifier_env *env) ...@@ -3074,9 +3078,7 @@ static int check_max_stack_depth(struct bpf_verifier_env *env)
continue_func: continue_func:
subprog_end = subprog[idx + 1].start; subprog_end = subprog[idx + 1].start;
for (; i < subprog_end; i++) { for (; i < subprog_end; i++) {
if (insn[i].code != (BPF_JMP | BPF_CALL)) if (!bpf_pseudo_call(insn + i))
continue;
if (insn[i].src_reg != BPF_PSEUDO_CALL)
continue; continue;
/* remember insn and function to return to */ /* remember insn and function to return to */
ret_insn[frame] = i + 1; ret_insn[frame] = i + 1;
...@@ -10846,8 +10848,7 @@ static int jit_subprogs(struct bpf_verifier_env *env) ...@@ -10846,8 +10848,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
return 0; return 0;
for (i = 0, insn = prog->insnsi; i < prog->len; i++, insn++) { for (i = 0, insn = prog->insnsi; i < prog->len; i++, insn++) {
if (insn->code != (BPF_JMP | BPF_CALL) || if (!bpf_pseudo_call(insn))
insn->src_reg != BPF_PSEUDO_CALL)
continue; continue;
/* Upon error here we cannot fall back to interpreter but /* Upon error here we cannot fall back to interpreter but
* need a hard reject of the program. Thus -EFAULT is * need a hard reject of the program. Thus -EFAULT is
...@@ -10976,8 +10977,7 @@ static int jit_subprogs(struct bpf_verifier_env *env) ...@@ -10976,8 +10977,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
for (i = 0; i < env->subprog_cnt; i++) { for (i = 0; i < env->subprog_cnt; i++) {
insn = func[i]->insnsi; insn = func[i]->insnsi;
for (j = 0; j < func[i]->len; j++, insn++) { for (j = 0; j < func[i]->len; j++, insn++) {
if (insn->code != (BPF_JMP | BPF_CALL) || if (!bpf_pseudo_call(insn))
insn->src_reg != BPF_PSEUDO_CALL)
continue; continue;
subprog = insn->off; subprog = insn->off;
insn->imm = BPF_CAST_CALL(func[subprog]->bpf_func) - insn->imm = BPF_CAST_CALL(func[subprog]->bpf_func) -
...@@ -11022,8 +11022,7 @@ static int jit_subprogs(struct bpf_verifier_env *env) ...@@ -11022,8 +11022,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
* later look the same as if they were interpreted only. * later look the same as if they were interpreted only.
*/ */
for (i = 0, insn = prog->insnsi; i < prog->len; i++, insn++) { for (i = 0, insn = prog->insnsi; i < prog->len; i++, insn++) {
if (insn->code != (BPF_JMP | BPF_CALL) || if (!bpf_pseudo_call(insn))
insn->src_reg != BPF_PSEUDO_CALL)
continue; continue;
insn->off = env->insn_aux_data[i].call_imm; insn->off = env->insn_aux_data[i].call_imm;
subprog = find_subprog(env, i + insn->off + 1); subprog = find_subprog(env, i + insn->off + 1);
...@@ -11052,8 +11051,7 @@ static int jit_subprogs(struct bpf_verifier_env *env) ...@@ -11052,8 +11051,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
/* cleanup main prog to be interpreted */ /* cleanup main prog to be interpreted */
prog->jit_requested = 0; prog->jit_requested = 0;
for (i = 0, insn = prog->insnsi; i < prog->len; i++, insn++) { for (i = 0, insn = prog->insnsi; i < prog->len; i++, insn++) {
if (insn->code != (BPF_JMP | BPF_CALL) || if (!bpf_pseudo_call(insn))
insn->src_reg != BPF_PSEUDO_CALL)
continue; continue;
insn->off = 0; insn->off = 0;
insn->imm = env->insn_aux_data[i].call_imm; insn->imm = env->insn_aux_data[i].call_imm;
...@@ -11088,8 +11086,7 @@ static int fixup_call_args(struct bpf_verifier_env *env) ...@@ -11088,8 +11086,7 @@ static int fixup_call_args(struct bpf_verifier_env *env)
return -EINVAL; return -EINVAL;
} }
for (i = 0; i < prog->len; i++, insn++) { for (i = 0; i < prog->len; i++, insn++) {
if (insn->code != (BPF_JMP | BPF_CALL) || if (!bpf_pseudo_call(insn))
insn->src_reg != BPF_PSEUDO_CALL)
continue; continue;
depth = get_callee_stack_depth(env, insn, i); depth = get_callee_stack_depth(env, insn, i);
if (depth < 0) if (depth < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment