* [PATCH bpf-next v2 1/2] bpf: Show target_{obj,btf}_id in tracing link fdinfo
2023-05-17 10:31 [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link Yafang Shao
@ 2023-05-17 10:31 ` Yafang Shao
2023-05-17 10:31 ` [PATCH bpf-next v2 2/2] bpftool: Show target_{obj,btf}_id in tracing link info Yafang Shao
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yafang Shao @ 2023-05-17 10:31 UTC (permalink / raw)
To: quentin, ast, daniel, john.fastabend, andrii, martin.lau, song,
yhs, kpsingh, sdf, haoluo, jolsa
Cc: bpf, Yafang Shao
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
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Song Liu <song@kernel.org>
---
kernel/bpf/syscall.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 909c112..b262108 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -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,
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next v2 2/2] bpftool: Show target_{obj,btf}_id in tracing link info
2023-05-17 10:31 [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link Yafang Shao
2023-05-17 10:31 ` [PATCH bpf-next v2 1/2] bpf: Show target_{obj,btf}_id in tracing link fdinfo Yafang Shao
@ 2023-05-17 10:31 ` Yafang Shao
2023-05-17 14:14 ` [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link Quentin Monnet
2023-05-19 17:10 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Yafang Shao @ 2023-05-17 10:31 UTC (permalink / raw)
To: quentin, ast, daniel, john.fastabend, andrii, martin.lau, song,
yhs, kpsingh, sdf, haoluo, jolsa
Cc: bpf, Yafang Shao
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"}]}]
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Song Liu <song@kernel.org>
---
tools/bpf/bpftool/link.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 243b74e..2d78607 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,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);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link
2023-05-17 10:31 [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link Yafang Shao
2023-05-17 10:31 ` [PATCH bpf-next v2 1/2] bpf: Show target_{obj,btf}_id in tracing link fdinfo Yafang Shao
2023-05-17 10:31 ` [PATCH bpf-next v2 2/2] bpftool: Show target_{obj,btf}_id in tracing link info Yafang Shao
@ 2023-05-17 14:14 ` Quentin Monnet
2023-05-19 17:10 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Quentin Monnet @ 2023-05-17 14:14 UTC (permalink / raw)
To: Yafang Shao, ast, daniel, john.fastabend, andrii, martin.lau,
song, yhs, kpsingh, sdf, haoluo, jolsa
Cc: bpf
2023-05-17 10:31 UTC+0000 ~ Yafang Shao <laoar.shao@gmail.com>
> 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(-)
>
Acked-by: Quentin Monnet <quentin@isovalent.com>
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link
2023-05-17 10:31 [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link Yafang Shao
` (2 preceding siblings ...)
2023-05-17 14:14 ` [PATCH bpf-next v2 0/2] bpf: Show target_{obj,btf}_id for tracing link Quentin Monnet
@ 2023-05-19 17:10 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-05-19 17:10 UTC (permalink / raw)
To: Yafang Shao
Cc: quentin, ast, daniel, john.fastabend, andrii, martin.lau, song,
yhs, kpsingh, sdf, haoluo, jolsa, bpf
Hello:
This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 17 May 2023 10:31:24 +0000 you wrote:
> 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.
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread