kernel/bpf/stream.c
Source file repositories/reference/linux-study-clean/kernel/bpf/stream.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/stream.c- Extension
.c- Size
- 9531 bytes
- Lines
- 403
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/bpf.hlinux/filter.hlinux/bpf_mem_alloc.hlinux/gfp.hlinux/memory.hlinux/mutex.h
Detected Declarations
struct dump_stack_ctxfunction bpf_stream_elem_initfunction __bpf_stream_push_strfunction bpf_stream_consume_capacityfunction bpf_stream_release_capacityfunction bpf_stream_push_strfunction bpf_stream_free_elemfunction bpf_stream_free_listfunction bpf_stream_backlog_fillfunction bpf_stream_consume_elemfunction bpf_stream_readfunction bpf_prog_stream_readfunction bpf_stream_vprintkfunction bpf_stream_print_stackfunction bpf_prog_stream_initfunction bpf_prog_stream_freefunction bpf_stream_stage_initfunction bpf_stream_stage_freefunction bpf_stream_stage_printkfunction bpf_stream_stage_commitfunction dump_stack_cbfunction bpf_stream_stage_dump_stack
Annotated Snippet
struct dump_stack_ctx {
struct bpf_stream_stage *ss;
int err;
};
static bool dump_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp)
{
struct dump_stack_ctx *ctxp = cookie;
const char *file = "", *line = "";
struct bpf_prog *prog;
int num, ret;
rcu_read_lock();
prog = bpf_prog_ksym_find(ip);
rcu_read_unlock();
if (prog) {
ret = bpf_prog_get_file_line(prog, ip, &file, &line, &num);
if (ret < 0)
goto end;
ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n %s @ %s:%d\n",
(void *)(long)ip, line, file, num);
return !ctxp->err;
}
end:
ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n", (void *)(long)ip);
return !ctxp->err;
}
int bpf_stream_stage_dump_stack(struct bpf_stream_stage *ss)
{
struct dump_stack_ctx ctx = { .ss = ss };
int ret;
ret = bpf_stream_stage_printk(ss, "CPU: %d UID: %d PID: %d Comm: %s\n",
raw_smp_processor_id(), __kuid_val(current_real_cred()->euid),
current->pid, current->comm);
if (ret)
return ret;
ret = bpf_stream_stage_printk(ss, "Call trace:\n");
if (ret)
return ret;
arch_bpf_stack_walk(dump_stack_cb, &ctx);
if (ctx.err)
return ctx.err;
return bpf_stream_stage_printk(ss, "\n");
}
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/filter.h`, `linux/bpf_mem_alloc.h`, `linux/gfp.h`, `linux/memory.h`, `linux/mutex.h`.
- Detected declarations: `struct dump_stack_ctx`, `function bpf_stream_elem_init`, `function __bpf_stream_push_str`, `function bpf_stream_consume_capacity`, `function bpf_stream_release_capacity`, `function bpf_stream_push_str`, `function bpf_stream_free_elem`, `function bpf_stream_free_list`, `function bpf_stream_backlog_fill`, `function bpf_stream_consume_elem`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source 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.