kernel/bpf/arraymap.c
Source file repositories/reference/linux-study-clean/kernel/bpf/arraymap.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/arraymap.c- Extension
.c- Size
- 39836 bytes
- Lines
- 1461
- 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.
- 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/err.hlinux/slab.hlinux/mm.hlinux/filter.hlinux/perf_event.huapi/linux/btf.hlinux/rcupdate_trace.hlinux/btf_ids.hcrypto/sha2.hmap_in_map.h
Detected Declarations
struct bpf_iter_seq_array_map_infostruct prog_poke_elemfunction Copyrightfunction bpf_array_alloc_percpufunction array_map_alloc_checkfunction array_map_get_hashfunction array_map_direct_value_addrfunction array_map_direct_value_metafunction array_map_gen_lookupfunction percpu_array_map_gen_lookupfunction bpf_percpu_array_copyfunction bpf_array_get_next_keyfunction array_map_update_elemfunction bpf_percpu_array_updatefunction array_map_delete_elemfunction array_map_free_internal_structsfunction array_map_freefunction for_each_possible_cpufunction array_map_seq_show_elemfunction percpu_array_map_seq_show_elemfunction array_map_check_btffunction array_map_mmapfunction array_map_meta_equalfunction __bpf_array_map_seq_showfunction for_each_possible_cpufunction bpf_array_map_seq_showfunction bpf_array_map_seq_stopfunction bpf_iter_init_array_mapfunction bpf_iter_fini_array_mapfunction bpf_for_each_array_elemfunction array_map_mem_usagefunction fd_array_map_alloc_checkfunction fd_array_map_freefunction bpf_fd_array_map_lookup_elemfunction bpf_fd_array_map_update_elemfunction __fd_array_map_delete_elemfunction fd_array_map_delete_elemfunction prog_fd_array_put_ptrfunction prog_fd_array_sys_lookup_elemfunction bpf_fd_array_map_clearfunction prog_array_map_seq_show_elemfunction prog_array_map_poke_trackfunction prog_array_map_poke_untrackfunction bpf_arch_poke_desc_updatefunction prog_array_map_poke_runfunction list_for_each_entryfunction prog_array_map_clear_deferredfunction prog_array_map_clear
Annotated Snippet
struct bpf_iter_seq_array_map_info {
struct bpf_map *map;
void *percpu_value_buf;
u32 index;
};
static void *bpf_array_map_seq_start(struct seq_file *seq, loff_t *pos)
{
struct bpf_iter_seq_array_map_info *info = seq->private;
struct bpf_map *map = info->map;
struct bpf_array *array;
u32 index;
if (info->index >= map->max_entries)
return NULL;
if (*pos == 0)
++*pos;
array = container_of(map, struct bpf_array, map);
index = info->index & array->index_mask;
if (info->percpu_value_buf)
return (void *)(uintptr_t)array->pptrs[index];
return array_map_elem_ptr(array, index);
}
static void *bpf_array_map_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
struct bpf_iter_seq_array_map_info *info = seq->private;
struct bpf_map *map = info->map;
struct bpf_array *array;
u32 index;
++*pos;
++info->index;
if (info->index >= map->max_entries)
return NULL;
array = container_of(map, struct bpf_array, map);
index = info->index & array->index_mask;
if (info->percpu_value_buf)
return (void *)(uintptr_t)array->pptrs[index];
return array_map_elem_ptr(array, index);
}
static int __bpf_array_map_seq_show(struct seq_file *seq, void *v)
{
struct bpf_iter_seq_array_map_info *info = seq->private;
struct bpf_iter__bpf_map_elem ctx = {};
struct bpf_map *map = info->map;
struct bpf_array *array = container_of(map, struct bpf_array, map);
struct bpf_iter_meta meta;
struct bpf_prog *prog;
int off = 0, cpu = 0;
void __percpu *pptr;
u32 size;
meta.seq = seq;
prog = bpf_iter_get_info(&meta, v == NULL);
if (!prog)
return 0;
ctx.meta = &meta;
ctx.map = info->map;
if (v) {
ctx.key = &info->index;
if (!info->percpu_value_buf) {
ctx.value = v;
} else {
pptr = (void __percpu *)(uintptr_t)v;
size = array->elem_size;
for_each_possible_cpu(cpu) {
copy_map_value_long(map, info->percpu_value_buf + off,
per_cpu_ptr(pptr, cpu));
check_and_init_map_value(map, info->percpu_value_buf + off);
off += size;
}
ctx.value = info->percpu_value_buf;
}
}
return bpf_iter_run_prog(prog, &ctx);
}
static int bpf_array_map_seq_show(struct seq_file *seq, void *v)
{
return __bpf_array_map_seq_show(seq, v);
}
static void bpf_array_map_seq_stop(struct seq_file *seq, void *v)
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/btf.h`, `linux/err.h`, `linux/slab.h`, `linux/mm.h`, `linux/filter.h`, `linux/perf_event.h`, `uapi/linux/btf.h`.
- Detected declarations: `struct bpf_iter_seq_array_map_info`, `struct prog_poke_elem`, `function Copyright`, `function bpf_array_alloc_percpu`, `function array_map_alloc_check`, `function array_map_get_hash`, `function array_map_direct_value_addr`, `function array_map_direct_value_meta`, `function array_map_gen_lookup`, `function percpu_array_map_gen_lookup`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- 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.