bpf: Retrieve ref_ctr_offset from uprobe perf link
Subsystems (6)
Jiri Olsa
reviewerv2 cover bpf: Retrieve ref_ctr_offset from uprobe perf link
hi,
adding ref_ctr_offset retrieval for uprobe perf link info.
v2 changes:
- display ref_ctr_offset as hex number [Andrii]
- added acks
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 v2 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
Jiri Olsa
reviewerPATCH v2 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
Jiri Olsa
reviewerPATCH v2 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 0x303a3fa
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 0x%llx " , 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
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 8 lines · On Fri, 9 May 2025 17:35:36 +0200 you wrote:
hi,
addingref_ctr_offsetretrieval for uprobe perf link info.v2 changes:
- displayref_ctr_offsetas hex number [Andrii]
- added acks[...]
Here is the summary with links:
- [PATCHv2,bpf-next,1/3] bpf: Add support to retrieve ref_ctr_offset for uprobe perf link
https://git.kernel.org/bpf/bpf-next/c/823153334042 - [PATCHv2,bpf-next,2/3] selftests/bpf: Add link info test for ref_ctr_offset retrieval https://git.kernel.org/bpf/bpf-next/c/d57293db64f5 - [PATCHv2,bpf-next,3/3] bpftool: Display ref_ctr_offset for uprobe link info https://git.kernel.org/bpf/bpf-next/c/97596edfec01
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html