arch/x86/net/bpf_jit_comp.c
Source file repositories/reference/linux-study-clean/arch/x86/net/bpf_jit_comp.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/net/bpf_jit_comp.c- Extension
.c- Size
- 119025 bytes
- Lines
- 4223
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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/netdevice.hlinux/filter.hlinux/if_vlan.hlinux/bitfield.hlinux/bpf.hlinux/bpf_verifier.hlinux/memory.hlinux/sort.hasm/extable.hasm/ftrace.hasm/set_memory.hasm/nospec-branch.hasm/text-patching.hasm/unwind.hasm/cfi.h
Detected Declarations
struct jit_contextstruct x64_jit_datafunction is_imm8function roundfunction is_simm32function is_uimm32function bpf_size_to_x86_bytesfunction is_eregfunction is_ereg_8lfunction is_axregfunction add_1modfunction add_2modfunction add_3modfunction add_1regfunction add_2regfunction jit_fill_holefunction bpf_arch_text_invalidatefunction push_r9function pop_r9function push_r12function push_callee_regsfunction pop_r12function pop_callee_regsfunction emit_add_rspfunction emit_sub_rspfunction emit_nopsfunction emit_fineibtfunction emit_kcfifunction emit_cfifunction emit_prologue_tail_callfunction emit_prologuefunction emit_patchfunction emit_callfunction emit_rsb_callfunction emit_jumpfunction __bpf_arch_text_pokefunction bpf_arch_text_pokefunction __emit_indirect_jumpfunction emit_indirect_jumpfunction emit_returnfunction emit_bpf_tail_call_indirectfunction emit_bpf_tail_call_directfunction bpf_tail_call_direct_fixupfunction emit_mov_imm32function emit_mov_imm64function emit_mov_regfunction emit_movsx_regfunction emit_insn_suffix
Annotated Snippet
struct jit_context {
int cleanup_addr; /* Epilogue code offset */
/*
* Program specific offsets of labels in the code; these rely on the
* JIT doing at least 2 passes, recording the position on the first
* pass, only to generate the correct offset on the second pass.
*/
int tail_call_direct_label;
int tail_call_indirect_label;
};
/* Maximum number of bytes emitted while JITing one eBPF insn */
#define BPF_MAX_INSN_SIZE 128
#define BPF_INSN_SAFETY 64
/* Number of bytes emit_patch() needs to generate instructions */
#define X86_PATCH_SIZE 5
/* Number of bytes that will be skipped on tailcall */
#define X86_TAIL_CALL_OFFSET (12 + ENDBR_INSN_SIZE)
static void push_r9(u8 **pprog)
{
u8 *prog = *pprog;
EMIT2(0x41, 0x51); /* push r9 */
*pprog = prog;
}
static void pop_r9(u8 **pprog)
{
u8 *prog = *pprog;
EMIT2(0x41, 0x59); /* pop r9 */
*pprog = prog;
}
static void push_r12(u8 **pprog)
{
u8 *prog = *pprog;
EMIT2(0x41, 0x54); /* push r12 */
*pprog = prog;
}
static void push_callee_regs(u8 **pprog, bool *callee_regs_used)
{
u8 *prog = *pprog;
if (callee_regs_used[0])
EMIT1(0x53); /* push rbx */
if (callee_regs_used[1])
EMIT2(0x41, 0x55); /* push r13 */
if (callee_regs_used[2])
EMIT2(0x41, 0x56); /* push r14 */
if (callee_regs_used[3])
EMIT2(0x41, 0x57); /* push r15 */
*pprog = prog;
}
static void pop_r12(u8 **pprog)
{
u8 *prog = *pprog;
EMIT2(0x41, 0x5C); /* pop r12 */
*pprog = prog;
}
static void pop_callee_regs(u8 **pprog, bool *callee_regs_used)
{
u8 *prog = *pprog;
if (callee_regs_used[3])
EMIT2(0x41, 0x5F); /* pop r15 */
if (callee_regs_used[2])
EMIT2(0x41, 0x5E); /* pop r14 */
if (callee_regs_used[1])
EMIT2(0x41, 0x5D); /* pop r13 */
if (callee_regs_used[0])
EMIT1(0x5B); /* pop rbx */
*pprog = prog;
}
/* add rsp, depth */
static void emit_add_rsp(u8 **pprog, u16 depth)
{
u8 *prog = *pprog;
if (!depth)
return;
Annotation
- Immediate include surface: `linux/netdevice.h`, `linux/filter.h`, `linux/if_vlan.h`, `linux/bitfield.h`, `linux/bpf.h`, `linux/bpf_verifier.h`, `linux/memory.h`, `linux/sort.h`.
- Detected declarations: `struct jit_context`, `struct x64_jit_data`, `function is_imm8`, `function round`, `function is_simm32`, `function is_uimm32`, `function bpf_size_to_x86_bytes`, `function is_ereg`, `function is_ereg_8l`, `function is_axreg`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.