Skip to content

Commit 9343184

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf: Show target_{obj,btf}_id for tracing link'
Yafang Shao says: ==================== 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) ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents effcf62 + d7e45eb commit 9343184

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

kernel/bpf/syscall.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,10 +2968,17 @@ static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link,
29682968
{
29692969
struct bpf_tracing_link *tr_link =
29702970
container_of(link, struct bpf_tracing_link, link.link);
2971+
u32 target_btf_id, target_obj_id;
29712972

2973+
bpf_trampoline_unpack_key(tr_link->trampoline->key,
2974+
&target_obj_id, &target_btf_id);
29722975
seq_printf(seq,
2973-
"attach_type:\t%d\n",
2974-
tr_link->attach_type);
2976+
"attach_type:\t%d\n"
2977+
"target_obj_id:\t%u\n"
2978+
"target_btf_id:\t%u\n",
2979+
tr_link->attach_type,
2980+
target_obj_id,
2981+
target_btf_id);
29752982
}
29762983

29772984
static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,

tools/bpf/bpftool/link.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
195195

196196
show_link_attach_type_json(info->tracing.attach_type,
197197
json_wtr);
198+
jsonw_uint_field(json_wtr, "target_obj_id", info->tracing.target_obj_id);
199+
jsonw_uint_field(json_wtr, "target_btf_id", info->tracing.target_btf_id);
198200
break;
199201
case BPF_LINK_TYPE_CGROUP:
200202
jsonw_lluint_field(json_wtr, "cgroup_id",
@@ -375,6 +377,10 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
375377
printf("\n\tprog_type %u ", prog_info.type);
376378

377379
show_link_attach_type_plain(info->tracing.attach_type);
380+
if (info->tracing.target_obj_id || info->tracing.target_btf_id)
381+
printf("\n\ttarget_obj_id %u target_btf_id %u ",
382+
info->tracing.target_obj_id,
383+
info->tracing.target_btf_id);
378384
break;
379385
case BPF_LINK_TYPE_CGROUP:
380386
printf("\n\tcgroup_id %zu ", (size_t)info->cgroup.cgroup_id);

0 commit comments

Comments
 (0)