diff mbox series

[bpf-next,v2] bpftool: Show map IDs along with struct_ops links.

Message ID 20230419003651.988865-1-kuifeng@meta.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next,v2] bpftool: Show map IDs along with struct_ops links. | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
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: 18 this patch: 18
netdev/cc_maintainers warning 7 maintainers not CCed: sdf@google.com haoluo@google.com yhs@fb.com daniel@iogearbox.net john.fastabend@gmail.com kpsingh@kernel.org jolsa@kernel.org
netdev/build_clang success Errors and warnings before: 18 this patch: 18
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: 18 this patch: 18
netdev/checkpatch warning WARNING: From:/Signed-off-by: email address mismatch: 'From: Kui-Feng Lee <thinker.li@gmail.com>' != 'Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>'
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-36 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc

Commit Message

Kui-Feng Lee April 19, 2023, 12:36 a.m. UTC
A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach
struct_ops to links. (226bc6ae6405) It would be helpful for users to
know which map is associated with the link.

The assumption was that every link is associated with a BPF program, but
this does not hold true for struct_ops. It would be better to display
map_id instead of prog_id for struct_ops links. However, some tools may
rely on the old assumption and need a prog_id.  The discussion on the
mailing list suggests that tools should parse JSON format. We will maintain
the existing JSON format by adding a map_id without removing prog_id. As
for plain text format, we will remove prog_id from the header line and add
a map_id for struct_ops links.

Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
---
 tools/bpf/bpftool/link.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Quentin Monnet April 19, 2023, 11:25 p.m. UTC | #1
On Wed, 19 Apr 2023 at 01:37, Kui-Feng Lee <thinker.li@gmail.com> wrote:
>
> A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach
> struct_ops to links. (226bc6ae6405) It would be helpful for users to
> know which map is associated with the link.
>
> The assumption was that every link is associated with a BPF program, but
> this does not hold true for struct_ops. It would be better to display
> map_id instead of prog_id for struct_ops links. However, some tools may
> rely on the old assumption and need a prog_id.  The discussion on the
> mailing list suggests that tools should parse JSON format. We will maintain
> the existing JSON format by adding a map_id without removing prog_id. As
> for plain text format, we will remove prog_id from the header line and add
> a map_id for struct_ops links.
>
> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
> Reviewed-by: Quentin Monnet <quentin@isovalent.com>

Looks all good from my side, thank you.
Kui-Feng Lee April 20, 2023, 12:23 a.m. UTC | #2
Thank you for reviewing this.

On 4/19/23 16:25, Quentin Monnet wrote:
> On Wed, 19 Apr 2023 at 01:37, Kui-Feng Lee <thinker.li@gmail.com> wrote:
>>
>> A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach
>> struct_ops to links. (226bc6ae6405) It would be helpful for users to
>> know which map is associated with the link.
>>
>> The assumption was that every link is associated with a BPF program, but
>> this does not hold true for struct_ops. It would be better to display
>> map_id instead of prog_id for struct_ops links. However, some tools may
>> rely on the old assumption and need a prog_id.  The discussion on the
>> mailing list suggests that tools should parse JSON format. We will maintain
>> the existing JSON format by adding a map_id without removing prog_id. As
>> for plain text format, we will remove prog_id from the header line and add
>> a map_id for struct_ops links.
>>
>> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
>> Reviewed-by: Quentin Monnet <quentin@isovalent.com>
> 
> Looks all good from my side, thank you.
Andrii Nakryiko April 20, 2023, 11:41 p.m. UTC | #3
On Tue, Apr 18, 2023 at 5:37 PM Kui-Feng Lee <thinker.li@gmail.com> wrote:
>
> A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach
> struct_ops to links. (226bc6ae6405) It would be helpful for users to
> know which map is associated with the link.
>
> The assumption was that every link is associated with a BPF program, but
> this does not hold true for struct_ops. It would be better to display
> map_id instead of prog_id for struct_ops links. However, some tools may
> rely on the old assumption and need a prog_id.  The discussion on the
> mailing list suggests that tools should parse JSON format. We will maintain
> the existing JSON format by adding a map_id without removing prog_id. As
> for plain text format, we will remove prog_id from the header line and add
> a map_id for struct_ops links.
>
> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
> Reviewed-by: Quentin Monnet <quentin@isovalent.com>
> ---
>  tools/bpf/bpftool/link.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> index f985b79cca27..8eb8520bd7b4 100644
> --- a/tools/bpf/bpftool/link.c
> +++ b/tools/bpf/bpftool/link.c
> @@ -195,6 +195,10 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
>                                  info->netns.netns_ino);
>                 show_link_attach_type_json(info->netns.attach_type, json_wtr);
>                 break;
> +       case BPF_LINK_TYPE_STRUCT_OPS:
> +               jsonw_uint_field(json_wtr, "map_id",
> +                                info->struct_ops.map_id);
> +               break;
>         default:
>                 break;
>         }
> @@ -227,7 +231,10 @@ static void show_link_header_plain(struct bpf_link_info *info)
>         else
>                 printf("type %u  ", info->type);
>
> -       printf("prog %u  ", info->prog_id);
> +       if (info->type == BPF_LINK_TYPE_STRUCT_OPS)
> +               printf("map_id %u  ", info->struct_ops.map_id);
> +       else
> +               printf("prog %u  ", info->prog_id);

