tools/testing/selftests/bpf/progs/kfunc_call_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/kfunc_call_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/kfunc_call_test.c- Extension
.c- Size
- 6698 bytes
- Lines
- 316
- 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_misc.h../test_kmods/bpf_testmod_kfunc.h
Detected Declarations
struct syscall_test_argsstruct ctx_valfunction kfunc_call_test5function kfunc_call_test5_asmfunction kfunc_call_test4function kfunc_call_test2function kfunc_call_test1function kfunc_call_test_ref_btf_idfunction kfunc_call_test_passfunction kfunc_syscall_testfunction kfunc_syscall_test_nullfunction kfunc_call_test_get_memfunction kfunc_call_test_static_unused_argfunction kfunc_call_ctx
Annotated Snippet
struct syscall_test_args {
__u8 data[16];
size_t size;
};
SEC("syscall")
int kfunc_syscall_test(struct syscall_test_args *args)
{
const long size = args->size;
if (size > sizeof(args->data))
return -7; /* -E2BIG */
bpf_kfunc_call_test_mem_len_pass1(&args->data, sizeof(args->data));
bpf_kfunc_call_test_mem_len_pass1(&args->data, sizeof(*args));
bpf_kfunc_call_test_mem_len_pass1(&args->data, size);
return 0;
}
SEC("syscall")
int kfunc_syscall_test_null(struct syscall_test_args *args)
{
/* Must be called with args as a NULL pointer
* we do not check for it to have the verifier consider that
* the pointer might not be null, and so we can load it.
*
* So the following can not be added:
*
* if (args)
* return -22;
*/
bpf_kfunc_call_test_mem_len_pass1(args, 0);
return 0;
}
SEC("tc")
int kfunc_call_test_get_mem(struct __sk_buff *skb)
{
struct prog_test_ref_kfunc *pt;
unsigned long s = 0;
int *p = NULL;
int ret = 0;
pt = bpf_kfunc_call_test_acquire(&s);
if (pt) {
p = bpf_kfunc_call_test_get_rdwr_mem(pt, 2 * sizeof(int));
if (p) {
p[0] = 42;
ret = p[1]; /* 108 */
} else {
ret = -1;
}
if (ret >= 0) {
p = bpf_kfunc_call_test_get_rdonly_mem(pt, 2 * sizeof(int));
if (p)
ret = p[0]; /* 42 */
else
ret = -1;
}
bpf_kfunc_call_test_release(pt);
}
return ret;
}
SEC("tc")
int kfunc_call_test_static_unused_arg(struct __sk_buff *skb)
{
u32 expected = 5, actual;
actual = bpf_kfunc_call_test_static_unused_arg(expected, 0xdeadbeef);
return actual != expected ? -1 : 0;
}
struct ctx_val {
struct bpf_testmod_ctx __kptr *ctx;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct ctx_val);
} ctx_map SEC(".maps");
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `../test_kmods/bpf_testmod_kfunc.h`.
- Detected declarations: `struct syscall_test_args`, `struct ctx_val`, `function kfunc_call_test5`, `function kfunc_call_test5_asm`, `function kfunc_call_test4`, `function kfunc_call_test2`, `function kfunc_call_test1`, `function kfunc_call_test_ref_btf_id`, `function kfunc_call_test_pass`, `function kfunc_syscall_test`.
- 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.