tools/testing/selftests/bpf/prog_tests/recursive_attach.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/recursive_attach.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/recursive_attach.c- Extension
.c- Size
- 6890 bytes
- Lines
- 219
- 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
test_progs.hfentry_recursive.skel.hfentry_recursive_target.skel.hbpf/btf.hbpf/libbpf_internal.h
Detected Declarations
function test_recursive_fentry_chainfunction test_recursive_fentryfunction test_fentry_attach_btf_presencefunction test_fentry_attach_stress
Annotated Snippet
if (i == 0) {
prev_fd = bpf_program__fd(target_skel->progs.test1);
err = bpf_program__set_attach_target(prog, prev_fd, "test1");
} else {
prev_fd = bpf_program__fd(tracing_chain[i-1]->progs.recursive_attach);
err = bpf_program__set_attach_target(prog, prev_fd, "recursive_attach");
}
if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
goto close_prog;
err = fentry_recursive__load(tracing_chain[i]);
/* The first attach should succeed, the second fail */
if (i == 0) {
if (!ASSERT_OK(err, "fentry_recursive__load"))
goto close_prog;
if (attach) {
err = fentry_recursive__attach(tracing_chain[i]);
if (!ASSERT_OK(err, "fentry_recursive__attach"))
goto close_prog;
}
if (detach) {
/* Flag attach_tracing_prog should still be set, preventing
* attachment of the following prog.
*/
fentry_recursive__detach(tracing_chain[i]);
}
} else {
if (!ASSERT_ERR(err, "fentry_recursive__load"))
goto close_prog;
}
}
close_prog:
fentry_recursive_target__destroy(target_skel);
for (int i = 0; i < 2; i++) {
fentry_recursive__destroy(tracing_chain[i]);
}
}
void test_recursive_fentry(void)
{
if (test__start_subtest("attach"))
test_recursive_fentry_chain(true, false);
if (test__start_subtest("load"))
test_recursive_fentry_chain(false, false);
if (test__start_subtest("detach"))
test_recursive_fentry_chain(true, true);
}
/* Test that a tracing prog reattachment (when we land in
* "prog->aux->dst_trampoline and tgt_prog is NULL" branch in
* bpf_tracing_prog_attach) does not lead to a crash due to missing attach_btf
*/
void test_fentry_attach_btf_presence(void)
{
struct fentry_recursive_target *target_skel = NULL;
struct fentry_recursive *tracing_skel = NULL;
struct bpf_program *prog;
int err, link_fd, tgt_prog_fd;
target_skel = fentry_recursive_target__open_and_load();
if (!ASSERT_OK_PTR(target_skel, "fentry_recursive_target__open_and_load"))
goto close_prog;
tracing_skel = fentry_recursive__open();
if (!ASSERT_OK_PTR(tracing_skel, "fentry_recursive__open"))
goto close_prog;
prog = tracing_skel->progs.recursive_attach;
tgt_prog_fd = bpf_program__fd(target_skel->progs.fentry_target);
err = bpf_program__set_attach_target(prog, tgt_prog_fd, "fentry_target");
if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
goto close_prog;
err = fentry_recursive__load(tracing_skel);
if (!ASSERT_OK(err, "fentry_recursive__load"))
goto close_prog;
tgt_prog_fd = bpf_program__fd(tracing_skel->progs.recursive_attach);
link_fd = bpf_link_create(tgt_prog_fd, 0, BPF_TRACE_FENTRY, NULL);
if (!ASSERT_GE(link_fd, 0, "link_fd"))
goto close_prog;
fentry_recursive__detach(tracing_skel);
err = fentry_recursive__attach(tracing_skel);
ASSERT_ERR(err, "fentry_recursive__attach");
Annotation
- Immediate include surface: `test_progs.h`, `fentry_recursive.skel.h`, `fentry_recursive_target.skel.h`, `bpf/btf.h`, `bpf/libbpf_internal.h`.
- Detected declarations: `function test_recursive_fentry_chain`, `function test_recursive_fentry`, `function test_fentry_attach_btf_presence`, `function test_fentry_attach_stress`.
- 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.