tools/testing/selftests/bpf/progs/map_ptr_kern.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/map_ptr_kern.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/map_ptr_kern.c- Extension
.c- Size
- 17590 bytes
- Lines
- 721
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf.hbpf/bpf_helpers.h
Detected Declarations
struct bpf_mapstruct bpf_htabstruct bpf_arraystruct bpf_stack_mapstruct lpm_triestruct lpm_keystruct inner_mapstruct bpf_dtabstruct bpf_stabstruct bpf_cpu_mapstruct xsk_mapstruct bpf_shtabstruct bpf_cgroup_storage_mapstruct reuseport_arraystruct bpf_queue_stackstruct bpf_local_storage_mapstruct bpf_ringbufstruct bpf_ringbuf_mapfunction check_bpf_map_fieldsfunction check_bpf_map_ptrfunction checkfunction check_defaultfunction check_default_noinlinefunction check_hashfunction check_arrayfunction check_prog_arrayfunction check_perf_event_arrayfunction check_percpu_hashfunction check_percpu_arrayfunction check_stack_tracefunction check_cgroup_arrayfunction check_lru_hashfunction check_lru_percpu_hashfunction check_lpm_triefunction check_array_of_mapsfunction check_hash_of_mapsfunction check_devmapfunction check_sockmapfunction check_cpumapfunction check_xskmapfunction check_sockhashfunction check_cgroup_storagefunction check_reuseport_sockarrayfunction check_percpu_cgroup_storagefunction check_queuefunction check_stackfunction check_sk_storagefunction check_devmap_hash
Annotated Snippet
struct bpf_map {
enum bpf_map_type map_type;
__u32 key_size;
__u32 value_size;
__u32 max_entries;
__u32 id;
} __attribute__((preserve_access_index));
static inline int check_bpf_map_fields(struct bpf_map *map, __u32 key_size,
__u32 value_size, __u32 max_entries)
{
VERIFY(map->map_type == g_map_type);
VERIFY(map->key_size == key_size);
VERIFY(map->value_size == value_size);
VERIFY(map->max_entries == max_entries);
VERIFY(map->id > 0);
return 1;
}
static inline int check_bpf_map_ptr(struct bpf_map *indirect,
struct bpf_map *direct)
{
VERIFY(indirect->map_type == direct->map_type);
VERIFY(indirect->key_size == direct->key_size);
VERIFY(indirect->value_size == direct->value_size);
VERIFY(indirect->max_entries == direct->max_entries);
VERIFY(indirect->id == direct->id);
return 1;
}
static inline int check(struct bpf_map *indirect, struct bpf_map *direct,
__u32 key_size, __u32 value_size, __u32 max_entries)
{
VERIFY(check_bpf_map_ptr(indirect, direct));
VERIFY(check_bpf_map_fields(indirect, key_size, value_size,
max_entries));
return 1;
}
static inline int check_default(struct bpf_map *indirect,
struct bpf_map *direct)
{
VERIFY(check(indirect, direct, sizeof(__u32), sizeof(__u32),
MAX_ENTRIES));
return 1;
}
static __noinline int
check_default_noinline(struct bpf_map *indirect, struct bpf_map *direct)
{
VERIFY(check(indirect, direct, sizeof(__u32), sizeof(__u32),
MAX_ENTRIES));
return 1;
}
typedef struct {
int counter;
} atomic_t;
struct bpf_htab {
struct bpf_map map;
atomic_t count;
__u32 n_buckets;
__u32 elem_size;
} __attribute__((preserve_access_index));
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(map_flags, BPF_F_NO_PREALLOC); /* to test bpf_htab.count */
__uint(max_entries, MAX_ENTRIES);
__type(key, __u32);
__type(value, __u32);
} m_hash SEC(".maps");
__s64 bpf_map_sum_elem_count(struct bpf_map *map) __ksym;
static inline int check_hash(void)
{
struct bpf_htab *hash = (struct bpf_htab *)&m_hash;
struct bpf_map *map = (struct bpf_map *)&m_hash;
int i;
VERIFY(check_default_noinline(&hash->map, map));
VERIFY(hash->n_buckets == MAX_ENTRIES);
VERIFY(hash->elem_size == 64);
VERIFY(hash->count.counter == 0);
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `struct bpf_map`, `struct bpf_htab`, `struct bpf_array`, `struct bpf_stack_map`, `struct lpm_trie`, `struct lpm_key`, `struct inner_map`, `struct bpf_dtab`, `struct bpf_stab`, `struct bpf_cpu_map`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.