Re: [RFC PATCH] bpftool: Add bpf_cookie to perf output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 27, 2022 at 12:27 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.
>
>     $ bpftool perf
>     pid 83  fd 9: prog_id 5  bpf_cookie: 123  tracepoint  sched_process_exec
>

I think a more natural place to expose this would be in `bpftool link
show` output, as bpf_cookie is actually per attachment (i.e., link)
information (not a per-program). We'll need to anticipate multi-attach
use cases (e.g., multi-attach kprobe and fentry programs we are
discussing at the moment).

> Signed-off-by: Dmitrii Dolgov <9erthalion6@xxxxxxxxx>
> ---
>  include/linux/trace_events.h                  |  4 ++--
>  kernel/bpf/syscall.c                          | 13 +++++++------
>  kernel/trace/bpf_trace.c                      |  3 ++-
>  samples/bpf/task_fd_query_user.c              | 16 ++++++++--------
>  tools/bpf/bpftool/perf.c                      | 19 +++++++++++--------
>  tools/lib/bpf/bpf.c                           |  3 ++-
>  tools/lib/bpf/bpf.h                           |  2 +-
>  tools/lib/bpf/libbpf.map                      |  1 +
>  .../bpf/prog_tests/task_fd_query_rawtp.c      | 10 +++++-----
>  .../bpf/prog_tests/task_fd_query_tp.c         |  4 ++--
>  10 files changed, 41 insertions(+), 34 deletions(-)
>

[...]

> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> index 079cc81ac51e..80bd705eca59 100644
> --- a/tools/lib/bpf/bpf.h
> +++ b/tools/lib/bpf/bpf.h
> @@ -315,7 +315,7 @@ LIBBPF_API int bpf_load_btf(const void *btf, __u32 btf_size, char *log_buf,
>                             __u32 log_buf_size, bool do_log);
>  LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
>                                  __u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
> -                                __u64 *probe_offset, __u64 *probe_addr);
> +                                __u64 *probe_offset, __u64 *probe_addr, __u64 *bpf_cookie);

can't do this, it breaks source code compatibility.
bpf_task_fd_query() API isn't extendable.

>
>  enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */
>  LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type);

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux