Message ID | 20230515130849.57502-4-laoar.shao@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | bpf: bpf trampoline improvements | expand |
On Mon, May 15, 2023 at 6:09 AM Yafang Shao <laoar.shao@gmail.com> wrote: > [...] > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com> The change looks good to me, except that we should split the change into two commits. Also, this doesn't seem to be related to the other two patches. So it is a little weird to add it in v2. Other than these. Acked-by: Song Liu <song@kernel.org>
On Tue, May 16, 2023 at 12:13 AM Song Liu <song@kernel.org> wrote: > > On Mon, May 15, 2023 at 6:09 AM Yafang Shao <laoar.shao@gmail.com> wrote: > > > > [...] > > > > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com> > > The change looks good to me, except that we should split the change > into two commits. > Will split it and send them. Thanks for your review. > Also, this doesn't seem to be related to the other two patches. So it is > a little weird to add it in v2. > > Other than these. > > Acked-by: Song Liu <song@kernel.org>
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 909c112..870395a 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2968,10 +2968,18 @@ static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link, { struct bpf_tracing_link *tr_link = container_of(link, struct bpf_tracing_link, link.link); + u32 target_btf_id; + u32 target_obj_id; + bpf_trampoline_unpack_key(tr_link->trampoline->key, + &target_obj_id, &target_btf_id); seq_printf(seq, - "attach_type:\t%d\n", - tr_link->attach_type); + "attach_type:\t%d\n" + "target_obj_id:\t%u\n" + "target_btf_id:\t%u\n", + tr_link->attach_type, + target_obj_id, + target_btf_id); } static int bpf_tracing_link_fill_link_info(const struct bpf_link *link, diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c index 243b74e..cfe896f 100644 --- a/tools/bpf/bpftool/link.c +++ b/tools/bpf/bpftool/link.c @@ -195,6 +195,8 @@ static int show_link_close_json(int fd, struct bpf_link_info *info) show_link_attach_type_json(info->tracing.attach_type, json_wtr); + jsonw_uint_field(json_wtr, "target_obj_id", info->tracing.target_obj_id); + jsonw_uint_field(json_wtr, "target_btf_id", info->tracing.target_btf_id); break; case BPF_LINK_TYPE_CGROUP: jsonw_lluint_field(json_wtr, "cgroup_id", @@ -375,6 +377,8 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info) printf("\n\tprog_type %u ", prog_info.type); show_link_attach_type_plain(info->tracing.attach_type); + printf("\n\ttarget_obj_id %u target_btf_id %u ", + info->tracing.target_obj_id, info->tracing.target_btf_id); break; case BPF_LINK_TYPE_CGROUP: printf("\n\tcgroup_id %zu ", (size_t)info->cgroup.cgroup_id);
The target_btf_id can help us understand which kernel function is linked by a tracing prog. The target_btf_id and target_obj_id have already been exposed to userspace, so we just need to show them. The result as follows, tools/bpf/bpftool/bpftool link show 2: tracing prog 13 prog_type tracing attach_type trace_fentry target_obj_id 1 target_btf_id 13964 pids trace(10673) $ tools/bpf/bpftool/bpftool link show -j [{"id":2,"type":"tracing","prog_id":13,"prog_type":"tracing","attach_type":"trace_fentry","target_obj_id":1,"target_btf_id":13964,"pids":[{"pid":10673,"comm":"trace"}]}] $ cat /proc/10673/fdinfo/10 pos: 0 flags: 02000000 mnt_id: 15 ino: 2094 link_type: tracing link_id: 2 prog_tag: a04f5eef06a7f555 prog_id: 13 attach_type: 24 target_obj_id: 1 target_btf_id: 13964 $ tail /proc/kallsyms ffffffffc0400fa0 t bpf_prog_a04f5eef06a7f555_fentry_run [bpf] ffffffffc062f000 t bpf_trampoline_6442464908 [bpf] $ echo $((6442464908 & 0x7fffffff)) $((6442464908 >> 32)) 13964 1 Signed-off-by: Yafang Shao <laoar.shao@gmail.com> --- kernel/bpf/syscall.c | 12 ++++++++++-- tools/bpf/bpftool/link.c | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-)