diff mbox series

[bpf-next,8/8] bpftool: Display cookie for kprobe multi link

Message ID 20240118095416.989152-9-jolsa@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series bpf: Add cookies retrieval for perf/kprobe multi links | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 fail Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
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: 8 this patch: 8
netdev/cc_maintainers success CCed 0 of 0 maintainers
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: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 90 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiri Olsa Jan. 18, 2024, 9:54 a.m. UTC
Displaying cookies for kprobe multi link, in plain mode:

  # bpftool link
  ...
  1397: kprobe_multi  prog 47532
          kretprobe.multi  func_cnt 3
          addr             cookie           func [module]
          ffffffff82b370c0 3                bpf_fentry_test1
          ffffffff82b39780 1                bpf_fentry_test2
          ffffffff82b397a0 2                bpf_fentry_test3

And in json mode:

  # bpftool link -j | jq
  ...
    {
      "id": 1397,
      "type": "kprobe_multi",
      "prog_id": 47532,
      "retprobe": true,
      "func_cnt": 3,
      "missed": 0,
      "funcs": [
        {
          "addr": 18446744071607382208,
          "func": "bpf_fentry_test1",
          "module": null,
          "cookie": 3
        },
        {
          "addr": 18446744071607392128,
          "func": "bpf_fentry_test2",
          "module": null,
          "cookie": 1
        },
        {
          "addr": 18446744071607392160,
          "func": "bpf_fentry_test3",
          "module": null,
          "cookie": 2
        }
      ]
    }

Cookie is attached to specific address, and because we sort addresses
before printing, we need to sort cookies the same way, hence adding
the struct addr_cookie to keep and sort them together.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/bpf/bpftool/link.c | 71 ++++++++++++++++++++++++++++++++--------
 1 file changed, 57 insertions(+), 14 deletions(-)

Comments

