public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/4] bpf: Add support for sleepable raw tracepoint programs
@ 2026-03-11 18:22 Mykyta Yatsenko
  2026-03-11 18:22 ` [PATCH bpf-next v3 1/4] bpf: Add sleepable execution path for " Mykyta Yatsenko
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Mykyta Yatsenko @ 2026-03-11 18:22 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, eddyz87
  Cc: Mykyta Yatsenko, Kumar Kartikeya Dwivedi

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 inside __bpf_trace_run(), 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 modifies __bpf_trace_run() to support sleepable programs:
use migrate_disable() for per-CPU data protection on both paths,
adding rcu_read_lock() only for non-sleepable programs. For sleepable
programs, call might_fault() to annotate faultable context and rely
on the outer rcu_tasks_trace lock from the faultable tracepoint
callback for program lifetime protection. Also removes
preempt_disable from the faultable tracepoint BPF callback wrapper,
since per-CPU protection and RCU locking are now managed per-program
inside __bpf_trace_run().

Patch 2 allows BPF_TRACE_RAW_TP programs to be loaded as sleepable,
and adds a load-time check in bpf_check_attach_target() to reject
sleepable programs targeting non-faultable tracepoints with a
verifier error message.

Patch 3 adds the tp_btf.s section handler in libbpf, following the
existing pattern of fentry.s/fexit.s/lsm.s.

Patch 4 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
at load time via RUN_TESTS).

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
Changes in v3:
  - Moved faultable tracepoint check from attach time to load time in
    bpf_check_attach_target(), providing a clear verifier error message
  - Removed cant_sleep() call from non-sleepable path in
    __bpf_trace_run()
  - Folded preempt_disable removal into the sleepable execution path
    patch
  - Used RUN_TESTS() with __failure/__msg for negative test case instead
    of explicit userspace program
  - Reduced series from 6 patches to 4
  - Link to v2: https://lore.kernel.org/r/20260225-sleepable_tracepoints-v2-0-0330dafd650f@meta.com

Changes in v2:
  - Address AI review points - modified the order of the patches
  - Link to v1: https://lore.kernel.org/bpf/20260218-sleepable_tracepoints-v1-0-ec2705497208@meta.com/

---
Mykyta Yatsenko (4):
      bpf: Add sleepable execution path for raw tracepoint programs
      bpf: Verifier support for sleepable 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/verifier.c                              |  9 ++++-
 kernel/trace/bpf_trace.c                           | 13 +++++--
 tools/lib/bpf/libbpf.c                             |  1 +
 .../selftests/bpf/prog_tests/sleepable_raw_tp.c    | 40 ++++++++++++++++++++
 .../selftests/bpf/progs/test_sleepable_raw_tp.c    | 43 ++++++++++++++++++++++
 .../bpf/progs/test_sleepable_raw_tp_fail.c         | 18 +++++++++
 tools/testing/selftests/bpf/verifier/sleepable.c   | 17 ++++++++-
 8 files changed, 135 insertions(+), 8 deletions(-)
---
base-commit: bd2e02e3c9215305dfa344c050d5822f19929cf7
change-id: 20260216-sleepable_tracepoints-381ae1410550

Best regards,
-- 
Mykyta Yatsenko <yatsenko@meta.com>


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2026-03-12 21:03 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 18:22 [PATCH bpf-next v3 0/4] bpf: Add support for sleepable raw tracepoint programs Mykyta Yatsenko
2026-03-11 18:22 ` [PATCH bpf-next v3 1/4] bpf: Add sleepable execution path for " Mykyta Yatsenko
2026-03-11 19:25   ` Emil Tsalapatis
2026-03-11 23:39   ` Puranjay Mohan
2026-03-12 20:51   ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 2/4] bpf: Verifier support for sleepable " Mykyta Yatsenko
2026-03-11 18:49   ` Emil Tsalapatis
2026-03-11 18:53   ` bot+bpf-ci
2026-03-11 23:07     ` Kumar Kartikeya Dwivedi
2026-03-12  5:50       ` Leon Hwang
2026-03-12  6:21         ` Menglong Dong
2026-03-12  6:43           ` Leon Hwang
2026-03-11 23:08   ` Kumar Kartikeya Dwivedi
2026-03-11 23:40   ` Puranjay Mohan
2026-03-12 20:59   ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 3/4] libbpf: Add tp_btf.s section handler for sleepable raw tracepoints Mykyta Yatsenko
2026-03-11 18:54   ` Emil Tsalapatis
2026-03-11 23:40   ` Puranjay Mohan
2026-03-12 20:59   ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 4/4] selftests/bpf: Add tests for sleepable raw tracepoint programs Mykyta Yatsenko
2026-03-11 19:12   ` Emil Tsalapatis
2026-03-11 23:41   ` Puranjay Mohan
2026-03-12 21:03   ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox