include/linux/filter.h
Source file repositories/reference/linux-study-clean/include/linux/filter.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/filter.h- Extension
.h- Size
- 53419 bytes
- Lines
- 1907
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- 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/atomic.hlinux/bpf.hlinux/refcount.hlinux/compat.hlinux/skbuff.hlinux/linkage.hlinux/printk.hlinux/workqueue.hlinux/sched.hlinux/sched/clock.hlinux/capability.hlinux/set_memory.hlinux/kallsyms.hlinux/if_vlan.hlinux/vmalloc.hlinux/sockptr.hlinux/u64_stats_sync.hnet/sch_generic.hasm/byteorder.huapi/linux/filter.h
Detected Declarations
struct sk_buffstruct sockstruct seccomp_datastruct bpf_prog_auxstruct xdp_rxq_infostruct xdp_buffstruct sock_reuseportstruct ctl_tablestruct ctl_table_headerstruct compat_sock_fprogstruct sock_fprog_kernstruct bpf_binary_headerstruct bpf_prog_statsstruct bpf_timed_may_gotostruct sk_filterstruct bpf_skb_data_endstruct bpf_nh_paramsstruct bpf_redirect_infostruct bpf_net_contextstruct bpf_sock_addr_kernstruct bpf_sock_ops_kernstruct bpf_sysctl_kernstruct bpf_sockopt_bufstruct bpf_sockopt_kernstruct bpf_sk_lookup_kernfunction insn_is_mov_percpu_addrfunction insn_is_zextfunction insn_is_cast_userfunction smp_store_releasefunction __bpf_prog_runfunction bpf_prog_runfunction bpf_prog_run_pin_on_cpufunction is_stack_arg_ldxfunction is_stack_arg_stfunction is_stack_arg_stxfunction bpf_net_ctx_clearfunction bpf_net_ctx_get_all_used_flush_listsfunction typesfunction bpf_prog_run_data_pointersfunction bpf_compute_and_save_data_endfunction bpf_restore_data_endfunction __bpf_prog_run_save_cbfunction bpf_prog_run_save_cbfunction bpf_prog_run_clear_cbfunction bpf_prog_insn_sizefunction bpf_prog_sizefunction bpf_prog_was_classicfunction bpf_ctx_off_adjust_machine
Annotated Snippet
struct compat_sock_fprog {
u16 len;
compat_uptr_t filter; /* struct sock_filter * */
};
struct sock_fprog_kern {
u16 len;
struct sock_filter *filter;
};
/* Some arches need doubleword alignment for their instructions and/or data */
#define BPF_IMAGE_ALIGNMENT 8
struct bpf_binary_header {
u32 size;
u8 image[] __aligned(BPF_IMAGE_ALIGNMENT);
};
struct bpf_prog_stats {
u64_stats_t cnt;
u64_stats_t nsecs;
u64_stats_t misses;
struct u64_stats_sync syncp;
} __aligned(2 * sizeof(u64));
struct bpf_timed_may_goto {
u64 count;
u64 timestamp;
};
struct sk_filter {
refcount_t refcnt;
struct rcu_head rcu;
struct bpf_prog *prog;
};
DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
extern struct mutex nf_conn_btf_access_lock;
extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log,
const struct bpf_reg_state *reg,
int off, int size);
typedef unsigned int (*bpf_dispatcher_fn)(const void *ctx,
const struct bpf_insn *insnsi,
unsigned int (*bpf_func)(const void *,
const struct bpf_insn *));
static __always_inline u32 __bpf_prog_run(const struct bpf_prog *prog,
const void *ctx,
bpf_dispatcher_fn dfunc)
{
u32 ret;
cant_migrate();
if (static_branch_unlikely(&bpf_stats_enabled_key)) {
struct bpf_prog_stats *stats;
u64 duration, start = sched_clock();
unsigned long flags;
ret = dfunc(ctx, prog->insnsi, prog->bpf_func);
duration = sched_clock() - start;
if (likely(prog->stats)) {
stats = this_cpu_ptr(prog->stats);
flags = u64_stats_update_begin_irqsave(&stats->syncp);
u64_stats_inc(&stats->cnt);
u64_stats_add(&stats->nsecs, duration);
u64_stats_update_end_irqrestore(&stats->syncp, flags);
}
} else {
ret = dfunc(ctx, prog->insnsi, prog->bpf_func);
}
return ret;
}
static __always_inline u32 bpf_prog_run(const struct bpf_prog *prog, const void *ctx)
{
return __bpf_prog_run(prog, ctx, bpf_dispatcher_nop_func);
}
/*
* Use in preemptible and therefore migratable context to make sure that
* the execution of the BPF program runs on one CPU.
*
* This uses migrate_disable/enable() explicitly to document that the
* invocation of a BPF program does not require reentrancy protection
* against a BPF program which is invoked from a preempting task.
*/
static inline u32 bpf_prog_run_pin_on_cpu(const struct bpf_prog *prog,
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/bpf.h`, `linux/refcount.h`, `linux/compat.h`, `linux/skbuff.h`, `linux/linkage.h`, `linux/printk.h`, `linux/workqueue.h`.
- Detected declarations: `struct sk_buff`, `struct sock`, `struct seccomp_data`, `struct bpf_prog_aux`, `struct xdp_rxq_info`, `struct xdp_buff`, `struct sock_reuseport`, `struct ctl_table`, `struct ctl_table_header`, `struct compat_sock_fprog`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.