arch/x86/net/bpf_jit_comp32.c
Source file repositories/reference/linux-study-clean/arch/x86/net/bpf_jit_comp32.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/net/bpf_jit_comp32.c- Extension
.c- Size
- 68189 bytes
- Lines
- 2599
- 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.
- 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.hasm/cacheflush.hasm/set_memory.hasm/nospec-branch.hasm/asm-prototypes.hlinux/bpf.h
Detected Declarations
struct jit_contextfunction Dumazetfunction is_imm8function is_simm32function add_1regfunction add_2regfunction jit_fill_holefunction emit_ia32_mov_ifunction emit_ia32_mov_rfunction emit_ia32_mov_r64function emit_ia32_mov_i64function operationfunction emit_ia32_to_le_r64function emit_ia32_to_be_r64function operationfunction operationfunction operationfunction emit_ia32_alu_r64function operationfunction emit_ia32_alu_i64function emit_ia32_neg64function emit_ia32_lsh_r64function emit_ia32_arsh_r64function emit_ia32_rsh_r64function emit_ia32_lsh_i64function emit_ia32_rsh_i64function emit_ia32_arsh_i64function emit_ia32_mul_r64function emit_ia32_mul_i64function bpf_size_to_x86_bytesfunction emit_prologuefunction emit_epiloguefunction emit_jmp_edxfunction emit_bpf_tail_callfunction emit_push_r64function emit_push_r32function get_cond_jmp_opcodefunction regparmfunction do_jitfunction bpf_jit_needs_zextfunction bpf_jit_supports_kfunc_call
Annotated Snippet
struct jit_context {
int cleanup_addr; /* Epilogue code offset */
};
/* Maximum number of bytes emitted while JITing one eBPF insn */
#define BPF_MAX_INSN_SIZE 128
#define BPF_INSN_SAFETY 64
#define PROLOGUE_SIZE 35
/*
* Emit prologue code for BPF program and check its size.
* bpf_tail_call helper will skip it while jumping into another program.
*/
static void emit_prologue(u8 **pprog, u32 stack_depth)
{
u8 *prog = *pprog;
int cnt = 0;
const u8 *r1 = bpf2ia32[BPF_REG_1];
const u8 fplo = bpf2ia32[BPF_REG_FP][0];
const u8 fphi = bpf2ia32[BPF_REG_FP][1];
const u8 *tcc = bpf2ia32[TCALL_CNT];
/* push ebp */
EMIT1(0x55);
/* mov ebp,esp */
EMIT2(0x89, 0xE5);
/* push edi */
EMIT1(0x57);
/* push esi */
EMIT1(0x56);
/* push ebx */
EMIT1(0x53);
/* sub esp,STACK_SIZE */
EMIT2_off32(0x81, 0xEC, STACK_SIZE);
/* sub ebp,SCRATCH_SIZE+12*/
EMIT3(0x83, add_1reg(0xE8, IA32_EBP), SCRATCH_SIZE + 12);
/* xor ebx,ebx */
EMIT2(0x31, add_2reg(0xC0, IA32_EBX, IA32_EBX));
/* Set up BPF prog stack base register */
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EBP), STACK_VAR(fplo));
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EBX), STACK_VAR(fphi));
/* Move BPF_CTX (EAX) to BPF_REG_R1 */
/* mov dword ptr [ebp+off],eax */
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EAX), STACK_VAR(r1[0]));
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EBX), STACK_VAR(r1[1]));
/* Initialize Tail Count */
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EBX), STACK_VAR(tcc[0]));
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EBX), STACK_VAR(tcc[1]));
BUILD_BUG_ON(cnt != PROLOGUE_SIZE);
*pprog = prog;
}
/* Emit epilogue code for BPF program */
static void emit_epilogue(u8 **pprog, u32 stack_depth)
{
u8 *prog = *pprog;
const u8 *r0 = bpf2ia32[BPF_REG_0];
int cnt = 0;
/* mov eax,dword ptr [ebp+off]*/
EMIT3(0x8B, add_2reg(0x40, IA32_EBP, IA32_EAX), STACK_VAR(r0[0]));
/* mov edx,dword ptr [ebp+off]*/
EMIT3(0x8B, add_2reg(0x40, IA32_EBP, IA32_EDX), STACK_VAR(r0[1]));
/* add ebp,SCRATCH_SIZE+12*/
EMIT3(0x83, add_1reg(0xC0, IA32_EBP), SCRATCH_SIZE + 12);
/* mov ebx,dword ptr [ebp-12]*/
EMIT3(0x8B, add_2reg(0x40, IA32_EBP, IA32_EBX), -12);
/* mov esi,dword ptr [ebp-8]*/
EMIT3(0x8B, add_2reg(0x40, IA32_EBP, IA32_ESI), -8);
/* mov edi,dword ptr [ebp-4]*/
EMIT3(0x8B, add_2reg(0x40, IA32_EBP, IA32_EDI), -4);
EMIT1(0xC9); /* leave */
EMIT1(0xC3); /* ret */
*pprog = prog;
}
static int emit_jmp_edx(u8 **pprog, u8 *ip)
{
u8 *prog = *pprog;
int cnt = 0;
Annotation
- Immediate include surface: `linux/netdevice.h`, `linux/filter.h`, `linux/if_vlan.h`, `asm/cacheflush.h`, `asm/set_memory.h`, `asm/nospec-branch.h`, `asm/asm-prototypes.h`, `linux/bpf.h`.
- Detected declarations: `struct jit_context`, `function Dumazet`, `function is_imm8`, `function is_simm32`, `function add_1reg`, `function add_2reg`, `function jit_fill_hole`, `function emit_ia32_mov_i`, `function emit_ia32_mov_r`, `function emit_ia32_mov_r64`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
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.