// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2023 Red Hat, Inc. */ #include <test_progs.h> #include"fentry_recursive.skel.h" #include"fentry_recursive_target.skel.h" #include <bpf/btf.h> #include"bpf/libbpf_internal.h"
/* Test recursive attachment of tracing progs with more than one nesting level *isnotpossible.Createachainofattachment,verifythatthelastprog *willfail.Dependingonthearguments,followingcasesaretested: * *-Recursiveloadingoftracingprogs,withoutattaching(attach=false, *detach=false).Thechainlookslikethis: *loadtarget *loadfentry1->target *loadfentry2->fentry1(fail) * *-Recursiveattachoftracingprogs(attach=true,detach=false).The *chainlookslikethis: *loadtarget *loadfentry1->target *attachfentry1->target *loadfentry2->fentry1(fail) * *-Recursiveattachanddetachoftracingprogs(attach=true,detach= *true).Thisvalidatesthatattach_tracing_progflagwillbesetthroughout *thewholelifecycleofanfentryprog,independentlyfromwhetherit's *detached.Thechainlookslikethis: *loadtarget *loadfentry1->target *attachfentry1->target *detachfentry1 *loadfentry2->fentry1(fail)
*/ staticvoid test_recursive_fentry_chain(bool attach, bool detach)
{ struct fentry_recursive_target *target_skel = NULL; struct fentry_recursive *tracing_chain[2] = {}; struct bpf_program *prog; int prev_fd, err;
target_skel = fentry_recursive_target__open_and_load(); if (!ASSERT_OK_PTR(target_skel, "fentry_recursive_target__open_and_load")) return;
/* Create an attachment chain with two fentry progs */ for (int i = 0; i < 2; i++) {
tracing_chain[i] = fentry_recursive__open(); if (!ASSERT_OK_PTR(tracing_chain[i], "fentry_recursive__open")) goto close_prog;
/* The first prog in the chain is going to be attached to the target *fentryprogram,thesecondonetothepreviousinthechain.
*/
prog = tracing_chain[i]->progs.recursive_attach; 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 *attachmentofthefollowingprog.
*/
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_trampolineandtgt_progisNULL"branchin *bpf_tracing_prog_attach)doesnotleadtoacrashduetomissingattach_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;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.