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.

Dependency Surface

Detected Declarations

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

Implementation Notes