tools/testing/selftests/bpf/progs/verifier_map_in_map.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_map_in_map.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/verifier_map_in_map.c
Extension
.c
Size
6663 bytes
Lines
301
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct rb_ctx {
	void *rb;
	struct bpf_dynptr dptr;
};

static __always_inline struct rb_ctx __rb_event_reserve(__u32 sz)
{
	struct rb_ctx rb_ctx = {};
	void *rb;
	__u32 cpu = bpf_get_smp_processor_id();
	__u32 rb_slot = cpu & 1;

	rb = bpf_map_lookup_elem(&rb_in_map, &rb_slot);
	if (!rb)
		return rb_ctx;

	rb_ctx.rb = rb;
	bpf_ringbuf_reserve_dynptr(rb, sz, 0, &rb_ctx.dptr);

	return rb_ctx;
}

static __noinline void __rb_event_submit(struct rb_ctx *ctx)
{
	if (!ctx->rb)
		return;

	/* If the verifier (incorrectly) concludes that ctx->rb can be
	 * NULL at this point, we'll get "BPF_EXIT instruction in main
	 * prog would lead to reference leak" error
	 */
	bpf_ringbuf_submit_dynptr(&ctx->dptr, 0);
}

SEC("socket")
int map_ptr_is_never_null_rb(void *ctx)
{
	struct rb_ctx event_ctx = __rb_event_reserve(256);
	__rb_event_submit(&event_ctx);
	return 0;
}

char _license[] SEC("license") = "GPL";

Annotation

Implementation Notes