Skip to content

Commit dfe6625

Browse files
Benjamin TissoiresAlexei Starovoitov
authored andcommitted
bpf: introduce in_sleepable() helper
No code change, but it'll allow to have only one place to change everything when we add in_sleepable in cur_state. Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> Link: https://lore.kernel.org/r/20240221-hid-bpf-sleepable-v3-2-1fb378ca6301@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 55bad79 commit dfe6625

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,14 +5255,19 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,
52555255
return -EINVAL;
52565256
}
52575257

5258+
static bool in_sleepable(struct bpf_verifier_env *env)
5259+
{
5260+
return env->prog->aux->sleepable;
5261+
}
5262+
52585263
/* The non-sleepable programs and sleepable programs with explicit bpf_rcu_read_lock()
52595264
* can dereference RCU protected pointers and result is PTR_TRUSTED.
52605265
*/
52615266
static bool in_rcu_cs(struct bpf_verifier_env *env)
52625267
{
52635268
return env->cur_state->active_rcu_lock ||
52645269
env->cur_state->active_lock.ptr ||
5265-
!env->prog->aux->sleepable;
5270+
!in_sleepable(env);
52665271
}
52675272

52685273
/* Once GCC supports btf_type_tag the following mechanism will be replaced with tag check */
@@ -10164,7 +10169,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
1016410169
return -EINVAL;
1016510170
}
1016610171

10167-
if (!env->prog->aux->sleepable && fn->might_sleep) {
10172+
if (!in_sleepable(env) && fn->might_sleep) {
1016810173
verbose(env, "helper call might sleep in a non-sleepable prog\n");
1016910174
return -EINVAL;
1017010175
}
@@ -10194,7 +10199,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
1019410199
return -EINVAL;
1019510200
}
1019610201

10197-
if (env->prog->aux->sleepable && is_storage_get_function(func_id))
10202+
if (in_sleepable(env) && is_storage_get_function(func_id))
1019810203
env->insn_aux_data[insn_idx].storage_get_func_atomic = true;
1019910204
}
1020010205

@@ -11535,7 +11540,7 @@ static bool check_css_task_iter_allowlist(struct bpf_verifier_env *env)
1153511540
return true;
1153611541
fallthrough;
1153711542
default:
11538-
return env->prog->aux->sleepable;
11543+
return in_sleepable(env);
1153911544
}
1154011545
}
1154111546

@@ -12056,7 +12061,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
1205612061
}
1205712062

1205812063
sleepable = is_kfunc_sleepable(&meta);
12059-
if (sleepable && !env->prog->aux->sleepable) {
12064+
if (sleepable && !in_sleepable(env)) {
1206012065
verbose(env, "program must be sleepable to call sleepable kfunc %s\n", func_name);
1206112066
return -EACCES;
1206212067
}
@@ -19669,7 +19674,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env)
1966919674
}
1967019675

1967119676
if (is_storage_get_function(insn->imm)) {
19672-
if (!env->prog->aux->sleepable ||
19677+
if (!in_sleepable(env) ||
1967319678
env->insn_aux_data[i + delta].storage_get_func_atomic)
1967419679
insn_buf[0] = BPF_MOV64_IMM(BPF_REG_5, (__force __s32)GFP_ATOMIC);
1967519680
else

0 commit comments

Comments
 (0)