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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf.hbpf/bpf_helpers.hbpf_misc.h
Detected Declarations
struct rb_ctxfunction __retvalfunction __msgfunction __msgfunction __msgfunction __msgfunction map_ptr_is_never_nullfunction map_ptr_is_never_null_innerfunction map_ptr_is_never_null_inner_spill_fillfunction __rb_event_reservefunction __rb_event_submitfunction map_ptr_is_never_null_rb
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
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `struct rb_ctx`, `function __retval`, `function __msg`, `function __msg`, `function __msg`, `function __msg`, `function map_ptr_is_never_null`, `function map_ptr_is_never_null_inner`, `function map_ptr_is_never_null_inner_spill_fill`, `function __rb_event_reserve`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.