Quentin Monnet Jan. 18, 2024, 5:51 p.m. UTC | #1
2024-01-18 09:55 UTC+0000 ~ Jiri Olsa <jolsa@kernel.org>
> Displaying cookies for kprobe multi link, in plain mode:
> 
>   # bpftool link
>   ...
>   1397: kprobe_multi  prog 47532
>           kretprobe.multi  func_cnt 3
>           addr             cookie           func [module]
>           ffffffff82b370c0 3                bpf_fentry_test1
>           ffffffff82b39780 1                bpf_fentry_test2
>           ffffffff82b397a0 2                bpf_fentry_test3
> 
> And in json mode:
> 
>   # bpftool link -j | jq
>   ...
>     {
>       "id": 1397,
>       "type": "kprobe_multi",
>       "prog_id": 47532,
>       "retprobe": true,
>       "func_cnt": 3,
>       "missed": 0,
>       "funcs": [
>         {
>           "addr": 18446744071607382208,
>           "func": "bpf_fentry_test1",
>           "module": null,
>           "cookie": 3
>         },
>         {
>           "addr": 18446744071607392128,
>           "func": "bpf_fentry_test2",
>           "module": null,
>           "cookie": 1
>         },
>         {
>           "addr": 18446744071607392160,
>           "func": "bpf_fentry_test3",
>           "module": null,
>           "cookie": 2
>         }
>       ]
>     }
> 
> Cookie is attached to specific address, and because we sort addresses
> before printing, we need to sort cookies the same way, hence adding
> the struct addr_cookie to keep and sort them together.
> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/bpf/bpftool/link.c | 71 ++++++++++++++++++++++++++++++++--------
>  1 file changed, 57 insertions(+), 14 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> index b66a1598b87c..fd862afe6c6f 100644
> --- a/tools/bpf/bpftool/link.c
> +++ b/tools/bpf/bpftool/link.c
> @@ -249,18 +249,44 @@ static int get_prog_info(int prog_id, struct bpf_prog_info *info)
>  	return err;
>  }
>  
> -static int cmp_u64(const void *A, const void *B)
> +struct addr_cookie {
> +	__u64 addr;
> +	__u64 cookie;
> +};
> +
> +static int cmp_addr_cookie(const void *A, const void *B)
> +{
> +	const struct addr_cookie *a = A, *b = B;
> +
> +	if (a->addr == b->addr)
> +		return 0;
> +	return a->addr < b->addr ? -1 : 1;
> +}
> +
> +static struct addr_cookie *
> +get_addr_cookie_array(__u64 *addrs, __u64 *cookies, __u32 count)
>  {
> -	const __u64 *a = A, *b = B;
> +	struct addr_cookie *data;
> +	__u32 i;
>  
> -	return *a - *b;
> +	data = calloc(count, sizeof(data[0]));
> +	if (!data) {
> +		p_err("mem alloc failed");
> +		return NULL;
> +	}
> +	for (i = 0; i < count; i++) {
> +		data[i].addr = addrs[i];
> +		data[i].cookie = cookies[i];
> +	}
> +	qsort(data, count, sizeof(data[0]), cmp_addr_cookie);
> +	return data;
>  }
>  
>  static void
>  show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
>  {
> +	struct addr_cookie *data;
>  	__u32 i, j = 0;
> -	__u64 *addrs;
>  
>  	jsonw_bool_field(json_wtr, "retprobe",
>  			 info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_RETURN);
> @@ -268,14 +294,17 @@ show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
>  	jsonw_uint_field(json_wtr, "missed", info->kprobe_multi.missed);
>  	jsonw_name(json_wtr, "funcs");
>  	jsonw_start_array(json_wtr);
> -	addrs = u64_to_ptr(info->kprobe_multi.addrs);
> -	qsort(addrs, info->kprobe_multi.count, sizeof(addrs[0]), cmp_u64);
> +	data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
> +				     u64_to_ptr(info->kprobe_multi.cookies),
> +				     info->kprobe_multi.count);
> +	if (!data)
> +		return;
>  
>  	/* Load it once for all. */
>  	if (!dd.sym_count)
>  		kernel_syms_load(&dd);
>  	for (i = 0; i < dd.sym_count; i++) {
> -		if (dd.sym_mapping[i].address != addrs[j])
> +		if (dd.sym_mapping[i].address != data[j].addr)
>  			continue;
>  		jsonw_start_object(json_wtr);
>  		jsonw_uint_field(json_wtr, "addr", dd.sym_mapping[i].address);
> @@ -287,11 +316,13 @@ show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
>  		} else {
>  			jsonw_string_field(json_wtr, "module", dd.sym_mapping[i].module);
>  		}
> +		jsonw_uint_field(json_wtr, "cookie", data[j].cookie);
>  		jsonw_end_object(json_wtr);
>  		if (j++ == info->kprobe_multi.count)
>  			break;
>  	}
>  	jsonw_end_array(json_wtr);
> +	free(data);
>  }
>  
>  static __u64 *u64_to_arr(__u64 val)
> @@ -675,8 +706,8 @@ void netfilter_dump_plain(const struct bpf_link_info *info)
>  
>  static void show_kprobe_multi_plain(struct bpf_link_info *info)
>  {
> +	struct addr_cookie *data;
>  	__u32 i, j = 0;
> -	__u64 *addrs;
>  
>  	if (!info->kprobe_multi.count)
>  		return;
> @@ -688,8 +719,11 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
>  	printf("func_cnt %u  ", info->kprobe_multi.count);
>  	if (info->kprobe_multi.missed)
>  		printf("missed %llu  ", info->kprobe_multi.missed);
> -	addrs = (__u64 *)u64_to_ptr(info->kprobe_multi.addrs);
> -	qsort(addrs, info->kprobe_multi.count, sizeof(__u64), cmp_u64);
> +	data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
> +				     u64_to_ptr(info->kprobe_multi.cookies),
> +				     info->kprobe_multi.count);
> +	if (!data)
> +		return;
>  
>  	/* Load it once for all. */
>  	if (!dd.sym_count)
> @@ -697,12 +731,12 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
>  	if (!dd.sym_count)
>  		return;

Don't we need to free(data) if we return here?

>  
> -	printf("\n\t%-16s %s", "addr", "func [module]");
> +	printf("\n\t%-16s %-16s %s", "addr", "cookie", "func [module]");
>  	for (i = 0; i < dd.sym_count; i++) {
> -		if (dd.sym_mapping[i].address != addrs[j])
> +		if (dd.sym_mapping[i].address != data[j].addr)
>  			continue;
> -		printf("\n\t%016lx %s",
> -		       dd.sym_mapping[i].address, dd.sym_mapping[i].name);
> +		printf("\n\t%016lx %-16llx %s",
> +		       dd.sym_mapping[i].address, data[j].cookie, dd.sym_mapping[i].name);
>  		if (dd.sym_mapping[i].module[0] != '\0')
>  			printf(" [%s]  ", dd.sym_mapping[i].module);
>  		else
> @@ -711,6 +745,7 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
>  		if (j++ == info->kprobe_multi.count)
>  			break;
>  	}
> +	free(data);
>  }
>  
>  static void show_uprobe_multi_plain(struct bpf_link_info *info)
> @@ -966,6 +1001,14 @@ static int do_show_link(int fd)
>  				return -ENOMEM;
>  			}
>  			info.kprobe_multi.addrs = ptr_to_u64(addrs);
> +			cookies = calloc(count, sizeof(__u64));
> +			if (!cookies) {
> +				p_err("mem alloc failed");
> +				free(addrs);
> +				close(fd);
> +				return -ENOMEM;
> +			}
> +			info.kprobe_multi.cookies = ptr_to_u64(cookies);
>  			goto again;
>  		}
>  	}
Jiri Olsa Jan. 19, 2024, 8:03 a.m. UTC | #2
On Thu, Jan 18, 2024 at 05:51:17PM +0000, Quentin Monnet wrote:

