tools/testing/selftests/bpf/progs/verifier_async_cb_context.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_async_cb_context.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_async_cb_context.c- Extension
.c- Size
- 3684 bytes
- Lines
- 182
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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.hbpf_experimental.h
Detected Declarations
struct timer_elemstruct wq_elemstruct task_work_elemfunction timer_cbfunction __msgfunction __msgfunction wq_cbfunction wq_non_sleepable_progfunction wq_sleepable_progfunction task_work_cbfunction task_work_non_sleepable_progfunction task_work_sleepable_prog
Annotated Snippet
struct timer_elem {
struct bpf_timer t;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct timer_elem);
} timer_map SEC(".maps");
static int timer_cb(void *map, int *key, struct bpf_timer *timer)
{
u32 data;
/* Timer callbacks are never sleepable, even from non-sleepable programs */
bpf_copy_from_user(&data, sizeof(data), NULL);
return 0;
}
SEC("fentry/bpf_fentry_test1")
__failure __msg("sleepable helper bpf_copy_from_user#{{[0-9]+}} in non-sleepable prog")
int timer_non_sleepable_prog(void *ctx)
{
struct timer_elem *val;
int key = 0;
val = bpf_map_lookup_elem(&timer_map, &key);
if (!val)
return 0;
bpf_timer_init(&val->t, &timer_map, 0);
bpf_timer_set_callback(&val->t, timer_cb);
return 0;
}
SEC("lsm.s/file_open")
__failure __msg("sleepable helper bpf_copy_from_user#{{[0-9]+}} in non-sleepable prog")
int timer_sleepable_prog(void *ctx)
{
struct timer_elem *val;
int key = 0;
val = bpf_map_lookup_elem(&timer_map, &key);
if (!val)
return 0;
bpf_timer_init(&val->t, &timer_map, 0);
bpf_timer_set_callback(&val->t, timer_cb);
return 0;
}
/* Workqueue tests */
struct wq_elem {
struct bpf_wq w;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct wq_elem);
} wq_map SEC(".maps");
static int wq_cb(void *map, int *key, void *value)
{
u32 data;
/* Workqueue callbacks are always sleepable, even from non-sleepable programs */
bpf_copy_from_user(&data, sizeof(data), NULL);
return 0;
}
SEC("fentry/bpf_fentry_test1")
__success
int wq_non_sleepable_prog(void *ctx)
{
struct wq_elem *val;
int key = 0;
val = bpf_map_lookup_elem(&wq_map, &key);
if (!val)
return 0;
if (bpf_wq_init(&val->w, &wq_map, 0) != 0)
return 0;
if (bpf_wq_set_callback(&val->w, wq_cb, 0) != 0)
return 0;
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_misc.h`, `bpf_experimental.h`.
- Detected declarations: `struct timer_elem`, `struct wq_elem`, `struct task_work_elem`, `function timer_cb`, `function __msg`, `function __msg`, `function wq_cb`, `function wq_non_sleepable_prog`, `function wq_sleepable_prog`, `function task_work_cb`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.