| From: |
| Mykyta Yatsenko <mykyta.yatsenko5-AT-gmail.com> |
| To: |
| bpf-AT-vger.kernel.org, ast-AT-kernel.org, andrii-AT-kernel.org, daniel-AT-iogearbox.net, kafai-AT-meta.com, kernel-team-AT-meta.com, eddyz87-AT-gmail.com, ameryhung-AT-gmail.com, puranjay-AT-kernel.org |
| Subject: |
| [PATCH RFC bpf-next 0/6] bpf: Add support for sleepable raw tracepoint programs |
| Date: |
| Wed, 18 Feb 2026 16:01:17 +0000 |
| Message-ID: |
| <20260218-sleepable_tracepoints-v1-0-ec2705497208@meta.com> |
| Cc: |
| Mykyta Yatsenko <yatsenko-AT-meta.com> |
| Archive-link: |
| Article |
This series adds support for sleepable BPF programs attached to raw
tracepoints (tp_btf). The motivation is to allow BPF programs on
syscall tracepoints to use sleepable helpers such as
bpf_copy_from_user(), enabling reliable user memory reads that can
page-fault.
Currently, raw tracepoint BPF programs always run with RCU read lock
held and preemption disabled, which prevents calling any helper that
might sleep. Faultable tracepoints (__DECLARE_TRACE_SYSCALL) already
run under rcu_tasks_trace protection in process context where sleeping
is safe.
This series removes that restriction for faultable tracepoints:
Patch 1 allows BPF_TRACE_RAW_TP programs to be loaded as sleepable.
The actual enforcement is deferred to attach time since the target
tracepoint is not known during load.
Patch 2 adds an attach-time check to reject sleepable programs on
non-faultable tracepoints (e.g., sched_switch) that may run in NMI
or other non-sleepable contexts.
Patch 3 modifies __bpf_trace_run() to support sleepable programs:
delete cant_sleep(), use migrate_disable() instead of rcu_read_lock(),
and rely on the outer rcu_tasks_trace lock from the faultable
tracepoint callback for program lifetime protection.
Patch 4 removes preempt_disable from the faultable tracepoint BPF
callback wrapper, since preemption management is now handled
per-program inside __bpf_trace_run().
Patch 5 adds the tp_btf.s section handler in libbpf, following the
existing pattern of fentry.s/fexit.s/lsm.s.
Patch 6 adds selftests covering both the positive case (sleepable
program on sys_enter using bpf_copy_from_user() to read user memory)
and the negative case (sleepable program rejected on sched_switch).
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
Mykyta Yatsenko (6):
bpf: Allow sleepable programs for BPF_TRACE_RAW_TP attach type
bpf: Reject sleepable raw_tp programs on non-faultable tracepoints
bpf: Remove preempt_disable from faultable tracepoint BPF callbacks
bpf: Add sleepable execution path for raw tracepoint programs
libbpf: Add tp_btf.s section handler for sleepable raw tracepoints
selftests/bpf: Add tests for sleepable raw tracepoint programs
include/trace/bpf_probe.h | 2 -
kernel/bpf/syscall.c | 5 ++
kernel/bpf/verifier.c | 3 +-
kernel/trace/bpf_trace.c | 22 +++++++--
tools/lib/bpf/libbpf.c | 1 +
.../selftests/bpf/prog_tests/sleepable_raw_tp.c | 56 ++++++++++++++++++++++
.../selftests/bpf/progs/test_sleepable_raw_tp.c | 43 +++++++++++++++++
.../bpf/progs/test_sleepable_raw_tp_fail.c | 16 +++++++
tools/testing/selftests/bpf/verifier/sleepable.c | 5 +-
9 files changed, 143 insertions(+), 10 deletions(-)
---
base-commit: 4c51f90d45dca71e7974ed5a7c40b9c04a6c6762
change-id: 20260216-sleepable_tracepoints-381ae1410550
Best regards,
--
Mykyta Yatsenko <yatsenko@meta.com>