diff mbox series

[bpf-next,1/2] bpf: Show target_{obj,btf}_id in tracing link fdinfo

Message ID 20230516123926.57623-2-laoar.shao@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series bpf: Show target_{obj,btf}_id for tracing link | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 10 this patch: 10
netdev/cc_maintainers warning 1 maintainers not CCed: martin.lau@linux.dev
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 10 this patch: 10
netdev/checkpatch warning CHECK: Alignment should match open parenthesis WARNING: line length of 90 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }}
bpf/vmtest-bpf-next-VM_Test-2 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-9 success Logs for veristat

Commit Message

Yafang Shao May 16, 2023, 12:39 p.m. UTC
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 | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko May 16, 2023, 10:27 p.m. UTC | #1
On Tue, May 16, 2023 at 5:39 AM Yafang Shao <laoar.shao@gmail.com> 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.
>
> 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 | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 909c112..870395a 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -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?

>
> +       bpf_trampoline_unpack_key(tr_link->trampoline->key,
> +                                                         &target_obj_id, &target_btf_id);

formatting seems odd?...


>         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
>
Yafang Shao May 17, 2023, 3 a.m. UTC | #2
On Wed, May 17, 2023 at 6:28 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Tue, May 16, 2023 at 5:39 AM Yafang Shao <laoar.shao@gmail.com> 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.
> >
> > 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 | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index 909c112..870395a 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -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.

> >
> > +       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.
diff mbox series

Patch

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 909c112..870395a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -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,