bpf: Show target_{obj,btf}_id for tracing link
v2 cover bpf: Show target_{obj,btf}_id for tracing link
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.
For some other link types like perf_event and kprobe_multi, it is not easy to find which functions are attached either. We may support ->fill_link_info for them in the future.
v1->v2:
- Skip showing them in the plain output for the old kernels. (Quentin)
- Coding improvement. (Andrii)
Yafang Shao (2):
bpf: Show target_{obj,btf}_id in tracing link fdinfo
bpftool: Show target_{obj,btf}_id in tracing link info
kernel/bpf/syscall.c | 11 +++++++++-- tools/bpf/bpftool/link.c | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/2 bpf: Show target_{obj,btf}_id in tracing link fdinfo
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,
$ 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
--- kernel/bpf/syscall.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/syscall.c +9 -2
@@ -2968,10 +2968,17 @@ 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, 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,
Signature · 1 line
1.8.3.1
PATCH v2 2/2 bpftool: Show target_{obj,btf}_id in tracing link info
In reply to Yafang ShaoThe 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"}]}]--- tools/bpf/bpftool/link.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/bpf/bpftool/link.c +6 -0
@@ -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,10 @@ 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); +if (info->tracing.target_obj_id || info->tracing.target_btf_id) +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);
Signature · 1 line
1.8.3.1
2023-05-17 10:31 UTC+0000 ~ Yafang Shao <[email protected]>
Quoted 12 lines
The
target_btf_idcan help us understand which kernel function is linked by a tracing prog. Thetarget_btf_idandtarget_obj_idhave already been exposed to userspace, so we just need to show them.For some other link types like
perf_eventandkprobe_multi, it is not easy to find which functions are attached either. We may support ->fill_link_info for them in the future.
v1->v2:
- Skip showing them in the plain output for the old kernels. (Quentin)
- Coding improvement. (Andrii)
Quoted 8 lines
Yafang Shao (2):
bpf: Show target_{obj,btf}_id in tracing link fdinfo
bpftool: Show target_{obj,btf}_id in tracing link infokernel/bpf/syscall.c | 11 +++++++++-- tools/bpf/bpftool/link.c | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-)
Thanks!
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Wed, 17 May 2023 10:31:24 +0000 you wrote:
The
target_btf_idcan help us understand which kernel function is linked by a tracing prog. Thetarget_btf_idandtarget_obj_idhave already been exposed to userspace, so we just need to show them.For some other link types like
perf_eventandkprobe_multi, it is not easy to find which functions are attached either. We may support ->fill_link_info for them in the future.[...]
Here is the summary with links:
- [bpf-next,v2,1/2] bpf: Show target_{obj,btf}_id in tracing link fdinfo
https://git.kernel.org/bpf/bpf-next/c/e859e429511a - [bpf-next,v2,2/2] bpftool: Show target_{obj,btf}_id in tracing link info https://git.kernel.org/bpf/bpf-next/c/d7e45eb4802b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html