SNIP

> >  static __u64 *u64_to_arr(__u64 val)
> > @@ -675,8 +706,8 @@ void netfilter_dump_plain(const struct bpf_link_info *info)
> >  
> >  static void show_kprobe_multi_plain(struct bpf_link_info *info)
> >  {
> > +	struct addr_cookie *data;
> >  	__u32 i, j = 0;
> > -	__u64 *addrs;
> >  
> >  	if (!info->kprobe_multi.count)
> >  		return;
> > @@ -688,8 +719,11 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
> >  	printf("func_cnt %u  ", info->kprobe_multi.count);
> >  	if (info->kprobe_multi.missed)
> >  		printf("missed %llu  ", info->kprobe_multi.missed);
> > -	addrs = (__u64 *)u64_to_ptr(info->kprobe_multi.addrs);
> > -	qsort(addrs, info->kprobe_multi.count, sizeof(__u64), cmp_u64);
> > +	data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
> > +				     u64_to_ptr(info->kprobe_multi.cookies),
> > +				     info->kprobe_multi.count);
> > +	if (!data)
> > +		return;
> >  
> >  	/* Load it once for all. */
> >  	if (!dd.sym_count)
> > @@ -697,12 +731,12 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
> >  	if (!dd.sym_count)
> >  		return;
> 
> Don't we need to free(data) if we return here?

good catch! I guess I got distracted by show_kprobe_multi_plain being
similar to show_kprobe_multi_json, which does not check dd.sym_count
and does not return, which it should :-\ I'll include that fix as well

thanks,
jirka

> 
> >  
> > -	printf("\n\t%-16s %s", "addr", "func [module]");
> > +	printf("\n\t%-16s %-16s %s", "addr", "cookie", "func [module]");
> >  	for (i = 0; i < dd.sym_count; i++) {
> > -		if (dd.sym_mapping[i].address != addrs[j])
> > +		if (dd.sym_mapping[i].address != data[j].addr)
> >  			continue;
> > -		printf("\n\t%016lx %s",
> > -		       dd.sym_mapping[i].address, dd.sym_mapping[i].name);
> > +		printf("\n\t%016lx %-16llx %s",
> > +		       dd.sym_mapping[i].address, data[j].cookie, dd.sym_mapping[i].name);
> >  		if (dd.sym_mapping[i].module[0] != '\0')
> >  			printf(" [%s]  ", dd.sym_mapping[i].module);
> >  		else
> > @@ -711,6 +745,7 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
> >  		if (j++ == info->kprobe_multi.count)
> >  			break;
> >  	}
> > +	free(data);
> >  }
> >  
> >  static void show_uprobe_multi_plain(struct bpf_link_info *info)
> > @@ -966,6 +1001,14 @@ static int do_show_link(int fd)
> >  				return -ENOMEM;
> >  			}
> >  			info.kprobe_multi.addrs = ptr_to_u64(addrs);
> > +			cookies = calloc(count, sizeof(__u64));
> > +			if (!cookies) {
> > +				p_err("mem alloc failed");
> > +				free(addrs);
> > +				close(fd);
> > +				return -ENOMEM;
> > +			}
> > +			info.kprobe_multi.cookies = ptr_to_u64(cookies);
> >  			goto again;
> >  		}
> >  	}
>
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index b66a1598b87c..fd862afe6c6f 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -249,18 +249,44 @@  static int get_prog_info(int prog_id, struct bpf_prog_info *info)
 	return err;
 }
 
