arch/mips/net/bpf_jit_comp.c
Source file repositories/reference/linux-study-clean/arch/mips/net/bpf_jit_comp.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/net/bpf_jit_comp.c- Extension
.c- Size
- 26246 bytes
- Lines
- 1022
- Domain
- Architecture Layer
- Bucket
- arch/mips
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/limits.hlinux/bitops.hlinux/errno.hlinux/filter.hlinux/bpf.hlinux/slab.hasm/bitops.hasm/cacheflush.hasm/cpu-features.hasm/isa-rev.hasm/uasm.hbpf_jit_comp.h
Detected Declarations
function Copyrightfunction pop_regsfunction get_targetfunction get_offsetfunction emit_mov_ifunction emit_mov_rfunction valid_alu_ifunction rewrite_alu_ifunction emit_alu_ifunction emit_alu_rfunction emit_atomic_rfunction emit_cmpxchg_rfunction emit_bswap_rfunction valid_jmp_ifunction invert_jmpfunction setup_jmpfunction setup_jmp_ifunction setup_jmp_rfunction finish_jmpfunction emit_jmp_ifunction emit_jmp_rfunction emit_jafunction emit_exitfunction build_bodyfunction set_convert_flagfunction jit_fill_holefunction bpf_jit_needs_zext
Annotated Snippet
if (mask & BIT(reg)) {
if ((excl & BIT(reg)) == 0) {
if (sizeof(long) == 4)
emit(ctx, sw, reg, depth, MIPS_R_SP);
else /* sizeof(long) == 8 */
emit(ctx, sd, reg, depth, MIPS_R_SP);
}
depth += sizeof(long);
}
ctx->stack_used = max((int)ctx->stack_used, depth);
return depth;
}
/*
* Pop registers from the stack, starting at a given depth from the stack
* pointer and increasing. The next depth to be read is returned.
*/
int pop_regs(struct jit_context *ctx, u32 mask, u32 excl, int depth)
{
int reg;
for (reg = 0; reg < BITS_PER_BYTE * sizeof(mask); reg++)
if (mask & BIT(reg)) {
if ((excl & BIT(reg)) == 0) {
if (sizeof(long) == 4)
emit(ctx, lw, reg, depth, MIPS_R_SP);
else /* sizeof(long) == 8 */
emit(ctx, ld, reg, depth, MIPS_R_SP);
}
depth += sizeof(long);
}
return depth;
}
/* Compute the 28-bit jump target address from a BPF program location */
int get_target(struct jit_context *ctx, u32 loc)
{
u32 index = INDEX(ctx->descriptors[loc]);
unsigned long pc = (unsigned long)&ctx->target[ctx->jit_index];
unsigned long addr = (unsigned long)&ctx->target[index];
if (!ctx->target)
return 0;
if ((addr ^ pc) & ~MIPS_JMP_MASK)
return -1;
return addr & MIPS_JMP_MASK;
}
/* Compute the PC-relative offset to relative BPF program offset */
int get_offset(const struct jit_context *ctx, int off)
{
return (INDEX(ctx->descriptors[ctx->bpf_index + off]) -
ctx->jit_index - 1) * sizeof(u32);
}
/* dst = imm (register width) */
void emit_mov_i(struct jit_context *ctx, u8 dst, s32 imm)
{
if (imm >= -0x8000 && imm <= 0x7fff) {
emit(ctx, addiu, dst, MIPS_R_ZERO, imm);
} else {
emit(ctx, lui, dst, (s16)((u32)imm >> 16));
emit(ctx, ori, dst, dst, (u16)(imm & 0xffff));
}
clobber_reg(ctx, dst);
}
/* dst = src (register width) */
void emit_mov_r(struct jit_context *ctx, u8 dst, u8 src)
{
emit(ctx, ori, dst, src, 0);
clobber_reg(ctx, dst);
}
/* Validate ALU immediate range */
bool valid_alu_i(u8 op, s32 imm)
{
switch (BPF_OP(op)) {
case BPF_NEG:
case BPF_LSH:
case BPF_RSH:
case BPF_ARSH:
/* All legal eBPF values are valid */
return true;
case BPF_ADD:
if (IS_ENABLED(CONFIG_CPU_DADDI_WORKAROUNDS))
Annotation
- Immediate include surface: `linux/limits.h`, `linux/bitops.h`, `linux/errno.h`, `linux/filter.h`, `linux/bpf.h`, `linux/slab.h`, `asm/bitops.h`, `asm/cacheflush.h`.
- Detected declarations: `function Copyright`, `function pop_regs`, `function get_target`, `function get_offset`, `function emit_mov_i`, `function emit_mov_r`, `function valid_alu_i`, `function rewrite_alu_i`, `function emit_alu_i`, `function emit_alu_r`.
- Atlas domain: Architecture Layer / arch/mips.
- 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.