mallya's blog

Cooking into BPF internals

In Progress

17 Mar 2026 · Varun R Mallya · BPF, Kernel, fundamentals

Note: This will be a casual blog, so excuse my language. It’s mostly stuff for documentation (for my brain).

The goal

sys_bpf

We start from the very beginning. sys_bpf is where everything begins.

bpf_prog_load

	/* run eBPF verifier */
	err = bpf_check(&prog, attr, uattr, uattr_size);
	if (err < 0)
		goto free_used_maps;

	prog = bpf_prog_select_runtime(prog, &err);
	if (err < 0)
		goto free_used_maps;

	err = bpf_prog_mark_insn_arrays_ready(prog);
	if (err < 0)
		goto free_used_maps;

	err = bpf_prog_alloc_id(prog);
	if (err)
		goto free_used_maps;

The order in which this is run is pretty cool too.

bpf_check

Tangent: - idr_preload(GFP_KERNEL) this is preloading the ID mapping allocation in the current context and it goes to the integer ID management part in the kernel that thandoes the ID alocation. - prog_idrwhenever accessed is supposed to be protected by a spinlock.

NOTE:

This blog, like all the blogs in this series is dynamic. It will keep being updated. This article is a stub.