bpf: Add support for sleepable raw tracepoint programs#11100
bpf: Add support for sleepable raw tracepoint programs#11100kernel-patches-daemon-bpf[bot] wants to merge 6 commits intobpf-next_basefrom
Conversation
Add BPF_TRACE_RAW_TP to the set of tracing program attach types that can be loaded as sleepable in can_be_sleepable(). The actual enforcement that the target tracepoint supports sleepable execution (i.e., is faultable) is deferred to attach time, since the target tracepoint is not known at program load time. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Add an attach-time check in bpf_raw_tp_link_attach() to ensure that sleepable BPF programs can only attach to faultable tracepoints. Faultable tracepoints (e.g., sys_enter, sys_exit) are guaranteed to run in a context where sleeping is safe, using rcu_tasks_trace for protection. Non-faultable tracepoints may run in NMI or other non-sleepable contexts. This complements the verifier-side change that allows BPF_TRACE_RAW_TP programs to be loaded as sleepable. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Remove preempt_disable_notrace()/preempt_enable_notrace() from __BPF_DECLARE_TRACE_SYSCALL, the BPF probe callback wrapper for faultable (syscall) tracepoints. The preemption management is now handled inside __bpf_trace_run() on a per-program basis: migrate_disable() for sleepable programs, rcu_read_lock() (which implies preempt-off in non-PREEMPT_RCU configs) for non-sleepable programs. This allows sleepable BPF programs to actually sleep when attached to faultable tracepoints. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Modify __bpf_trace_run() to support both sleepable and non-sleepable BPF programs. When the program is sleepable: - Skip cant_sleep() and instead call might_fault() to annotate the faultable context - Use migrate_disable()/migrate_enable() instead of rcu_read_lock()/rcu_read_unlock() to allow sleeping while still protecting percpu data access - The outer rcu_tasks_trace lock is already held by the faultable tracepoint callback (__DECLARE_TRACE_SYSCALL), providing lifetime protection for the BPF program For non-sleepable programs, behavior is unchanged: cant_sleep() check, rcu_read_lock() protection. This allows multiple BPF programs with different sleepable settings to coexist on the same faultable tracepoint, since __bpf_trace_run() is invoked per-link. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Add SEC_DEF for "tp_btf.s+" section prefix, enabling userspace BPF
programs to use SEC("tp_btf.s/<tracepoint>") to load sleepable raw
tracepoint programs. This follows the existing pattern used for
fentry.s, fexit.s, fmod_ret.s, and lsm.s section definitions.
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Add two subtests: - success: Attach a sleepable BPF program to the faultable sys_enter tracepoint (tp_btf.s/sys_enter). Verify the program is triggered by a syscall. - reject_non_faultable: Attempt to attach a sleepable BPF program to a non-faultable tracepoint (tp_btf.s/sched_switch). Verify that attachment is rejected. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
|
Upstream branch: 4c51f90 |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: AI-authorship-score: medium |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: AI-authorship-score: low |
|
Forwarding comment 3921845974 via email |
|
Forwarding comment 3921864733 via email |
|
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1055256 expired. Closing PR. |
Pull request for series with
subject: bpf: Add support for sleepable raw tracepoint programs
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1055256