kernel/bpf/arena.c
Source file repositories/reference/linux-study-clean/kernel/bpf/arena.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/arena.c- Extension
.c- Size
- 34798 bytes
- Lines
- 1194
- 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/btf.hlinux/cacheflush.hlinux/err.hlinux/irq_work.hlinux/filter.hlinux/llist.hlinux/btf_ids.hlinux/vmalloc.hlinux/pagemap.hasm/tlbflush.hrange_tree.h
Detected Declarations
struct bpf_arenastruct arena_free_spanstruct apply_range_datastruct clear_range_datastruct vma_listfunction bpf_arena_get_kern_vm_startfunction bpf_arena_get_user_vm_startfunction bpf_arena_map_kern_vm_startfunction arena_map_peek_elemfunction arena_map_push_elemfunction arena_map_pop_elemfunction arena_map_delete_elemfunction arena_map_get_next_keyfunction compute_pgofffunction apply_range_set_cbfunction architecturesfunction flush_vmap_cachefunction apply_range_clear_cbfunction apply_range_set_scratch_cbfunction populate_pgtable_except_ptefunction existing_page_cbfunction arena_map_freefunction arena_map_update_elemfunction arena_map_check_btffunction arena_map_mem_usagefunction remember_vmafunction arena_vm_openfunction arena_vm_may_splitfunction arena_vm_mremapfunction arena_vm_closefunction arena_vm_faultfunction arena_get_unmapped_areafunction arena_map_mmapfunction arena_map_direct_value_addrfunction clear_lo32function arena_alloc_pagesfunction zap_pagesfunction list_for_each_entryfunction arena_free_pagesfunction llist_for_each_safefunction arena_reserve_pagesfunction arena_free_workerfunction arena_free_irqfunction bpf_arena_free_pagesfunction bpf_arena_free_pages_non_sleepablefunction bpf_arena_reserve_pagesfunction kfunc_initfunction __bpf_prog_report_arena_violation
Annotated Snippet
struct bpf_arena {
struct bpf_map map;
u64 user_vm_start;
u64 user_vm_end;
struct vm_struct *kern_vm;
struct page *scratch_page;
struct range_tree rt;
/* protects rt */
rqspinlock_t spinlock;
struct list_head vma_list;
/* protects vma_list */
struct mutex lock;
u64 zap_gen;
struct mutex zap_mutex;
struct irq_work free_irq;
struct work_struct free_work;
struct llist_head free_spans;
};
static void arena_free_worker(struct work_struct *work);
static void arena_free_irq(struct irq_work *iw);
struct arena_free_span {
struct llist_node node;
unsigned long uaddr;
u32 page_cnt;
};
u64 bpf_arena_get_kern_vm_start(struct bpf_arena *arena)
{
return arena ? (u64) (long) arena->kern_vm->addr + GUARD_SZ / 2 : 0;
}
u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena)
{
return arena ? arena->user_vm_start : 0;
}
/**
* bpf_arena_map_kern_vm_start - kern_vm_start lookup by struct bpf_map *
* @map: a BPF_MAP_TYPE_ARENA map
*
* Return @map's kern_vm_start.
*/
u64 bpf_arena_map_kern_vm_start(struct bpf_map *map)
{
return bpf_arena_get_kern_vm_start(container_of(map, struct bpf_arena, map));
}
/**
* bpf_prog_arena - return the bpf_map of the arena referenced by @prog
* @prog: a loaded BPF program
*
* The verifier enforces at most one arena per program and stores it in
* prog->aux->arena. Return that arena's underlying bpf_map, or NULL if
* @prog does not reference an arena.
*/
struct bpf_map *bpf_prog_arena(struct bpf_prog *prog)
{
struct bpf_arena *arena = prog->aux->arena;
return arena ? &arena->map : NULL;
}
static long arena_map_peek_elem(struct bpf_map *map, void *value)
{
return -EOPNOTSUPP;
}
static long arena_map_push_elem(struct bpf_map *map, void *value, u64 flags)
{
return -EOPNOTSUPP;
}
static long arena_map_pop_elem(struct bpf_map *map, void *value)
{
return -EOPNOTSUPP;
}
static long arena_map_delete_elem(struct bpf_map *map, void *value)
{
return -EOPNOTSUPP;
}
static int arena_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
{
return -EOPNOTSUPP;
}
static long compute_pgoff(struct bpf_arena *arena, long uaddr)
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/btf.h`, `linux/cacheflush.h`, `linux/err.h`, `linux/irq_work.h`, `linux/filter.h`, `linux/llist.h`, `linux/btf_ids.h`.
- Detected declarations: `struct bpf_arena`, `struct arena_free_span`, `struct apply_range_data`, `struct clear_range_data`, `struct vma_list`, `function bpf_arena_get_kern_vm_start`, `function bpf_arena_get_user_vm_start`, `function bpf_arena_map_kern_vm_start`, `function arena_map_peek_elem`, `function arena_map_push_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.