bpf: Retrieve ref_ctr_offset from uprobe perf link
Subsystems (6)
Jiri Olsa
reviewercover bpf: Retrieve ref_ctr_offset from uprobe perf link
hi,
adding ref_ctr_offset retrieval for uprobe perf link info.
thanks,
jirka
---
Jiri Olsa (3):
bpf: Add support to retrieve ref_ctr_offset for uprobe perf link selftests/bpf: Add link info test for ref_ctr_offset retrieval
bpftool: Display ref_ctr_offset for uprobe link info
include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 5 +++-- kernel/trace/trace_uprobe.c | 2 +- tools/bpf/bpftool/link.c | 3 +++ tools/include/uapi/linux/bpf.h | 1 + tools/testing/selftests/bpf/prog_tests/fill_link_info.c | 18 ++++++++++++++++-- 6 files changed, 25 insertions(+), 5 deletions(-)
Jiri Olsa
reviewerPATCH 1/3 bpf: Add support to retrieve ref_ctr_offset for uprobe perf link
Adding support to retrieve ref_ctr_offset for uprobe perf link, which got somehow omitted from the initial uprobe link info changes.
--- include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 5 +++-- kernel/trace/trace_uprobe.c | 2 +- tools/include/uapi/linux/bpf.h | 1 + 4 files changed, 6 insertions(+), 3 deletions(-)
include/uapi/linux/bpf.h +1 -0
@@ -6724,6 +6724,7 @@ struct bpf_link_info {__u32 name_len;__u32 offset;/* offset from file_name */ __u64 cookie; +__u64 ref_ctr_offset; } uprobe;/* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */ struct {__aligned_u64 func_name;/* in/out */
kernel/bpf/syscall.c +3 -2
@@ -3800,14 +3800,14 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,static int bpf_perf_link_fill_uprobe (const struct perf_event *event,struct bpf_link_info *info) { +u64 ref_ctr_offset, offset;char __user *uname; -u64 addr, offset;u32 ulen, type;int err; uname =u64_to_user_ptr (info->perf_event.uprobe.file_name); ulen = info->perf_event.uprobe.name_len; - err =bpf_perf_link_fill_common (event, uname, &ulen, &offset, &addr, + err =bpf_perf_link_fill_common (event, uname, &ulen, &offset, &ref_ctr_offset, &type,NULL );if (err)return err;
@@ -3819,6 +3819,7 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event, info->perf_event.uprobe.name_len = ulen; info->perf_event.uprobe.offset = offset; info->perf_event.uprobe.cookie = event->bpf_cookie; + info->perf_event.uprobe.ref_ctr_offset = ref_ctr_offset; return 0; }#endif
kernel/trace/trace_uprobe.c +1 -1
@@ -1489,7 +1489,7 @@ int bpf_get_uprobe_info(const struct perf_event *event, u32 *fd_type, : BPF_FD_TYPE_UPROBE; *filename = tu->filename; *probe_offset = tu->offset; - *probe_addr =0 ; + *probe_addr = tu->ref_ctr_offset; return 0; }#endif /* CONFIG_PERF_EVENTS */
tools/include/uapi/linux/bpf.h +1 -0
@@ -6724,6 +6724,7 @@ struct bpf_link_info {__u32 name_len;__u32 offset;/* offset from file_name */ __u64 cookie; +__u64 ref_ctr_offset; } uprobe;/* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */ struct {__aligned_u64 func_name;/* in/out */
Signature · 1 line
2.49.0
Re: [PATCH bpf-next 1/3] bpf: Add support to retrieve ref_ctr_offset for uprobe perf link
Quoted 5 lines · Jiri Olsa
Adding support to retrieve
ref_ctr_offsetfor uprobe perf link, which got somehow omitted from the initial uprobe link info changes.Signed-off-by Jiri Olsa <[email protected]>
LGTM
Quoted 76 lines
--- include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 5 +++-- kernel/trace/trace_uprobe.c | 2 +- tools/include/uapi/linux/bpf.h | 1 + 4 files changed, 6 insertions(+), 3 deletions(-)include/uapi/linux/bpf.h +1
-0@@ -6724,6 +6724,7 @@ struct bpf_link_info {__u32 name_len;__u32 offset;/* offset from file_name */ __u64 cookie; +__u64 ref_ctr_offset; } uprobe;/* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */ struct {__aligned_u64 func_name;/* in/out */ kernel/bpf/syscall.c +3
-2@@ -3800,14 +3800,14 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,static int bpf_perf_link_fill_uprobe (const struct perf_event *event,struct bpf_link_info *info) { +u64 ref_ctr_offset, offset;char __user *uname; -u64 addr, offset;u32 ulen, type;int err; uname =u64_to_user_ptr (info->perf_event.uprobe.file_name); ulen = info->perf_event.uprobe.name_len; - err =bpf_perf_link_fill_common (event, uname, &ulen, &offset, &addr, + err =bpf_perf_link_fill_common (event, uname, &ulen, &offset, &ref_ctr_offset, &type,NULL );if (err)return err;@@ -3819,6 +3819,7 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event, info->perf_event.uprobe.name_len = ulen; info->perf_event.uprobe.offset = offset; info->perf_event.uprobe.cookie = event->bpf_cookie; + info->perf_event.uprobe.ref_ctr_offset = ref_ctr_offset; return 0; }#endif kernel/trace/trace_uprobe.c +1
-1@@ -1489,7 +1489,7 @@ int bpf_get_uprobe_info(const struct perf_event *event, u32 *fd_type, : BPF_FD_TYPE_UPROBE; *filename = tu->filename; *probe_offset = tu->offset; - *probe_addr =0 ; + *probe_addr = tu->ref_ctr_offset; return 0; }#endif /* CONFIG_PERF_EVENTS */ tools/include/uapi/linux/bpf.h +1
-1@@ -6724,6 +6724,7 @@ struct bpf_link_info {__u32 name_len;__u32 offset;/* offset from file_name */ __u64 cookie; +__u64 ref_ctr_offset; } uprobe;/* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */ struct {__aligned_u64 func_name;/* in/out */ --2.49.0
Signature · 2 lines
Regards Yafang
Jiri Olsa
reviewerPATCH 2/3 selftests/bpf: Add link info test for ref_ctr_offset retrieval
In reply to Jiri OlsaAdding link info test for ref_ctr_offset retrieval for both uprobe and uretprobe probes.
--- .../selftests/bpf/prog_tests/fill_link_info.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/fill_link_info.c +16 -2
@@ -37,6 +37,7 @@ static noinline void uprobe_func(void)static int verify_perf_link_info (int fd,enum bpf_perf_event_type type,long addr,ssize_t offset,ssize_t entry_offset) { +ssize_t ref_ctr_offset = entry_offset/* ref_ctr_offset for uprobes */ ;struct bpf_link_info info;__u32 len =sizeof (info);char buf[PATH_MAX ];
@@ -97,6 +98,7 @@ static int verify_perf_link_info(int fd, enum bpf_perf_event_type type, long addcase BPF_PERF_EVENT_UPROBE :case BPF_PERF_EVENT_URETPROBE :ASSERT_EQ (info.perf_event.uprobe.offset, offset,"uprobe_offset" ); +ASSERT_EQ (info.perf_event.uprobe.ref_ctr_offset, ref_ctr_offset,"uprobe_ref_ctr_offset" );ASSERT_EQ (info.perf_event.uprobe.name_len,strlen (UPROBE_FILE ) +1 ,"name_len" );
@@ -241,20 +243,32 @@ static void test_uprobe_fill_link_info(struct test_fill_link_info *skel, .retprobe = type == BPF_PERF_EVENT_URETPROBE, .bpf_cookie = PERF_EVENT_COOKIE, ); +const char *sema[1 ] = { +"uprobe_link_info_sema_1" , + }; +__u64 *ref_ctr_offset;struct bpf_link *link;int link_fd, err; + err =elf_resolve_syms_offsets ("/proc/self/exe" ,1 , sema, + (unsigned long **) &ref_ctr_offset,STT_OBJECT ); +if (!ASSERT_OK (err,"elf_resolve_syms_offsets_object" )) +return ; + + opts.ref_ctr_offset = *ref_ctr_offset; link =bpf_program__attach_uprobe_opts (skel->progs.uprobe_run,0 ,/* self pid */ UPROBE_FILE , uprobe_offset, &opts);if (!ASSERT_OK_PTR (link,"attach_uprobe" )) -return ; + goto out; link_fd =bpf_link__fd (link); - err =verify_perf_link_info (link_fd, type,0 , uprobe_offset,0 ); + err =verify_perf_link_info (link_fd, type,0 , uprobe_offset, *ref_ctr_offset);ASSERT_OK (err,"verify_perf_link_info" );bpf_link__destroy (link); +out: +free (ref_ctr_offset); }static int verify_kmulti_link_info (int fd,bool retprobe,bool has_cookies)
Signature · 1 line
2.49.0
Re: [PATCH bpf-next 2/3] selftests/bpf: Add link info test for ref_ctr_offset retrieval
Quoted 5 lines · Jiri Olsa
Adding link info test for
ref_ctr_offsetretrieval for both uprobe and uretprobe probes.Signed-off-by Jiri Olsa <[email protected]>
LGTM
Quoted 62 lines
--- .../selftests/bpf/prog_tests/fill_link_info.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/prog_tests/fill_link_info.c +16
-3@@ -37,6 +37,7 @@ static noinline void uprobe_func(void)static int verify_perf_link_info (int fd,enum bpf_perf_event_type type,long addr,ssize_t offset,ssize_t entry_offset) { +ssize_t ref_ctr_offset = entry_offset/* ref_ctr_offset for uprobes */ ;struct bpf_link_info info;__u32 len =sizeof (info);char buf[PATH_MAX ];@@ -97,6 +98,7 @@ static int verify_perf_link_info(int fd, enum bpf_perf_event_type type, long addcase BPF_PERF_EVENT_UPROBE :case BPF_PERF_EVENT_URETPROBE :ASSERT_EQ (info.perf_event.uprobe.offset, offset,"uprobe_offset" ); +ASSERT_EQ (info.perf_event.uprobe.ref_ctr_offset, ref_ctr_offset,"uprobe_ref_ctr_offset" );ASSERT_EQ (info.perf_event.uprobe.name_len,strlen (UPROBE_FILE ) +1 ,"name_len" );@@ -241,20 +243,32 @@ static void test_uprobe_fill_link_info(struct test_fill_link_info *skel, .retprobe = type == BPF_PERF_EVENT_URETPROBE, .bpf_cookie = PERF_EVENT_COOKIE, ); +const char *sema[1 ] = { +"uprobe_link_info_sema_1" , + }; +__u64 *ref_ctr_offset;struct bpf_link *link;int link_fd, err; + err =elf_resolve_syms_offsets ("/proc/self/exe" ,1 , sema, + (unsigned long **) &ref_ctr_offset,STT_OBJECT ); +if (!ASSERT_OK (err,"elf_resolve_syms_offsets_object" )) +return ; + + opts.ref_ctr_offset = *ref_ctr_offset; link =bpf_program__attach_uprobe_opts (skel->progs.uprobe_run,0 ,/* self pid */ UPROBE_FILE , uprobe_offset, &opts);if (!ASSERT_OK_PTR (link,"attach_uprobe" )) -return ; + goto out; link_fd =bpf_link__fd (link); - err =verify_perf_link_info (link_fd, type,0 , uprobe_offset,0 ); + err =verify_perf_link_info (link_fd, type,0 , uprobe_offset, *ref_ctr_offset);ASSERT_OK (err,"verify_perf_link_info" );bpf_link__destroy (link); +out: +free (ref_ctr_offset); }static int verify_kmulti_link_info (int fd,bool retprobe,bool has_cookies) --2.49.0
Signature · 2 lines
Regards Yafang
Jiri Olsa
reviewerPATCH 3/3 bpftool: Display ref_ctr_offset for uprobe link info
In reply to Jiri OlsaAdding support to display ref_ctr_offset in link output, like:
# bpftool link
...
42: perf_event prog 174
uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538
bpf_cookie 3735928559
pids test_progs(1820) # bpftool link -j | jq
[
...
{
"id": 42,
...
"ref_ctr_offset": 50500538,
}
]--- tools/bpf/bpftool/link.c | 3 +++ 1 file changed, 3 insertions(+)
tools/bpf/bpftool/link.c +3 -0
@@ -380,6 +380,7 @@ show_perf_event_uprobe_json(struct bpf_link_info *info, json_writer_t *wtr) u64_to_ptr(info->perf_event.uprobe.file_name));jsonw_uint_field (wtr,"offset" , info->perf_event.uprobe.offset);jsonw_uint_field (wtr,"cookie" , info->perf_event.uprobe.cookie); +jsonw_uint_field (wtr,"ref_ctr_offset" , info->perf_event.uprobe.ref_ctr_offset); } static void
@@ -823,6 +824,8 @@ static void show_perf_event_uprobe_plain(struct bpf_link_info *info)printf ("%s+%#x " , buf, info->perf_event.uprobe.offset);if (info->perf_event.uprobe.cookie)printf ("cookie %llu " , info->perf_event.uprobe.cookie); +if (info->perf_event.uprobe.ref_ctr_offset) +printf ("ref_ctr_offset %llu " , info->perf_event.uprobe.ref_ctr_offset); }static void show_perf_event_tracepoint_plain (struct bpf_link_info *info)
Signature · 1 line
2.49.0
Re: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
Quoted 19 lines · Jiri Olsa
Adding support to display
ref_ctr_offsetin link output, like:# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538 bpf_cookie 3735928559 pids test_progs(1820)# bpftool link -j | jq [ ... { "id": 42, ... "ref_ctr_offset": 50500538, } ]
Quoted 1 line
Signed-off-by Jiri Olsa <[email protected]>
Thanks Jiri!
Re: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
In reply to Jiri OlsaQuoted 7 lines · Jiri Olsa
Adding support to display
ref_ctr_offsetin link output, like:# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538
let's use hex for ref_ctr_offset?
and also, why do we have bpf_cookie and cookie emitted? Are they different?
Quoted 42 lines
bpf_cookie 3735928559 pids test_progs(1820)# bpftool link -j | jq [ ... { "id": 42, ... "ref_ctr_offset": 50500538, } ]Signed-off-by Jiri Olsa <[email protected]>--- tools/bpf/bpftool/link.c | 3 +++ 1 file changed, 3 insertions(+)tools/bpf/bpftool/link.c +3
-1@@ -380,6 +380,7 @@ show_perf_event_uprobe_json(struct bpf_link_info *info, json_writer_t *wtr) u64_to_ptr(info->perf_event.uprobe.file_name));jsonw_uint_field (wtr,"offset" , info->perf_event.uprobe.offset);jsonw_uint_field (wtr,"cookie" , info->perf_event.uprobe.cookie); +jsonw_uint_field (wtr,"ref_ctr_offset" , info->perf_event.uprobe.ref_ctr_offset); } static void@@ -823,6 +824,8 @@ static void show_perf_event_uprobe_plain(struct bpf_link_info *info)printf ("%s+%#x " , buf, info->perf_event.uprobe.offset);if (info->perf_event.uprobe.cookie)printf ("cookie %llu " , info->perf_event.uprobe.cookie); +if (info->perf_event.uprobe.ref_ctr_offset) +printf ("ref_ctr_offset %llu " , info->perf_event.uprobe.ref_ctr_offset); }static void show_perf_event_tracepoint_plain (struct bpf_link_info *info) --2.49.0
Re: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
Quoted 10 lines · Andrii Nakryiko
Quoted 7 lines · Jiri Olsa
Adding support to display
ref_ctr_offsetin link output, like:# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538let's use hex for
ref_ctr_offset?
I had that, then I saw cookie was dec ;-) either way is fine for me
Quoted 2 lines
and also, why do we have
bpf_cookieand cookie emitted? Are they different?
hum, right.. so there's bpf_cookie retrieval from perf_link through the task_file iterator:
cbdaf71f7e65 bpftool: Add bpf_cookie to link output
I guess it was added before we decided to have bpf_link_info.perf_event interface, which seems easier to me
jirka
Quoted 43 lines
Quoted 43 lines
bpf_cookie 3735928559 pids test_progs(1820)# bpftool link -j | jq [ ... { "id": 42, ... "ref_ctr_offset": 50500538, } ]Signed-off-by Jiri Olsa <[email protected]>--- tools/bpf/bpftool/link.c | 3 +++ 1 file changed, 3 insertions(+)tools/bpf/bpftool/link.c +3
-1@@ -380,6 +380,7 @@ show_perf_event_uprobe_json(struct bpf_link_info *info, json_writer_t *wtr) u64_to_ptr(info->perf_event.uprobe.file_name));jsonw_uint_field (wtr,"offset" , info->perf_event.uprobe.offset);jsonw_uint_field (wtr,"cookie" , info->perf_event.uprobe.cookie); +jsonw_uint_field (wtr,"ref_ctr_offset" , info->perf_event.uprobe.ref_ctr_offset); } static void@@ -823,6 +824,8 @@ static void show_perf_event_uprobe_plain(struct bpf_link_info *info)printf ("%s+%#x " , buf, info->perf_event.uprobe.offset);if (info->perf_event.uprobe.cookie)printf ("cookie %llu " , info->perf_event.uprobe.cookie); +if (info->perf_event.uprobe.ref_ctr_offset) +printf ("ref_ctr_offset %llu " , info->perf_event.uprobe.ref_ctr_offset); }static void show_perf_event_tracepoint_plain (struct bpf_link_info *info) --2.49.0
Quentin Monnet
maintainerRe: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
2025-05-07 10:56 UTC+0200 ~ Jiri Olsa <[email protected]>
Quoted 5 lines · Andrii Nakryiko
Quoted 4 lines · Jiri Olsa
Quoted 3 lines
Adding support to display
ref_ctr_offsetin link output, like:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538let's use hex for
ref_ctr_offset?I had that, then I saw cookie was dec ;-) either way is fine for me
I'm fine either way, but let's use the same base for the two values please. If you want to change the cookie to hexa (in the plain output) for better readability, that's OK as well (JSON output needs to remain a decimal in both cases, of course).
Quentin
Re: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
Quoted 12 lines · Quentin Monnet
2025-05-07 10:56 UTC+0200 ~ Jiri Olsa <[email protected]>
Quoted 10 lines · Andrii Nakryiko
Quoted 9 lines · Jiri Olsa
Quoted 7 lines
Adding support to display
ref_ctr_offsetin link output, like:# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
let's use hex for
ref_ctr_offset?I had that, then I saw cookie was dec ;-) either way is fine for me
I'm fine either way, but let's use the same base for the two values please. If you want to change the cookie to hexa (in the plain output) for better readability, that's OK as well (JSON output needs to remain a decimal in both cases, of course).
Why should cookie and offset use the same base? Offset is always address-like, so hex makes most sense there, 100%. But a cookie is most probably going to be some small value (index into array, or small number representing attachment point number, etc), so decimal is most natural. Importantly, BPF cookie can't really be a pointer (what will you do with it on BPF side?), so it's something a bit more human-driven, and thus decimal seems like a better default.
Quoted 2 lines
Quentin
Quentin Monnet
maintainerRe: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
2025-05-07 11:18 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 22 lines · Quentin Monnet
Quoted 12 lines
2025-05-07 10:56 UTC+0200 ~ Jiri Olsa <[email protected]>
Quoted 10 lines · Andrii Nakryiko
Quoted 9 lines · Jiri Olsa
Quoted 7 lines
Adding support to display
ref_ctr_offsetin link output, like:# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538Quoted 8 lines
Quoted 3 lines
Quoted 1 line
let's use hex for
ref_ctr_offset?I had that, then I saw cookie was dec ;-) either way is fine for me
I'm fine either way, but let's use the same base for the two values please. If you want to change the cookie to hexa (in the plain output) for better readability, that's OK as well (JSON output needs to remain a decimal in both cases, of course).
Quoted 7 lines
Why should cookie and offset use the same base? Offset is always address-like, so hex makes most sense there, 100%. But a cookie is most probably going to be some small value (index into array, or small number representing attachment point number, etc), so decimal is most natural. Importantly, BPF cookie can't really be a pointer (what will you do with it on BPF side?), so it's something a bit more human-driven, and thus decimal seems like a better default.
OK my bad, I take it back, then :)
Quentin
Re: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
In reply to Jiri OlsaQuoted 17 lines · Jiri Olsa
Quoted 10 lines · Andrii Nakryiko
Quoted 7 lines · Jiri Olsa
Adding support to display
ref_ctr_offsetin link output, like:# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538let's use hex for
ref_ctr_offset?I had that, then I saw cookie was dec ;-) either way is fine for me
Quoted 2 lines
and also, why do we have
bpf_cookieand cookie emitted? Are they different?
Quoted 7 lines
hum, right.. so there's
bpf_cookieretrieval fromperf_linkthrough thetask_fileiterator:
cbdaf71f7e65bpftool: Addbpf_cookieto link outputI guess it was added before we decided to have bpf_link_info.perf_event interface, which seems easier to me
we could drop the bpf_cookie with attached patch, but should we worry about loosing 'bpf_cookie' tag from json output (there will be just 'cookie' tag now with the same value)
jirka
---
tools/bpf/bpftool/main.h +0 -2
@@ -104,9 +104,7 @@ struct obj_ref {struct obj_refs {int ref_cnt; -bool has_bpf_cookie;struct obj_ref *refs; -__u64 bpf_cookie; };struct btf ;
tools/bpf/bpftool/pids.c +0 -8
@@ -80,8 +80,6 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e)memcpy (ref->comm, e->comm,sizeof (ref->comm)); ref->comm[sizeof (ref->comm) -1 ] ='\0' ; refs->ref_cnt =1 ; - refs->has_bpf_cookie = e->has_bpf_cookie; - refs->bpf_cookie = e->bpf_cookie; err =hashmap__append (map, e->id, refs);if (err)
@@ -214,9 +212,6 @@ void emit_obj_refs_json(struct hashmap *map, __u32 id,if (refs->ref_cnt ==0 )break ; -if (refs->has_bpf_cookie) -jsonw_lluint_field (json_writer,"bpf_cookie" , refs->bpf_cookie); -jsonw_name (json_writer,"pids" );jsonw_start_array (json_writer);for (i =0 ; i < refs->ref_cnt; i++) {
@@ -246,9 +241,6 @@ void emit_obj_refs_plain(struct hashmap *map, __u32 id, const char *prefix)if (refs->ref_cnt ==0 )break ; -if (refs->has_bpf_cookie) -printf ("\n\tbpf_cookie %llu" , (unsigned long long ) refs->bpf_cookie); -printf ("%s" , prefix);for (i =0 ; i < refs->ref_cnt; i++) {struct obj_ref *ref = &refs->refs[i];
tools/bpf/bpftool/skeleton/pid_iter.bpf.c +0 -36
@@ -15,19 +15,6 @@ enum bpf_obj_type { BPF_OBJ_BTF, }; -struct bpf_perf_link___local { -struct bpf_link link; -struct file *perf_file; -} __attribute__((preserve_access_index)); - -struct perf_event___local { -u64 bpf_cookie; -} __attribute__((preserve_access_index)); - -enum bpf_link_type___local { - BPF_LINK_TYPE_PERF_EVENT___local =7 , -}; - extern const void bpf_link_fops __ksym; extern const void bpf_link_fops_poll __ksym __weak; extern const void bpf_map_fops __ksym;
@@ -52,17 +39,6 @@ static __always_inline __u32 get_obj_id(void *ent, enum bpf_obj_type type) } } -/* could be used only with BPF_LINK_TYPE_PERF_EVENT links */ -static __u64 get_bpf_cookie (struct bpf_link *link) -{ -struct bpf_perf_link___local *perf_link; -struct perf_event___local *event; - - perf_link = container_of(link, struct bpf_perf_link___local, link); - event =BPF_CORE_READ (perf_link, perf_file, private_data); -return BPF_CORE_READ (event, bpf_cookie); -} - SEC("iter/task_file")int iter (struct bpf_iter__task_file *ctx) {
@@ -102,18 +78,6 @@ int iter(struct bpf_iter__task_file *ctx) e.pid = task->tgid; e.id =get_obj_id (file->private_data, obj_type); -if (obj_type ==BPF_OBJ_LINK && - bpf_core_enum_value_exists(enum bpf_link_type___local, - BPF_LINK_TYPE_PERF_EVENT___local)) { -struct bpf_link *link = (struct bpf_link *) file->private_data; - - if (BPF_CORE_READ(link, type) == bpf_core_enum_value(enum bpf_link_type___local, - BPF_LINK_TYPE_PERF_EVENT___local)) { - e.has_bpf_cookie = true; - e.bpf_cookie =get_bpf_cookie (link); - } - } -bpf_probe_read_kernel_str (&e.comm,sizeof (e.comm), task->group_leader->comm);bpf_seq_write (ctx->meta->seq, &e,sizeof (e));
tools/bpf/bpftool/skeleton/pid_iter.h +0 -2
@@ -6,8 +6,6 @@struct pid_iter_entry {__u32 id;int pid; -__u64 bpf_cookie; -bool has_bpf_cookie;char comm[16 ]; };
Re: [PATCH bpf-next 3/3] bpftool: Display ref_ctr_offset for uprobe link info
Quoted 22 lines · Jiri Olsa
Quoted 20 lines · Jiri Olsa
Quoted 10 lines · Andrii Nakryiko
Quoted 7 lines · Jiri Olsa
Adding support to display
ref_ctr_offsetin link output, like:# bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 50500538let's use hex for
ref_ctr_offset?I had that, then I saw cookie was dec ;-) either way is fine for me
Quoted 2 lines
and also, why do we have
bpf_cookieand cookie emitted? Are they different?hum, right.. so there's
bpf_cookieretrieval fromperf_linkthrough thetask_fileiterator:
Quoted 9 lines
Quoted 4 lines
cbdaf71f7e65bpftool: Addbpf_cookieto link outputI guess it was added before we decided to have bpf_link_info.perf_event interface, which seems easier to me
we could drop the
bpf_cookiewith attached patch, but should we worry about loosing 'bpf_cookie' tag from json output (there will be just 'cookie' tag now with the same value)
I don't have strong feelings about this, but note that bpf_cookie is available on more kernel versions than the more recently added uprobe-specific cookie. If it's not too cumbersome, maybe we can just not display bpf_cookie *if* kernel provides uprobe-specific cookie information? Not sure, don't really care all that much, just noticed duplication earlier and thought to point this out.
Quoted 125 lines
jirka
---
tools/bpf/bpftool/main.h +0
-2@@ -104,9 +104,7 @@ struct obj_ref {struct obj_refs {int ref_cnt; -bool has_bpf_cookie;struct obj_ref *refs; -__u64 bpf_cookie; };struct btf ;tools/bpf/bpftool/pids.c +0
-8@@ -80,8 +80,6 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e)memcpy (ref->comm, e->comm,sizeof (ref->comm)); ref->comm[sizeof (ref->comm) -1 ] ='\0' ; refs->ref_cnt =1 ; - refs->has_bpf_cookie = e->has_bpf_cookie; - refs->bpf_cookie = e->bpf_cookie; err =hashmap__append (map, e->id, refs);if (err)@@ -214,9 +212,6 @@ void emit_obj_refs_json(struct hashmap *map, __u32 id,if (refs->ref_cnt ==0 )break ; -if (refs->has_bpf_cookie) -jsonw_lluint_field (json_writer,"bpf_cookie" , refs->bpf_cookie); -jsonw_name (json_writer,"pids" );jsonw_start_array (json_writer);for (i =0 ; i < refs->ref_cnt; i++) {@@ -246,9 +241,6 @@ void emit_obj_refs_plain(struct hashmap *map, __u32 id, const char *prefix)if (refs->ref_cnt ==0 )break ; -if (refs->has_bpf_cookie) -printf ("\n\tbpf_cookie %llu" , (unsigned long long ) refs->bpf_cookie); -printf ("%s" , prefix);for (i =0 ; i < refs->ref_cnt; i++) {struct obj_ref *ref = &refs->refs[i];tools/bpf/bpftool/skeleton/pid_iter.bpf.c +0
-36@@ -15,19 +15,6 @@ enum bpf_obj_type { BPF_OBJ_BTF, }; -struct bpf_perf_link___local { -struct bpf_link link; -struct file *perf_file; -} __attribute__((preserve_access_index)); - -struct perf_event___local { -u64 bpf_cookie; -} __attribute__((preserve_access_index)); - -enum bpf_link_type___local { - BPF_LINK_TYPE_PERF_EVENT___local =7 , -}; - extern const void bpf_link_fops __ksym; extern const void bpf_link_fops_poll __ksym __weak; extern const void bpf_map_fops __ksym;@@ -52,17 +39,6 @@ static __always_inline __u32 get_obj_id(void *ent, enum bpf_obj_type type) } } -/* could be used only with BPF_LINK_TYPE_PERF_EVENT links */ -static __u64 get_bpf_cookie (struct bpf_link *link) -{ -struct bpf_perf_link___local *perf_link; -struct perf_event___local *event; - - perf_link = container_of(link, struct bpf_perf_link___local, link); - event =BPF_CORE_READ (perf_link, perf_file, private_data); -return BPF_CORE_READ (event, bpf_cookie); -} - SEC("iter/task_file")int iter (struct bpf_iter__task_file *ctx) {@@ -102,18 +78,6 @@ int iter(struct bpf_iter__task_file *ctx) e.pid = task->tgid; e.id =get_obj_id (file->private_data, obj_type); -if (obj_type ==BPF_OBJ_LINK && - bpf_core_enum_value_exists(enum bpf_link_type___local, - BPF_LINK_TYPE_PERF_EVENT___local)) { -struct bpf_link *link = (struct bpf_link *) file->private_data; - - if (BPF_CORE_READ(link, type) == bpf_core_enum_value(enum bpf_link_type___local, - BPF_LINK_TYPE_PERF_EVENT___local)) { - e.has_bpf_cookie = true; - e.bpf_cookie =get_bpf_cookie (link); - } - } -bpf_probe_read_kernel_str (&e.comm,sizeof (e.comm), task->group_leader->comm);bpf_seq_write (ctx->meta->seq, &e,sizeof (e));tools/bpf/bpftool/skeleton/pid_iter.h +0
-2@@ -6,8 +6,6 @@struct pid_iter_entry {__u32 id;int pid; -__u64 bpf_cookie; -bool has_bpf_cookie;char comm[16 ]; };