arch/riscv/net/bpf_jit_comp64.c
Source file repositories/reference/linux-study-clean/arch/riscv/net/bpf_jit_comp64.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/net/bpf_jit_comp64.c- Extension
.c- Size
- 57915 bytes
- Lines
- 2160
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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.
- 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/bitfield.hlinux/bpf.hlinux/filter.hlinux/memory.hlinux/stop_machine.hasm/text-patching.hasm/cfi.hasm/percpu.hbpf_jit.h
Detected Declarations
function bpf_to_rv_regfunction seen_regfunction mark_fpfunction mark_callfunction seen_callfunction mark_tail_callfunction seen_tail_callfunction rv_tail_call_regfunction is_32b_intfunction in_auipc_jalr_rangefunction emit_sextw_altfunction emit_zextw_altfunction emit_addrfunction emit_immfunction __build_epiloguefunction emit_bccfunction emit_branchfunction emit_bpf_tail_callfunction init_regsfunction emit_jump_and_linkfunction is_signed_bpf_condfunction emit_callfunction emit_kcfifunction emit_ldx_insnfunction emit_stx_insnfunction emit_ldxfunction emit_stfunction emit_stxfunction emit_atomic_ld_stfunction emit_atomic_rmwfunction sign_extendfunction ex_handler_bpffunction add_exception_handlerfunction gen_jump_or_nopsfunction bpf_arch_text_pokefunction store_argsfunction restore_argsfunction restore_stack_argsfunction emit_store_stack_imm64function invoke_bpf_progfunction invoke_bpffunction __arch_prepare_bpf_trampolinefunction arch_bpf_trampoline_sizefunction arch_free_bpf_trampolinefunction arch_prepare_bpf_trampolinefunction bpf_jit_emit_insnfunction tofunction bpf_jit_build_prologue
Annotated Snippet
if (!upper) {
emit_li(rd, lower, ctx);
return;
}
emit_addiw(rd, rd, lower, ctx);
return;
}
shift = __ffs(upper);
upper >>= shift;
shift += 12;
emit_imm(rd, upper, ctx);
emit_slli(rd, rd, shift, ctx);
if (lower)
emit_addi(rd, rd, lower, ctx);
}
static void __build_epilogue(bool is_tail_call, struct rv_jit_context *ctx)
{
int stack_adjust = ctx->stack_size, store_offset = stack_adjust - 8;
if (seen_reg(RV_REG_RA, ctx)) {
emit_ld(RV_REG_RA, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
emit_ld(RV_REG_FP, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
if (seen_reg(RV_REG_S1, ctx)) {
emit_ld(RV_REG_S1, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
if (seen_reg(RV_REG_S2, ctx)) {
emit_ld(RV_REG_S2, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
if (seen_reg(RV_REG_S3, ctx)) {
emit_ld(RV_REG_S3, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
if (seen_reg(RV_REG_S4, ctx)) {
emit_ld(RV_REG_S4, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
if (seen_reg(RV_REG_S5, ctx)) {
emit_ld(RV_REG_S5, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
if (seen_reg(RV_REG_S6, ctx)) {
emit_ld(RV_REG_S6, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
if (ctx->arena_vm_start) {
emit_ld(RV_REG_ARENA, store_offset, RV_REG_SP, ctx);
store_offset -= 8;
}
emit_addi(RV_REG_SP, RV_REG_SP, stack_adjust, ctx);
/* Set return value. */
if (!is_tail_call)
emit_addiw(RV_REG_A0, RV_REG_A5, 0, ctx);
emit_jalr(RV_REG_ZERO, is_tail_call ? RV_REG_T3 : RV_REG_RA,
/* kcfi, fentry and TCC init insns will be skipped on tailcall */
is_tail_call ? (RV_KCFI_NINSNS + RV_FENTRY_NINSNS + 1) * 4 : 0,
ctx);
}
static void emit_bcc(u8 cond, u8 rd, u8 rs, int rvoff,
struct rv_jit_context *ctx)
{
switch (cond) {
case BPF_JEQ:
emit(rv_beq(rd, rs, rvoff >> 1), ctx);
return;
case BPF_JGT:
emit(rv_bltu(rs, rd, rvoff >> 1), ctx);
return;
case BPF_JLT:
emit(rv_bltu(rd, rs, rvoff >> 1), ctx);
return;
case BPF_JGE:
emit(rv_bgeu(rd, rs, rvoff >> 1), ctx);
return;
case BPF_JLE:
emit(rv_bgeu(rs, rd, rvoff >> 1), ctx);
return;
case BPF_JNE:
emit(rv_bne(rd, rs, rvoff >> 1), ctx);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bpf.h`, `linux/filter.h`, `linux/memory.h`, `linux/stop_machine.h`, `asm/text-patching.h`, `asm/cfi.h`, `asm/percpu.h`.
- Detected declarations: `function bpf_to_rv_reg`, `function seen_reg`, `function mark_fp`, `function mark_call`, `function seen_call`, `function mark_tail_call`, `function seen_tail_call`, `function rv_tail_call_reg`, `function is_32b_int`, `function in_auipc_jalr_range`.
- Atlas domain: Architecture Layer / arch/riscv.
- 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.