arch/loongarch/net/bpf_jit.c
Source file repositories/reference/linux-study-clean/arch/loongarch/net/bpf_jit.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/net/bpf_jit.c- Extension
.c- Size
- 64985 bytes
- Lines
- 2370
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- 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/memory.hbpf_jit.h
Detected Declarations
function prepare_bpf_tail_call_cntfunction build_prologuefunction __build_epiloguefunction build_epiloguefunction bpf_jit_supports_kfunc_callfunction bpf_jit_supports_far_kfunc_callfunction emit_bpf_tail_callfunction emit_store_stack_imm64function emit_atomic_rmwfunction emit_atomic_ld_stfunction is_signed_bpf_condfunction ex_handler_bpffunction add_exception_handlerfunction build_insnfunction build_bodyfunction jit_fill_holefunction validate_codefunction validate_ctxfunction emit_jump_and_linkfunction emit_jump_or_nopsfunction emit_callfunction bpf_arch_text_pokefunction bpf_arch_text_invalidatefunction store_argsfunction restore_argsfunction restore_stk_argsfunction invoke_bpf_progfunction invoke_bpffunction arch_free_bpf_trampolinefunction arch_protect_bpf_trampolinefunction sign_extendfunction __arch_prepare_bpf_trampolinefunction arch_prepare_bpf_trampolinefunction arch_bpf_trampoline_sizefunction bpf_jit_freefunction JITfunction bpf_jit_bypass_spec_v1function bpf_jit_bypass_spec_v4function bpf_jit_supports_arenafunction bpf_jit_supports_fsessionfunction bpf_jit_supports_subprog_tailcalls
Annotated Snippet
switch (BPF_SIZE(insn->code)) {
case BPF_B:
if (!cpu_has_lam_bh) {
pr_err_once("bpf-jit: amadd.b instruction is not supported\n");
return -EINVAL;
}
emit_insn(ctx, amaddb, t2, t1, src);
break;
case BPF_H:
if (!cpu_has_lam_bh) {
pr_err_once("bpf-jit: amadd.h instruction is not supported\n");
return -EINVAL;
}
emit_insn(ctx, amaddh, t2, t1, src);
break;
case BPF_W:
emit_insn(ctx, amaddw, t2, t1, src);
break;
case BPF_DW:
emit_insn(ctx, amaddd, t2, t1, src);
break;
}
break;
case BPF_AND:
if (isdw)
emit_insn(ctx, amandd, t2, t1, src);
else
emit_insn(ctx, amandw, t2, t1, src);
break;
case BPF_OR:
if (isdw)
emit_insn(ctx, amord, t2, t1, src);
else
emit_insn(ctx, amorw, t2, t1, src);
break;
case BPF_XOR:
if (isdw)
emit_insn(ctx, amxord, t2, t1, src);
else
emit_insn(ctx, amxorw, t2, t1, src);
break;
/* src = atomic_fetch_<op>(dst + off, src) */
case BPF_ADD | BPF_FETCH:
switch (BPF_SIZE(insn->code)) {
case BPF_B:
if (!cpu_has_lam_bh) {
pr_err_once("bpf-jit: amadd.b instruction is not supported\n");
return -EINVAL;
}
emit_insn(ctx, amaddb, src, t1, t3);
emit_zext_32(ctx, src, true);
break;
case BPF_H:
if (!cpu_has_lam_bh) {
pr_err_once("bpf-jit: amadd.h instruction is not supported\n");
return -EINVAL;
}
emit_insn(ctx, amaddh, src, t1, t3);
emit_zext_32(ctx, src, true);
break;
case BPF_W:
emit_insn(ctx, amaddw, src, t1, t3);
emit_zext_32(ctx, src, true);
break;
case BPF_DW:
emit_insn(ctx, amaddd, src, t1, t3);
break;
}
break;
case BPF_AND | BPF_FETCH:
if (isdw) {
emit_insn(ctx, amandd, src, t1, t3);
} else {
emit_insn(ctx, amandw, src, t1, t3);
emit_zext_32(ctx, src, true);
}
break;
case BPF_OR | BPF_FETCH:
if (isdw) {
emit_insn(ctx, amord, src, t1, t3);
} else {
emit_insn(ctx, amorw, src, t1, t3);
emit_zext_32(ctx, src, true);
}
break;
case BPF_XOR | BPF_FETCH:
if (isdw) {
emit_insn(ctx, amxord, src, t1, t3);
} else {
emit_insn(ctx, amxorw, src, t1, t3);
Annotation
- Immediate include surface: `linux/memory.h`, `bpf_jit.h`.
- Detected declarations: `function prepare_bpf_tail_call_cnt`, `function build_prologue`, `function __build_epilogue`, `function build_epilogue`, `function bpf_jit_supports_kfunc_call`, `function bpf_jit_supports_far_kfunc_call`, `function emit_bpf_tail_call`, `function emit_store_stack_imm64`, `function emit_atomic_rmw`, `function emit_atomic_ld_st`.
- Atlas domain: Architecture Layer / arch/loongarch.
- 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.