On Wed, Nov 29, 2023 at 11:56 AM Dmitrii Dolgov <9erthalion6@xxxxxxxxx> wrote: > > Currently, it's not allowed to attach an fentry/fexit prog to another > one of the same type. At the same time it's not uncommon to see a > tracing program with lots of logic in use, and the attachment limitation > prevents usage of fentry/fexit for performance analysis (e.g. with > "bpftool prog profile" command) in this case. An example could be > falcosecurity libs project that uses tp_btf tracing programs. > > Following the corresponding discussion [1], the reason for that is to > avoid tracing progs call cycles without introducing more complex > solutions. Relax "no same type" requirement to "no progs that are > already an attach target themselves" for the tracing type. In this way > only a standalone tracing program (without any other progs attached to > it) could be attached to another one, and no cycle could be formed. To > implement, add a new field into bpf_prog_aux to track the number of > attachments to the target prog. > > As a side effect of this change alone, one could create an unbounded > chain of tracing progs attached to each other. Similar issues between > fentry/fexit and extend progs are addressed via forbidding certain > combinations that could lead to similar chains. Introduce an > attach_depth field to limit the attachment chain, and display it in > bpftool. > > Note, that currently, due to various limitations, it's actually not > possible to form such an attachment cycle the original implementation > was prohibiting. It seems that the idea was to make this part robust > even in the view of potential future changes. > > [1]: https://lore.kernel.org/bpf/20191108064039.2041889-16-ast@xxxxxxxxxx/ > > Signed-off-by: Dmitrii Dolgov <9erthalion6@xxxxxxxxx> We discussed this in earlier version: " > If prog B attached to prog A, and prog C attached to prog B, then we > detach B. At this point, can we re-attach B to A? Nope, with the proposed changes it still wouldn't be possible to reattach B to A (if we're talking about tracing progs of course), because this time B is an attachment target on its own. " I think this can be problematic for some users. Basically, doing profiling on prog B can cause it to not work (cannot re-attach). Given it is not possible to create a call circle, shall we remove this issue? Thanks, Song