kernel/bpf/bpf_struct_ops.c
Source file repositories/reference/linux-study-clean/kernel/bpf/bpf_struct_ops.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/bpf_struct_ops.c- Extension
.c- Size
- 40957 bytes
- Lines
- 1530
- 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.
- 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/bpf_verifier.hlinux/btf.hlinux/filter.hlinux/slab.hlinux/numa.hlinux/seq_file.hlinux/refcount.hlinux/mutex.hlinux/btf_ids.hlinux/rcupdate_wait.hlinux/poll.h
Detected Declarations
struct bpf_struct_ops_valuestruct bpf_struct_ops_mapstruct bpf_struct_ops_linkfunction is_valid_value_typefunction bpf_struct_ops_image_freefunction prepare_arg_infofunction bpf_struct_ops_desc_releasefunction is_module_memberfunction bpf_struct_ops_supportedfunction bpf_struct_ops_desc_initfunction for_each_memberfunction bpf_struct_ops_map_get_next_keyfunction bpf_struct_ops_map_sys_lookup_elemfunction bpf_struct_ops_map_put_progsfunction bpf_struct_ops_map_dissoc_progsfunction bpf_struct_ops_map_free_imagefunction check_zero_holesfunction for_each_memberfunction bpf_struct_ops_link_releasefunction bpf_struct_ops_prepare_trampolinefunction bpf_struct_ops_ksym_initfunction bpf_struct_ops_map_add_ksymsfunction bpf_struct_ops_map_del_ksymsfunction bpf_struct_ops_map_free_ksymsfunction bpf_struct_ops_map_update_elemfunction bpf_struct_ops_map_delete_elemfunction bpf_struct_ops_map_seq_show_elemfunction __bpf_struct_ops_map_freefunction bpf_struct_ops_map_freefunction bpf_struct_ops_map_alloc_checkfunction count_func_ptrsfunction bpf_struct_ops_map_mem_usagefunction constfunction bpf_struct_ops_putfunction bpf_struct_ops_idfunction programsfunction bpf_struct_ops_valid_to_regfunction bpf_struct_ops_map_link_deallocfunction bpf_struct_ops_map_link_show_fdinfofunction bpf_struct_ops_map_link_fill_link_infofunction bpf_struct_ops_map_link_updatefunction bpf_struct_ops_map_link_detachfunction bpf_struct_ops_map_link_pollfunction bpf_struct_ops_link_createfunction bpf_prog_assoc_struct_opsfunction bpf_prog_disassoc_struct_opsfunction structfunction bpf_map_struct_ops_info_fill
Annotated Snippet
struct bpf_struct_ops_value {
struct bpf_struct_ops_common_value common;
char data[] ____cacheline_aligned_in_smp;
};
#define MAX_TRAMP_IMAGE_PAGES 8
struct bpf_struct_ops_map {
struct bpf_map map;
const struct bpf_struct_ops_desc *st_ops_desc;
/* protect map_update */
struct mutex lock;
/* link has all the bpf_links that is populated
* to the func ptr of the kernel's struct
* (in kvalue.data).
*/
struct bpf_link **links;
/* ksyms for bpf trampolines */
struct bpf_ksym **ksyms;
u32 funcs_cnt;
u32 image_pages_cnt;
/* image_pages is an array of pages that has all the trampolines
* that stores the func args before calling the bpf_prog.
*/
void *image_pages[MAX_TRAMP_IMAGE_PAGES];
/* The owner moduler's btf. */
struct btf *btf;
/* uvalue->data stores the kernel struct
* (e.g. tcp_congestion_ops) that is more useful
* to userspace than the kvalue. For example,
* the bpf_prog's id is stored instead of the kernel
* address of a func ptr.
*/
struct bpf_struct_ops_value *uvalue;
/* kvalue.data stores the actual kernel's struct
* (e.g. tcp_congestion_ops) that will be
* registered to the kernel subsystem.
*/
struct bpf_struct_ops_value kvalue;
};
struct bpf_struct_ops_link {
struct bpf_link link;
struct bpf_map __rcu *map;
wait_queue_head_t wait_hup;
};
static DEFINE_MUTEX(update_mutex);
#define VALUE_PREFIX "bpf_struct_ops_"
#define VALUE_PREFIX_LEN (sizeof(VALUE_PREFIX) - 1)
const struct bpf_verifier_ops bpf_struct_ops_verifier_ops = {
};
const struct bpf_prog_ops bpf_struct_ops_prog_ops = {
#ifdef CONFIG_NET
.test_run = bpf_struct_ops_test_run,
#endif
};
BTF_ID_LIST(st_ops_ids)
BTF_ID(struct, module)
BTF_ID(struct, bpf_struct_ops_common_value)
enum {
IDX_MODULE_ID,
IDX_ST_OPS_COMMON_VALUE_ID,
};
extern struct btf *btf_vmlinux;
static bool is_valid_value_type(struct btf *btf, s32 value_id,
const struct btf_type *type,
const char *value_name)
{
const struct btf_type *common_value_type;
const struct btf_member *member;
const struct btf_type *vt, *mt;
vt = btf_type_by_id(btf, value_id);
if (btf_vlen(vt) != 2) {
pr_warn("The number of %s's members should be 2, but we get %d\n",
value_name, btf_vlen(vt));
return false;
}
member = btf_type_member(vt);
mt = btf_type_by_id(btf, member->type);
common_value_type = btf_type_by_id(btf_vmlinux,
st_ops_ids[IDX_ST_OPS_COMMON_VALUE_ID]);
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/bpf_verifier.h`, `linux/btf.h`, `linux/filter.h`, `linux/slab.h`, `linux/numa.h`, `linux/seq_file.h`, `linux/refcount.h`.
- Detected declarations: `struct bpf_struct_ops_value`, `struct bpf_struct_ops_map`, `struct bpf_struct_ops_link`, `function is_valid_value_type`, `function bpf_struct_ops_image_free`, `function prepare_arg_info`, `function bpf_struct_ops_desc_release`, `function is_module_member`, `function bpf_struct_ops_supported`, `function bpf_struct_ops_desc_init`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.