if we output "prog %u" for prog_id, shouldn't we just output "map %u"
for map_id?

>  }
>
>  static void show_link_attach_type_plain(__u32 attach_type)
> --
> 2.34.1
>
Kui-Feng Lee April 21, 2023, 4:21 p.m. UTC | #4
On 4/20/23 16:41, Andrii Nakryiko wrote:
> On Tue, Apr 18, 2023 at 5:37 PM Kui-Feng Lee <thinker.li@gmail.com> wrote:
>>
>> A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach
>> struct_ops to links. (226bc6ae6405) It would be helpful for users to
>> know which map is associated with the link.
>>
>> The assumption was that every link is associated with a BPF program, but
>> this does not hold true for struct_ops. It would be better to display
>> map_id instead of prog_id for struct_ops links. However, some tools may
>> rely on the old assumption and need a prog_id.  The discussion on the
>> mailing list suggests that tools should parse JSON format. We will maintain
>> the existing JSON format by adding a map_id without removing prog_id. As
>> for plain text format, we will remove prog_id from the header line and add
>> a map_id for struct_ops links.
>>
>> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
>> Reviewed-by: Quentin Monnet <quentin@isovalent.com>
>> ---
>>   tools/bpf/bpftool/link.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
>> index f985b79cca27..8eb8520bd7b4 100644
>> --- a/tools/bpf/bpftool/link.c
>> +++ b/tools/bpf/bpftool/link.c
>> @@ -195,6 +195,10 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
>>                                   info->netns.netns_ino);
>>                  show_link_attach_type_json(info->netns.attach_type, json_wtr);
>>                  break;
>> +       case BPF_LINK_TYPE_STRUCT_OPS:
>> +               jsonw_uint_field(json_wtr, "map_id",
>> +                                info->struct_ops.map_id);
>> +               break;
>>          default:
>>                  break;
>>          }
>> @@ -227,7 +231,10 @@ static void show_link_header_plain(struct bpf_link_info *info)
>>          else
>>                  printf("type %u  ", info->type);
>>
>> -       printf("prog %u  ", info->prog_id);
>> +       if (info->type == BPF_LINK_TYPE_STRUCT_OPS)
>> +               printf("map_id %u  ", info->struct_ops.map_id);
>> +       else
>> +               printf("prog %u  ", info->prog_id);
> 
> if we output "prog %u" for prog_id, shouldn't we just output "map %u"
> for map_id?

"map" make sense to me.

> 
>>   }
>>
>>   static void show_link_attach_type_plain(__u32 attach_type)
>> --
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index f985b79cca27..8eb8520bd7b4 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -195,6 +195,10 @@  static int show_link_close_json(int fd, struct bpf_link_info *info)
 				 info->netns.netns_ino);
 		show_link_attach_type_json(info->netns.attach_type, json_wtr);
 		break;
+	case BPF_LINK_TYPE_STRUCT_OPS:
+		jsonw_uint_field(json_wtr, "map_id",
+				 info->struct_ops.map_id);
+		break;
 	default:
 		break;
 	}
@@ -227,7 +231,10 @@  static void show_link_header_plain(struct bpf_link_info *info)
 	else
 		printf("type %u  ", info->type);
 
-	printf("prog %u  ", info->prog_id);
+	if (info->type == BPF_LINK_TYPE_STRUCT_OPS)
+		printf("map_id %u  ", info->struct_ops.map_id);
+	else
+		printf("prog %u  ", info->prog_id);
 }
 
 static void show_link_attach_type_plain(__u32 attach_type)