On Wed, Jan 11, 2023 at 2:11 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > Currently we allow to load any tracing program as sleepable, > but BPF_TRACE_RAW_TP can't sleep. Making the check explicit > for tracing programs attach types, so sleepable BPF_TRACE_RAW_TP > will fail to load. > > Updating the verifier error to mention iter programs as well. > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> > --- > v2 changes: > - use bool for can_be_sleepable return value [Song] > - add tests [Song] > > kernel/bpf/verifier.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index fa4c911603e9..f20777c2a957 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -16743,6 +16743,18 @@ BTF_ID(func, rcu_read_unlock_strict) > #endif > BTF_SET_END(btf_id_deny) > > +static bool can_be_sleepable(struct bpf_prog *prog) > +{ > + if (prog->type == BPF_PROG_TYPE_TRACING) { > + return prog->expected_attach_type == BPF_TRACE_FENTRY || > + prog->expected_attach_type == BPF_TRACE_FEXIT || > + prog->expected_attach_type == BPF_MODIFY_RETURN || > + prog->expected_attach_type == BPF_TRACE_ITER; > + } > + return prog->type == BPF_PROG_TYPE_LSM || > + prog->type == BPF_PROG_TYPE_KPROBE; > +} imo it's too verbose. Maybe try a switch stmt ? Or at least copy prog->expected_attach_type and prog->type into variables.