-static int cmp_u64(const void *A, const void *B)
+struct addr_cookie {
+	__u64 addr;
+	__u64 cookie;
+};
+
+static int cmp_addr_cookie(const void *A, const void *B)
+{
+	const struct addr_cookie *a = A, *b = B;
+
+	if (a->addr == b->addr)
+		return 0;
+	return a->addr < b->addr ? -1 : 1;
+}
+
+static struct addr_cookie *
+get_addr_cookie_array(__u64 *addrs, __u64 *cookies, __u32 count)
 {
-	const __u64 *a = A, *b = B;
+	struct addr_cookie *data;
+	__u32 i;
 
-	return *a - *b;
+	data = calloc(count, sizeof(data[0]));
+	if (!data) {
+		p_err("mem alloc failed");
+		return NULL;
+	}
+	for (i = 0; i < count; i++) {
+		data[i].addr = addrs[i];
+		data[i].cookie = cookies[i];
+	}
+	qsort(data, count, sizeof(data[0]), cmp_addr_cookie);
+	return data;
 }
 
 static void
 show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 {
+	struct addr_cookie *data;
 	__u32 i, j = 0;
-	__u64 *addrs;
 
 	jsonw_bool_field(json_wtr, "retprobe",
 			 info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_RETURN);
@@ -268,14 +294,17 @@  show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 	jsonw_uint_field(json_wtr, "missed", info->kprobe_multi.missed);
 	jsonw_name(json_wtr, "funcs");
 	jsonw_start_array(json_wtr);
-	addrs = u64_to_ptr(info->kprobe_multi.addrs);
-	qsort(addrs, info->kprobe_multi.count, sizeof(addrs[0]), cmp_u64);
+	data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
+				     u64_to_ptr(info->kprobe_multi.cookies),
+				     info->kprobe_multi.count);
+	if (!data)
+		return;
 
 	/* Load it once for all. */
 	if (!dd.sym_count)
 		kernel_syms_load(&dd);
 	for (i = 0; i < dd.sym_count; i++) {
-		if (dd.sym_mapping[i].address != addrs[j])
+		if (dd.sym_mapping[i].address != data[j].addr)
 			continue;
 		jsonw_start_object(json_wtr);
 		jsonw_uint_field(json_wtr, "addr", dd.sym_mapping[i].address);
@@ -287,11 +316,13 @@  show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
 		} else {
 			jsonw_string_field(json_wtr, "module", dd.sym_mapping[i].module);
 		}
+		jsonw_uint_field(json_wtr, "cookie", data[j].cookie);
 		jsonw_end_object(json_wtr);
 		if (j++ == info->kprobe_multi.count)
 			break;
 	}
 	jsonw_end_array(json_wtr);
+	free(data);
 }
 
 static __u64 *u64_to_arr(__u64 val)
@@ -675,8 +706,8 @@  void netfilter_dump_plain(const struct bpf_link_info *info)
 
 static void show_kprobe_multi_plain(struct bpf_link_info *info)
 {
+	struct addr_cookie *data;
 	__u32 i, j = 0;
-	__u64 *addrs;
 
 	if (!info->kprobe_multi.count)
 		return;
@@ -688,8 +719,11 @@  static void show_kprobe_multi_plain(struct bpf_link_info *info)
 	printf("func_cnt %u  ", info->kprobe_multi.count);
 	if (info->kprobe_multi.missed)
 		printf("missed %llu  ", info->kprobe_multi.missed);
-	addrs = (__u64 *)u64_to_ptr(info->kprobe_multi.addrs);
-	qsort(addrs, info->kprobe_multi.count, sizeof(__u64), cmp_u64);
+	data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
+				     u64_to_ptr(info->kprobe_multi.cookies),
+				     info->kprobe_multi.count);
+	if (!data)
+		return;
 
 	/* Load it once for all. */
 	if (!dd.sym_count)
@@ -697,12 +731,12 @@  static void show_kprobe_multi_plain(struct bpf_link_info *info)
 	if (!dd.sym_count)
 		return;
 
-	printf("\n\t%-16s %s", "addr", "func [module]");
+	printf("\n\t%-16s %-16s %s", "addr", "cookie", "func [module]");
 	for (i = 0; i < dd.sym_count; i++) {
-		if (dd.sym_mapping[i].address != addrs[j])
+		if (dd.sym_mapping[i].address != data[j].addr)
 			continue;
-		printf("\n\t%016lx %s",
-		       dd.sym_mapping[i].address, dd.sym_mapping[i].name);
+		printf("\n\t%016lx %-16llx %s",
+		       dd.sym_mapping[i].address, data[j].cookie, dd.sym_mapping[i].name);
 		if (dd.sym_mapping[i].module[0] != '\0')
 			printf(" [%s]  ", dd.sym_mapping[i].module);
 		else
@@ -711,6 +745,7 @@  static void show_kprobe_multi_plain(struct bpf_link_info *info)
 		if (j++ == info->kprobe_multi.count)
 			break;
 	}
+	free(data);
 }
 
 static void show_uprobe_multi_plain(struct bpf_link_info *info)
@@ -966,6 +1001,14 @@  static int do_show_link(int fd)
 				return -ENOMEM;
 			}
 			info.kprobe_multi.addrs = ptr_to_u64(addrs);
+			cookies = calloc(count, sizeof(__u64));
+			if (!cookies) {
+				p_err("mem alloc failed");
+				free(addrs);
+				close(fd);
+				return -ENOMEM;
+			}
+			info.kprobe_multi.cookies = ptr_to_u64(cookies);
 			goto again;
 		}
 	}