arch/powerpc/net/bpf_jit_comp.c
Source file repositories/reference/linux-study-clean/arch/powerpc/net/bpf_jit_comp.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/net/bpf_jit_comp.c- Extension
.c- Size
- 41379 bytes
- Lines
- 1423
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- 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/moduleloader.hasm/cacheflush.hasm/asm-compat.hlinux/netdevice.hlinux/filter.hlinux/if_vlan.hlinux/kernel.hlinux/memory.hlinux/bpf.hasm/kprobes.hasm/text-patching.hbpf_jit.h
Detected Declarations
struct powerpc_jit_datafunction bpf_jit_fill_ill_insnsfunction bpf_jit_build_fentry_stubsfunction bpf_jit_emit_exit_insnfunction bpf_jit_needs_zextfunction priv_stack_init_guardfunction for_each_possible_cpufunction priv_stack_check_guardfunction for_each_possible_cpufunction bpf_jit_emit_common_epiloguefunction bpf_arch_text_invalidatefunction bpf_jit_freefunction JITfunction bpf_jit_supports_exceptionsfunction bpf_jit_supports_subprog_tailcallsfunction bpf_jit_supports_timed_may_gotofunction bpf_jit_supports_kfunc_callfunction bpf_jit_supports_private_stackfunction bpf_jit_supports_fsessionfunction bpf_jit_supports_arenafunction bpf_jit_supports_far_kfunc_callfunction bpf_jit_supports_insnfunction bpf_jit_supports_percpu_insnfunction bpf_jit_inlines_helper_callfunction arch_free_bpf_trampolinefunction arch_protect_bpf_trampolinefunction invoke_bpf_progfunction invoke_bpf_mod_retfunction __arch_prepare_bpf_trampolinefunction bpf_trampoline_restore_tail_call_cntfunction bpf_trampoline_save_argsfunction bpf_trampoline_restore_args_regsfunction bpf_trampoline_restore_args_stackfunction __arch_prepare_bpf_trampolinefunction bpf_arch_text_pokefunction arch_bpf_trampoline_sizefunction arch_prepare_bpf_trampolinefunction bpf_modify_instfunction do_isyncfunction isync
Annotated Snippet
struct powerpc_jit_data {
/* address of rw header */
struct bpf_binary_header *hdr;
/* address of ro final header */
struct bpf_binary_header *fhdr;
u32 *addrs;
u8 *fimage;
u32 proglen;
struct codegen_context ctx;
};
bool bpf_jit_needs_zext(void)
{
return true;
}
static void priv_stack_init_guard(void __percpu *priv_stack_ptr, int alloc_size)
{
int cpu, underflow_idx = (alloc_size - PRIV_STACK_GUARD_SZ) >> 3;
u64 *stack_ptr;
for_each_possible_cpu(cpu) {
stack_ptr = per_cpu_ptr(priv_stack_ptr, cpu);
stack_ptr[0] = PRIV_STACK_GUARD_VAL;
stack_ptr[1] = PRIV_STACK_GUARD_VAL;
stack_ptr[underflow_idx] = PRIV_STACK_GUARD_VAL;
stack_ptr[underflow_idx + 1] = PRIV_STACK_GUARD_VAL;
}
}
static void priv_stack_check_guard(void __percpu *priv_stack_ptr, int alloc_size,
struct bpf_prog *fp)
{
int cpu, underflow_idx = (alloc_size - PRIV_STACK_GUARD_SZ) >> 3;
u64 *stack_ptr;
for_each_possible_cpu(cpu) {
stack_ptr = per_cpu_ptr(priv_stack_ptr, cpu);
if (stack_ptr[0] != PRIV_STACK_GUARD_VAL ||
stack_ptr[1] != PRIV_STACK_GUARD_VAL ||
stack_ptr[underflow_idx] != PRIV_STACK_GUARD_VAL ||
stack_ptr[underflow_idx + 1] != PRIV_STACK_GUARD_VAL) {
pr_err("BPF private stack overflow/underflow detected for prog %s\n",
bpf_jit_get_prog_name(fp));
break;
}
}
}
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *fp)
{
u32 proglen;
u32 alloclen;
u8 *image = NULL;
u32 *code_base = NULL;
u32 *addrs = NULL;
struct powerpc_jit_data *jit_data = NULL;
struct codegen_context cgctx;
int pass;
int flen;
int priv_stack_alloc_size;
void __percpu *priv_stack_ptr = NULL;
struct bpf_binary_header *fhdr = NULL;
struct bpf_binary_header *hdr = NULL;
bool extra_pass = false;
u8 *fimage = NULL;
u32 *fcode_base = NULL;
u32 extable_len;
u32 fixup_len;
if (!fp->jit_requested)
return fp;
jit_data = fp->aux->jit_data;
if (!jit_data) {
jit_data = kzalloc_obj(*jit_data);
if (!jit_data)
return fp;
fp->aux->jit_data = jit_data;
}
priv_stack_ptr = fp->aux->priv_stack_ptr;
if (!priv_stack_ptr && fp->aux->jits_use_priv_stack) {
/*
* Allocate private stack of size equivalent to
* verifier-calculated stack size plus two memory
* guard regions to detect private stack overflow
* and underflow.
*/
priv_stack_alloc_size = round_up(fp->aux->stack_depth, 16) +
Annotation
- Immediate include surface: `linux/moduleloader.h`, `asm/cacheflush.h`, `asm/asm-compat.h`, `linux/netdevice.h`, `linux/filter.h`, `linux/if_vlan.h`, `linux/kernel.h`, `linux/memory.h`.
- Detected declarations: `struct powerpc_jit_data`, `function bpf_jit_fill_ill_insns`, `function bpf_jit_build_fentry_stubs`, `function bpf_jit_emit_exit_insn`, `function bpf_jit_needs_zext`, `function priv_stack_init_guard`, `function for_each_possible_cpu`, `function priv_stack_check_guard`, `function for_each_possible_cpu`, `function bpf_jit_emit_common_epilogue`.
- Atlas domain: Architecture Layer / arch/powerpc.
- 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.