tools/testing/selftests/bpf/progs/task_kfunc_common.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/task_kfunc_common.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/task_kfunc_common.h- Extension
.h- Size
- 1828 bytes
- Lines
- 78
- 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
errno.hvmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.h
Detected Declarations
struct __tasks_kfunc_map_valuefunction tasks_kfunc_map_insert
Annotated Snippet
struct __tasks_kfunc_map_value {
struct task_struct __kptr * task;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, int);
__type(value, struct __tasks_kfunc_map_value);
__uint(max_entries, 1);
} __tasks_kfunc_map SEC(".maps");
struct task_struct *bpf_task_acquire(struct task_struct *p) __ksym;
void bpf_task_release(struct task_struct *p) __ksym;
struct task_struct *bpf_task_from_pid(s32 pid) __ksym;
struct task_struct *bpf_task_from_vpid(s32 vpid) __ksym;
void bpf_rcu_read_lock(void) __ksym;
void bpf_rcu_read_unlock(void) __ksym;
static inline struct __tasks_kfunc_map_value *tasks_kfunc_map_value_lookup(struct task_struct *p)
{
s32 pid;
long status;
status = bpf_probe_read_kernel(&pid, sizeof(pid), &p->pid);
if (status)
return NULL;
return bpf_map_lookup_elem(&__tasks_kfunc_map, &pid);
}
static inline int tasks_kfunc_map_insert(struct task_struct *p)
{
struct __tasks_kfunc_map_value local, *v;
long status;
struct task_struct *acquired, *old;
s32 pid;
status = bpf_probe_read_kernel(&pid, sizeof(pid), &p->pid);
if (status)
return status;
local.task = NULL;
status = bpf_map_update_elem(&__tasks_kfunc_map, &pid, &local, BPF_NOEXIST);
if (status)
return status;
v = bpf_map_lookup_elem(&__tasks_kfunc_map, &pid);
if (!v) {
bpf_map_delete_elem(&__tasks_kfunc_map, &pid);
return -ENOENT;
}
acquired = bpf_task_acquire(p);
if (!acquired)
return -ENOENT;
old = bpf_kptr_xchg(&v->task, acquired);
if (old) {
bpf_task_release(old);
return -EEXIST;
}
return 0;
}
#endif /* _TASK_KFUNC_COMMON_H */
Annotation
- Immediate include surface: `errno.h`, `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `struct __tasks_kfunc_map_value`, `function tasks_kfunc_map_insert`.
- 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.