kernel/trace/bpf_trace.c
Source file repositories/reference/linux-study-clean/kernel/trace/bpf_trace.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/bpf_trace.c- Extension
.c- Size
- 102080 bytes
- Lines
- 3880
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/types.hlinux/slab.hlinux/bpf.hlinux/bpf_verifier.hlinux/bpf_perf_event.hlinux/btf.hlinux/filter.hlinux/uaccess.hlinux/ctype.hlinux/kprobes.hlinux/spinlock.hlinux/syscalls.hlinux/error-injection.hlinux/btf_ids.hlinux/bpf_lsm.hlinux/fprobe.hlinux/bsearch.hlinux/sort.hlinux/key.hlinux/namei.hlinux/file.hnet/bpf_sk_storage.huapi/linux/bpf.huapi/linux/btf.hasm/tlb.htrace_probe.htrace.hbpf_trace.h
Detected Declarations
struct bpf_trace_modulestruct bpf_trace_sample_datastruct bpf_nested_pt_regsstruct send_signal_irq_workstruct bpf_raw_tp_regsstruct bpf_session_run_ctxstruct bpf_kprobe_multi_linkstruct bpf_kprobe_multi_run_ctxstruct user_symsstruct multi_symbols_sortstruct modules_arraystruct bpf_uprobe_multi_linkstruct bpf_uprobestruct bpf_uprobe_multi_linkstruct bpf_uprobe_multi_run_ctxfunction trace_call_bpffunction trace_call_bpffunction bpf_probe_read_user_commonfunction bpf_probe_read_user_str_commonfunction bpf_probe_read_kernel_str_commonfunction __set_printk_clr_eventfunction get_map_perf_counterfunction __bpf_perf_event_outputfunction bpf_event_outputfunction do_bpf_send_signalfunction bpf_send_signal_commonfunction bpf_d_path_allowedfunction bpf_btf_printf_preparefunction get_entry_ipfunction bpf_tracing_func_protofunction is_kprobe_multifunction is_kprobe_sessionfunction is_uprobe_multifunction is_uprobe_sessionfunction is_trace_fsessionfunction kprobe_prog_func_protofunction kprobe_prog_is_valid_accessfunction tp_prog_func_protofunction tp_prog_is_valid_accessfunction pe_prog_func_protofunction put_bpf_raw_tp_regsfunction raw_tp_prog_func_protofunction tracing_prog_func_protofunction raw_tp_prog_is_valid_accessfunction tracing_prog_is_valid_accessfunction bpf_prog_test_run_tracingfunction raw_tp_writable_prog_is_valid_accessfunction pe_prog_is_valid_access
Annotated Snippet
subsys_initcall(send_signal_irq_work_init);
#ifdef CONFIG_MODULES
static int bpf_event_notify(struct notifier_block *nb, unsigned long op,
void *module)
{
struct bpf_trace_module *btm, *tmp;
struct module *mod = module;
int ret = 0;
if (mod->num_bpf_raw_events == 0 ||
(op != MODULE_STATE_COMING && op != MODULE_STATE_GOING))
goto out;
mutex_lock(&bpf_module_mutex);
switch (op) {
case MODULE_STATE_COMING:
btm = kzalloc_obj(*btm);
if (btm) {
btm->module = module;
list_add(&btm->list, &bpf_trace_modules);
} else {
ret = -ENOMEM;
}
break;
case MODULE_STATE_GOING:
list_for_each_entry_safe(btm, tmp, &bpf_trace_modules, list) {
if (btm->module == module) {
list_del(&btm->list);
kfree(btm);
break;
}
}
break;
}
mutex_unlock(&bpf_module_mutex);
out:
return notifier_from_errno(ret);
}
static struct notifier_block bpf_module_nb = {
.notifier_call = bpf_event_notify,
};
static int __init bpf_event_init(void)
{
register_module_notifier(&bpf_module_nb);
return 0;
}
fs_initcall(bpf_event_init);
#endif /* CONFIG_MODULES */
struct bpf_session_run_ctx {
struct bpf_run_ctx run_ctx;
bool is_return;
void *data;
};
#ifdef CONFIG_FPROBE
struct bpf_kprobe_multi_link {
struct bpf_link link;
struct fprobe fp;
unsigned long *addrs;
u64 *cookies;
u32 cnt;
u32 mods_cnt;
struct module **mods;
};
struct bpf_kprobe_multi_run_ctx {
struct bpf_session_run_ctx session_ctx;
struct bpf_kprobe_multi_link *link;
unsigned long entry_ip;
};
struct user_syms {
const char **syms;
char *buf;
};
#ifndef CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS
static DEFINE_PER_CPU(struct pt_regs, bpf_kprobe_multi_pt_regs);
#define bpf_kprobe_multi_pt_regs_ptr() this_cpu_ptr(&bpf_kprobe_multi_pt_regs)
#else
#define bpf_kprobe_multi_pt_regs_ptr() (NULL)
#endif
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/slab.h`, `linux/bpf.h`, `linux/bpf_verifier.h`, `linux/bpf_perf_event.h`, `linux/btf.h`, `linux/filter.h`.
- Detected declarations: `struct bpf_trace_module`, `struct bpf_trace_sample_data`, `struct bpf_nested_pt_regs`, `struct send_signal_irq_work`, `struct bpf_raw_tp_regs`, `struct bpf_session_run_ctx`, `struct bpf_kprobe_multi_link`, `struct bpf_kprobe_multi_run_ctx`, `struct user_syms`, `struct multi_symbols_sort`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.