public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/6] bpf: Add support for sleepable raw tracepoint programs
@ 2026-02-25 16:23 Mykyta Yatsenko
  2026-02-25 16:23 ` [PATCH bpf-next v2 1/6] bpf: Reject sleepable raw_tp programs on non-faultable tracepoints Mykyta Yatsenko
                   ` (5 more replies)
  0 siblings, 6 replies; 19+ messages in thread
From: Mykyta Yatsenko @ 2026-02-25 16:23 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, eddyz87; +Cc: Mykyta Yatsenko

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 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. This is a no-op until the verifier
allows sleepable raw_tp programs.

Patch 2 modifies __bpf_trace_run() to support sleepable programs:
use migrate_disable() instead of rcu_read_lock() 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.

Patch 3 removes preempt_disable from the faultable tracepoint BPF
callback wrapper, since preemption management is now handled
per-program inside __bpf_trace_run().

Patch 4 allows BPF_TRACE_RAW_TP programs to be loaded as sleepable.
All runtime infrastructure is in place at this point, ensuring no
bisectability issues.

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>
---
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 (6):
      bpf: Reject sleepable raw_tp programs on non-faultable tracepoints
      bpf: Add sleepable execution path for raw tracepoint programs
      bpf: Remove preempt_disable from faultable tracepoint BPF callbacks
      bpf: Allow sleepable programs for BPF_TRACE_RAW_TP attach type
      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                           | 20 ++++++--
 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, 142 insertions(+), 9 deletions(-)
---
base-commit: f620af11c27b8ec9994a39fe968aa778112d1566
change-id: 20260216-sleepable_tracepoints-381ae1410550

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


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

end of thread, other threads:[~2026-03-10 17:38 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 16:23 [PATCH bpf-next v2 0/6] bpf: Add support for sleepable raw tracepoint programs Mykyta Yatsenko
2026-02-25 16:23 ` [PATCH bpf-next v2 1/6] bpf: Reject sleepable raw_tp programs on non-faultable tracepoints Mykyta Yatsenko
2026-03-06  3:59   ` Kumar Kartikeya Dwivedi
2026-02-25 16:23 ` [PATCH bpf-next v2 2/6] bpf: Add sleepable execution path for raw tracepoint programs Mykyta Yatsenko
2026-02-25 17:12   ` bot+bpf-ci
2026-03-06  4:23     ` Kumar Kartikeya Dwivedi
2026-03-06  4:52       ` Kumar Kartikeya Dwivedi
2026-03-10 17:38         ` Yonghong Song
2026-02-25 16:23 ` [PATCH bpf-next v2 3/6] bpf: Remove preempt_disable from faultable tracepoint BPF callbacks Mykyta Yatsenko
2026-03-06  4:25   ` Kumar Kartikeya Dwivedi
2026-02-25 16:23 ` [PATCH bpf-next v2 4/6] bpf: Allow sleepable programs for BPF_TRACE_RAW_TP attach type Mykyta Yatsenko
2026-03-06  4:26   ` Kumar Kartikeya Dwivedi
2026-02-25 16:23 ` [PATCH bpf-next v2 5/6] libbpf: Add tp_btf.s section handler for sleepable raw tracepoints Mykyta Yatsenko
2026-03-06  4:26   ` Kumar Kartikeya Dwivedi
2026-02-25 16:23 ` [PATCH bpf-next v2 6/6] selftests/bpf: Add tests for sleepable raw tracepoint programs Mykyta Yatsenko
2026-03-06  4:41   ` Kumar Kartikeya Dwivedi
2026-03-06 23:56     ` Kumar Kartikeya Dwivedi
2026-03-09 21:11   ` Jiri Olsa
2026-03-10  0:22     ` Mykyta Yatsenko

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