On Wed, Mar 9, 2022 at 8:33 AM Dmitrii Dolgov <9erthalion6@xxxxxxxxx> wrote: > > Commit 82e6b1eee6a8 ("bpf: Allow to specify user-provided bpf_cookie for > BPF perf links") introduced the concept of user specified bpf_cookie, > which could be accessed by BPF programs using bpf_get_attach_cookie(). > For troubleshooting purposes it is convenient to expose bpf_cookie via > bpftool as well, so there is no need to meddle with the target BPF > program itself. > > Implemented using the pid iterator BPF program to actually fetch > bpf_cookies, which allows constraining code changes only to bpftool. > > $ bpftool link > 1: type 7 prog 5 > bpf_cookie 123 > pids bootstrap(81) > > Signed-off-by: Dmitrii Dolgov <9erthalion6@xxxxxxxxx> > Acked-by: Yonghong Song <yhs@xxxxxx> > --- Quentin, any opinion on this feature? The implementation seems straightforward enough. We'll need to not forget to expand the support to other types that support bpf_cookies (and multi-attach kprobes and fentries will be problematic, potentially), but this might be useful for debugging purposes. > Changes in v6: > - Remove unnecessary initialization of fields in pid_iter_entry > - Changing bpf_cookie_set to has_bpf_cookie > - Small code cleanup (casting bpf_cookie when needed, removing > __always_inline, etc.) > > Changes in v5: > - Remove unneeded cookie assigns > > Changes in v4: > - Fetch cookies only for bpf_perf_link > - Signal about bpf_cookie via the flag, instead of deducing it from > the object and link type > - Reset pid_iter_entry to avoid invalid indirect read from stack > > Changes in v3: > - Use pid iterator to fetch bpf_cookie > > Changes in v2: > - Display bpf_cookie in bpftool link command instead perf > > Previous discussion: https://lore.kernel.org/bpf/20220225152802.20957-1-9erthalion6@xxxxxxxxx/ > > tools/bpf/bpftool/main.h | 2 ++ > tools/bpf/bpftool/pids.c | 8 ++++++++ > tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 22 ++++++++++++++++++++++ > tools/bpf/bpftool/skeleton/pid_iter.h | 2 ++ > 4 files changed, 34 insertions(+) > [...]