tools/testing/selftests/bpf/progs/verifier_bits_iter.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_bits_iter.c- Extension
.c- Size
- 4299 bytes
- Lines
- 233
- 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
vmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf_misc.htask_kfunc_common.h
Detected Declarations
function __msgfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction bpf_for_eachfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction bpf_for_eachfunction __retval
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2024 Yafang Shao <laoar.shao@gmail.com> */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"
#include "task_kfunc_common.h"
char _license[] SEC("license") = "GPL";
int bpf_iter_bits_new(struct bpf_iter_bits *it, const u64 *unsafe_ptr__ign,
u32 nr_bits) __ksym __weak;
int *bpf_iter_bits_next(struct bpf_iter_bits *it) __ksym __weak;
void bpf_iter_bits_destroy(struct bpf_iter_bits *it) __ksym __weak;
u64 bits_array[511] = {};
SEC("iter.s/cgroup")
__description("bits iter without destroy")
__failure __msg("Unreleased reference")
int BPF_PROG(no_destroy, struct bpf_iter_meta *meta, struct cgroup *cgrp)
{
struct bpf_iter_bits it;
u64 data = 1;
bpf_iter_bits_new(&it, &data, 1);
bpf_iter_bits_next(&it);
return 0;
}
SEC("iter/cgroup")
__description("uninitialized iter in ->next()")
__failure __msg("expected an initialized iter_bits as R1")
int BPF_PROG(next_uninit, struct bpf_iter_meta *meta, struct cgroup *cgrp)
{
struct bpf_iter_bits it = {};
bpf_iter_bits_next(&it);
return 0;
}
SEC("iter/cgroup")
__description("uninitialized iter in ->destroy()")
__failure __msg("expected an initialized iter_bits as R1")
int BPF_PROG(destroy_uninit, struct bpf_iter_meta *meta, struct cgroup *cgrp)
{
struct bpf_iter_bits it = {};
bpf_iter_bits_destroy(&it);
return 0;
}
SEC("syscall")
__description("null pointer")
__success __retval(0)
int null_pointer(void)
{
struct bpf_iter_bits iter;
int err, nr = 0;
int *bit;
err = bpf_iter_bits_new(&iter, NULL, 1);
bpf_iter_bits_destroy(&iter);
if (err != -EINVAL)
return 1;
bpf_for_each(bits, bit, NULL, 1)
nr++;
return nr;
}
SEC("syscall")
__description("bits copy")
__success __retval(10)
int bits_copy(void)
{
u64 data = 0xf7310UL; /* 4 + 3 + 2 + 1 + 0*/
int nr = 0;
int *bit;
bpf_for_each(bits, bit, &data, 1)
nr++;
return nr;
}
SEC("syscall")
__description("bits memalloc")
__success __retval(64)
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_misc.h`, `task_kfunc_common.h`.
- Detected declarations: `function __msg`, `function __msg`, `function __msg`, `function __retval`, `function __retval`, `function __retval`, `function __retval`, `function bpf_for_each`, `function __retval`, `function __retval`.
- 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.