]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Verifier support for sleepable tracepoint programs
authorMykyta Yatsenko <yatsenko@meta.com>
Wed, 22 Apr 2026 19:41:09 +0000 (12:41 -0700)
committerKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 22 Apr 2026 20:44:29 +0000 (22:44 +0200)
Allow BPF_PROG_TYPE_RAW_TRACEPOINT, BPF_PROG_TYPE_TRACEPOINT, and
BPF_TRACE_RAW_TP (tp_btf) programs to be sleepable by adding them
to can_be_sleepable().

For BTF-based raw tracepoints (tp_btf), add a load-time check in
bpf_check_attach_target() that rejects sleepable programs attaching
to non-faultable tracepoints with a descriptive error message.

For raw tracepoints (raw_tp), add an attach-time check in
bpf_raw_tp_link_attach() that rejects sleepable programs on
non-faultable tracepoints. The attach-time check is needed because
the tracepoint name is not known at load time for raw_tp.

The attach-time check for classic tracepoints (tp) in
__perf_event_set_bpf_prog() was added in the previous patch.

Replace the verbose error message that enumerates allowed program
types with a generic "Program of this type cannot be sleepable"
message, since the list of sleepable-capable types keeps growing.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/bpf/20260422-sleepable_tracepoints-v13-4-99005dff21ef@meta.com
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
kernel/bpf/syscall.c
kernel/bpf/verifier.c

index a3c0214ca9341067eff2f6fc1897497f9cb3a9ec..3b1f0ba02f613649bb1be7c24f544457e6d4a74d 100644 (file)
@@ -4281,6 +4281,11 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog,
        if (!btp)
                return -ENOENT;
 
+       if (prog->sleepable && !tracepoint_is_faultable(btp->tp)) {
+               bpf_put_raw_tracepoint(btp);
+               return -EINVAL;
+       }
+
        link = kzalloc_obj(*link, GFP_USER);
        if (!link) {
                err = -ENOMEM;
index 185210b7338511686a804b0be1e0d5a9973b96df..5b4806fdb648f4431966a6891e19d9dd5fa3324c 100644 (file)
@@ -19267,6 +19267,12 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
                btp = bpf_get_raw_tracepoint(tname);
                if (!btp)
                        return -EINVAL;
+               if (prog->sleepable && !tracepoint_is_faultable(btp->tp)) {
+                       bpf_log(log, "Sleepable program cannot attach to non-faultable tracepoint %s\n",
+                               tname);
+                       bpf_put_raw_tracepoint(btp);
+                       return -EINVAL;
+               }
                fname = kallsyms_lookup((unsigned long)btp->bpf_func, NULL, NULL, NULL,
                                        trace_symbol);
                bpf_put_raw_tracepoint(btp);
@@ -19483,6 +19489,7 @@ static bool can_be_sleepable(struct bpf_prog *prog)
                case BPF_MODIFY_RETURN:
                case BPF_TRACE_ITER:
                case BPF_TRACE_FSESSION:
+               case BPF_TRACE_RAW_TP:
                        return true;
                default:
                        return false;
@@ -19490,7 +19497,9 @@ static bool can_be_sleepable(struct bpf_prog *prog)
        }
        return prog->type == BPF_PROG_TYPE_LSM ||
               prog->type == BPF_PROG_TYPE_KPROBE /* only for uprobes */ ||
-              prog->type == BPF_PROG_TYPE_STRUCT_OPS;
+              prog->type == BPF_PROG_TYPE_STRUCT_OPS ||
+              prog->type == BPF_PROG_TYPE_RAW_TRACEPOINT ||
+              prog->type == BPF_PROG_TYPE_TRACEPOINT;
 }
 
 static int check_attach_btf_id(struct bpf_verifier_env *env)
@@ -19512,7 +19521,7 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
        }
 
        if (prog->sleepable && !can_be_sleepable(prog)) {
-               verbose(env, "Only fentry/fexit/fsession/fmod_ret, lsm, iter, uprobe, and struct_ops programs can be sleepable\n");
+               verbose(env, "Program of this type cannot be sleepable\n");
                return -EINVAL;
        }