Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+15 -2
+9 -2
kernel/bpf/syscall.c
··· 2968 2968 { 2969 2969 struct bpf_tracing_link *tr_link = 2970 2970 container_of(link, struct bpf_tracing_link, link.link); 2971 + u32 target_btf_id, target_obj_id; 2971 2972 2973 + bpf_trampoline_unpack_key(tr_link->trampoline->key, 2974 + &target_obj_id, &target_btf_id); 2972 2975 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); 2975 2982 } 2976 2983 2977 2984 static int bpf_tracing_link_fill_link_info(const struct bpf_link *link,
+6
tools/bpf/bpftool/link.c
··· 195 195 196 196 show_link_attach_type_json(info->tracing.attach_type, 197 197 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); 198 200 break; 199 201 case BPF_LINK_TYPE_CGROUP: 200 202 jsonw_lluint_field(json_wtr, "cgroup_id", ··· 377 375 printf("\n\tprog_type %u ", prog_info.type); 378 376 379 377 show_link_attach_type_plain(info->tracing.attach_type); 378 + if (info->tracing.target_obj_id || info->tracing.target_btf_id) 379 + printf("\n\ttarget_obj_id %u target_btf_id %u ", 380 + info->tracing.target_obj_id, 381 + info->tracing.target_btf_id); 380 382 break; 381 383 case BPF_LINK_TYPE_CGROUP: 382 384 printf("\n\tcgroup_id %zu ", (size_t)info->cgroup.cgroup_id);