bpf: Show target_{obj,btf}_id for tracing link
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.
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 | 12 ++++++++++-- tools/bpf/bpftool/link.c | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/bpf/syscall.c +10 -2
@@ -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,
Signature · 1 line
1.8.3.1
Re: [PATCH bpf-next 1/2] bpf: Show target_{obj,btf}_id in tracing link fdinfo
Quoted 31 lines · Yafang Shao
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.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: 13964Signed-off-by Yafang Shao <[email protected]>Acked-by Song Liu <[email protected]>--- kernel/bpf/syscall.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)kernel/bpf/syscall.c +0
-0
kernel/bpf/syscall.c static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link, · line 2972
Quoted 5 lines
kernel/bpf/syscall.c +2
-0@@ -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;
nit: combine on a single line?
kernel/bpf/syscall.c static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link, · line 2975
Quoted 3 lines
kernel/bpf/syscall.c +2
-0+bpf_trampoline_unpack_key (tr_link->trampoline->key, + &target_obj_id, &target_btf_id);
formatting seems odd?...
Quoted 15 lines
kernel/bpf/syscall.c +6
-3seq_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, --1.8.3.1
Re: [PATCH bpf-next 1/2] bpf: Show target_{obj,btf}_id in tracing link fdinfo
Quoted 28 lines · Andrii Nakryiko
Quoted 26 lines · Yafang Shao
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.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: 13964Signed-off-by Yafang Shao <[email protected]>Acked-by Song Liu <[email protected]>--- kernel/bpf/syscall.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
Quoted 13 lines
kernel/bpf/syscall.c static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link, · line 2972
Quoted 10 lines
kernel/bpf/syscall.c +2
-0@@ -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;nit: combine on a single line?
Will change it.
Quoted 6 lines
kernel/bpf/syscall.c static void bpf_tracing_link_show_fdinfo(const struct bpf_link *link, · line 2975
Quoted 3 lines
kernel/bpf/syscall.c +2
-0+bpf_trampoline_unpack_key (tr_link->trampoline->key, + &target_obj_id, &target_btf_id);formatting seems odd?...
It is because the vim table size on my current dev server is 4. Will correct it.
Signature · 2 lines
Regards Yafang
PATCH 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 | 4 ++++ 1 file changed, 4 insertions(+)
tools/bpf/bpftool/link.c +4 -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,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);
Signature · 1 line
1.8.3.1
Re: [PATCH bpf-next 2/2] bpftool: Show target_{obj,btf}_id in tracing link info
2023-05-16 12:39 UTC+0000 ~ Yafang Shao <[email protected]>
Quoted 35 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.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"}]}]Signed-off-by Yafang Shao <[email protected]>Acked-by Song Liu <[email protected]>--- tools/bpf/bpftool/link.c | 4 ++++ 1 file changed, 4 insertions(+)tools/bpf/bpftool/link.c +2
-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",
tools/bpf/bpftool/link.c static int show_link_close_plain(int fd, struct bpf_link_info *info) · line 381
Quoted 5 lines
tools/bpf/bpftool/link.c +2
-0@@ -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);
Older kernels won't share this info, so maybe we can skip this printf() in plain output if the target object and BTF ids are 0?
Quoted 3 lines
tools/bpf/bpftool/link.c +0
-0break ;case BPF_LINK_TYPE_CGROUP :printf ("\n\tcgroup_id %zu " , (size_t )info->cgroup.cgroup_id);
Re: [PATCH bpf-next 2/2] bpftool: Show target_{obj,btf}_id in tracing link info
Quoted 39 lines · Quentin Monnet
2023-05-16 12:39 UTC+0000 ~ Yafang Shao <[email protected]>
Quoted 37 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.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"}]}]Signed-off-by Yafang Shao <[email protected]>Acked-by Song Liu <[email protected]>--- tools/bpf/bpftool/link.c | 4 ++++ 1 file changed, 4 insertions(+)tools/bpf/bpftool/link.c +2
-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,8 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)printf ("\n\tprog_type %u " , prog_info.type);
Quoted 7 lines
tools/bpf/bpftool/link.c static int show_link_close_plain(int fd, struct bpf_link_info *info) · line 381
Quoted 3 lines
tools/bpf/bpftool/link.c +2
-0show_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);Older kernels won't share this info, so maybe we can skip this
printf()in plain output if the target object and BTF ids are 0?
Good suggestion. Will change it in the next version. BTW, shouldn't we skip it in the json output as well ?
Signature · 2 lines
Regards Yafang
Re: [PATCH bpf-next 2/2] bpftool: Show target_{obj,btf}_id in tracing link info
2023-05-16 21:09 UTC+0800 ~ Yafang Shao <[email protected]>
Quoted 48 lines · Quentin Monnet
Quoted 39 lines
2023-05-16 12:39 UTC+0000 ~ Yafang Shao <[email protected]>
Quoted 37 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.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"}]}]Signed-off-by Yafang Shao <[email protected]>Acked-by Song Liu <[email protected]>--- tools/bpf/bpftool/link.c | 4 ++++ 1 file changed, 4 insertions(+)tools/bpf/bpftool/link.c +2
-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,8 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)printf ("\n\tprog_type %u " , prog_info.type);Quoted 7 lines
tools/bpf/bpftool/link.c static int show_link_close_plain(int fd, struct bpf_link_info *info) · line 381
Quoted 3 lines
tools/bpf/bpftool/link.c +2
-0show_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);Older kernels won't share this info, so maybe we can skip this
printf()in plain output if the target object and BTF ids are 0?
Quoted 2 lines
Good suggestion. Will change it in the next version. BTW, shouldn't we skip it in the json output as well ?
I'd keep it in JSON. Plain output is for reading in the console, we want to make it easy for users to find the relevant info. JSON is for machine consumption, it's OK to be more exhaustive and to leave it to the consuming program to decide what's relevant and what's not.
Quentin
Re: [PATCH bpf-next 2/2] bpftool: Show target_{obj,btf}_id in tracing link info
Quoted 50 lines · Quentin Monnet
2023-05-16 21:09 UTC+0800 ~ Yafang Shao <[email protected]>
Quoted 48 lines · Quentin Monnet
Quoted 46 lines
2023-05-16 12:39 UTC+0000 ~ Yafang Shao <[email protected]>
Quoted 35 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.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"}]}]Signed-off-by Yafang Shao <[email protected]>Acked-by Song Liu <[email protected]>--- tools/bpf/bpftool/link.c | 4 ++++ 1 file changed, 4 insertions(+)tools/bpf/bpftool/link.c +2
-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",tools/bpf/bpftool/link.c static int show_link_close_plain(int fd, struct bpf_link_info *info) · line 381
Quoted 5 lines
tools/bpf/bpftool/link.c +2
-0@@ -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);Older kernels won't share this info, so maybe we can skip this
printf()in plain output if the target object and BTF ids are 0?
Quoted 8 lines
Quoted 2 lines
Good suggestion. Will change it in the next version. BTW, shouldn't we skip it in the json output as well ?
I'd keep it in JSON. Plain output is for reading in the console, we want to make it easy for users to find the relevant info. JSON is for machine consumption, it's OK to be more exhaustive and to leave it to the consuming program to decide what's relevant and what's not.
Got it. Thanks for the explanation.
Signature · 2 lines
Regards Yafang