bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Add show_fdinfo for perf_event
@ 2025-06-04 16:37 Tao Chen
  2025-06-05 18:41 ` Andrii Nakryiko
  2025-06-05 21:53 ` Jiri Olsa
  0 siblings, 2 replies; 5+ messages in thread
From: Tao Chen @ 2025-06-04 16:37 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, Tao Chen

After commit 1b715e1b0ec5 ("bpf: Support ->fill_link_info for perf_event") add
perf_event info, we can also show the info with the method of cat /proc/[fd]/fdinfo.

kprobe fdinfo:
link_type:	perf
link_id:	2
prog_tag:	bcf7977d3b93787c
prog_id:	18
name:	bpf_fentry_test1
offset:	0
missed:	0
addr:	ffffffffaea8d134
event_type:	3
cookie:	3735928559

uprobe fdinfo:
link_type:	perf
link_id:	6
prog_tag:	bcf7977d3b93787c
prog_id:	7
name:	/proc/self/exe
offset:	6507541
event_type:	1
cookie:	3735928559

tracepoint fdinfo:
link_type:	perf
link_id:	4
prog_tag:	bcf7977d3b93787c
prog_id:	8
tp_name:	sched_switch
event_type:	5
cookie:	3735928559

perf_event fdinfo:
link_type:	perf
link_id:	5
prog_tag:	bcf7977d3b93787c
prog_id:	9
type:	1
config:	2
event_type:	6
cookie:	3735928559

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
 kernel/bpf/syscall.c | 126 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 9794446bc8..9af54852eb 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3793,6 +3793,35 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,
 	info->perf_event.kprobe.cookie = event->bpf_cookie;
 	return 0;
 }
+
+static void bpf_perf_link_fdinfo_kprobe(const struct perf_event *event,
+					struct seq_file *seq)
+{
+	const char *name;
+	int err;
+	u32 prog_id, type;
+	u64 offset, addr;
+	unsigned long missed;
+
+	err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
+				      &offset, &addr, &missed);
+	if (err)
+		return;
+
+	if (type == BPF_FD_TYPE_KRETPROBE)
+		type = BPF_PERF_EVENT_KRETPROBE;
+	else
+		type = BPF_PERF_EVENT_KPROBE;
+
+	seq_printf(seq,
+		   "name:\t%s\n"
+		   "offset:\t%llu\n"
+		   "missed:\t%lu\n"
+		   "addr:\t%llx\n"
+		   "event_type:\t%u\n"
+		   "cookie:\t%llu\n",
+		   name, offset, missed, addr, type, event->bpf_cookie);
+}
 #endif
 
 #ifdef CONFIG_UPROBE_EVENTS
@@ -3820,6 +3849,34 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event,
 	info->perf_event.uprobe.cookie = event->bpf_cookie;
 	return 0;
 }
+
+static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event,
+					struct seq_file *seq)
+{
+	const char *name;
+	int err;
+	u32 prog_id, type;
+	u64 offset, addr;
+	unsigned long missed;
+
+	err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
+				      &offset, &addr, &missed);
+	if (err)
+		return;
+
+	if (type == BPF_FD_TYPE_URETPROBE)
+		type = BPF_PERF_EVENT_URETPROBE;
+	else
+		type = BPF_PERF_EVENT_UPROBE;
+
+	seq_printf(seq,
+		   "name:\t%s\n"
+		   "offset:\t%llu\n"
+		   "event_type:\t%u\n"
+		   "cookie:\t%llu\n",
+		   name, offset, type, event->bpf_cookie);
+
+}
 #endif
 
 static int bpf_perf_link_fill_probe(const struct perf_event *event,
@@ -3888,10 +3945,79 @@ static int bpf_perf_link_fill_link_info(const struct bpf_link *link,
 	}
 }
 
+static void bpf_perf_event_link_show_fdinfo(const struct perf_event *event,
+					    struct seq_file *seq)
+{
+	seq_printf(seq,
+		   "type:\t%u\n"
+		   "config:\t%llu\n"
+		   "event_type:\t%u\n"
+		   "cookie:\t%llu\n",
+		   event->attr.type, event->attr.config,
+		   BPF_PERF_EVENT_EVENT, event->bpf_cookie);
+}
+
+static void bpf_tracepoint_link_show_fdinfo(const struct perf_event *event,
+					    struct seq_file *seq)
+{
+	int err;
+	const char *name;
+	u32 prog_id;
+
+	err = bpf_get_perf_event_info(event, &prog_id, NULL, &name, NULL,
+				      NULL, NULL);
+	if (err)
+		return;
+
+	seq_printf(seq,
+		   "tp_name:\t%s\n"
+		   "event_type:\t%u\n"
+		   "cookie:\t%llu\n",
+		   name, BPF_PERF_EVENT_TRACEPOINT, event->bpf_cookie);
+}
+
+static void bpf_probe_link_show_fdinfo(const struct perf_event *event,
+				       struct seq_file *seq)
+{
+#ifdef CONFIG_KPROBE_EVENTS
+	if (event->tp_event->flags & TRACE_EVENT_FL_KPROBE)
+		return bpf_perf_link_fdinfo_kprobe(event, seq);
+#endif
+
+#ifdef CONFIG_UPROBE_EVENTS
+	if (event->tp_event->flags & TRACE_EVENT_FL_UPROBE)
+		return bpf_perf_link_fdinfo_uprobe(event, seq);
+#endif
+}
+
+static void bpf_perf_link_show_fdinfo(const struct bpf_link *link,
+				      struct seq_file *seq)
+{
+	struct bpf_perf_link *perf_link;
+	const struct perf_event *event;
+
+	perf_link = container_of(link, struct bpf_perf_link, link);
+	event = perf_get_event(perf_link->perf_file);
+	if (IS_ERR(event))
+		return;
+
+	switch (event->prog->type) {
+	case BPF_PROG_TYPE_PERF_EVENT:
+		return bpf_perf_event_link_show_fdinfo(event, seq);
+	case BPF_PROG_TYPE_TRACEPOINT:
+		return bpf_tracepoint_link_show_fdinfo(event, seq);
+	case BPF_PROG_TYPE_KPROBE:
+		return bpf_probe_link_show_fdinfo(event, seq);
+	default:
+		return;
+	}
+}
+
 static const struct bpf_link_ops bpf_perf_link_lops = {
 	.release = bpf_perf_link_release,
 	.dealloc = bpf_perf_link_dealloc,
 	.fill_link_info = bpf_perf_link_fill_link_info,
+	.show_fdinfo = bpf_perf_link_show_fdinfo,
 };
 
 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: Add show_fdinfo for perf_event
  2025-06-04 16:37 [PATCH bpf-next] bpf: Add show_fdinfo for perf_event Tao Chen
@ 2025-06-05 18:41 ` Andrii Nakryiko
  2025-06-06  2:36   ` Tao Chen
  2025-06-05 21:53 ` Jiri Olsa
  1 sibling, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2025-06-05 18:41 UTC (permalink / raw)
  To: Tao Chen
  Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa, bpf, linux-kernel

On Wed, Jun 4, 2025 at 9:37 AM Tao Chen <chen.dylane@linux.dev> wrote:
>
> After commit 1b715e1b0ec5 ("bpf: Support ->fill_link_info for perf_event") add
> perf_event info, we can also show the info with the method of cat /proc/[fd]/fdinfo.
>
> kprobe fdinfo:
> link_type:      perf
> link_id:        2
> prog_tag:       bcf7977d3b93787c
> prog_id:        18
> name:   bpf_fentry_test1
> offset: 0
> missed: 0
> addr:   ffffffffaea8d134
> event_type:     3
> cookie: 3735928559
>
> uprobe fdinfo:
> link_type:      perf
> link_id:        6
> prog_tag:       bcf7977d3b93787c
> prog_id:        7
> name:   /proc/self/exe
> offset: 6507541
> event_type:     1
> cookie: 3735928559
>
> tracepoint fdinfo:
> link_type:      perf
> link_id:        4
> prog_tag:       bcf7977d3b93787c
> prog_id:        8
> tp_name:        sched_switch
> event_type:     5
> cookie: 3735928559
>
> perf_event fdinfo:
> link_type:      perf
> link_id:        5
> prog_tag:       bcf7977d3b93787c
> prog_id:        9
> type:   1
> config: 2
> event_type:     6
> cookie: 3735928559
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> ---
>  kernel/bpf/syscall.c | 126 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 126 insertions(+)
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 9794446bc8..9af54852eb 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -3793,6 +3793,35 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,
>         info->perf_event.kprobe.cookie = event->bpf_cookie;
>         return 0;
>  }
> +
> +static void bpf_perf_link_fdinfo_kprobe(const struct perf_event *event,
> +                                       struct seq_file *seq)
> +{
> +       const char *name;
> +       int err;
> +       u32 prog_id, type;
> +       u64 offset, addr;
> +       unsigned long missed;
> +
> +       err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
> +                                     &offset, &addr, &missed);
> +       if (err)
> +               return;
> +
> +       if (type == BPF_FD_TYPE_KRETPROBE)
> +               type = BPF_PERF_EVENT_KRETPROBE;
> +       else
> +               type = BPF_PERF_EVENT_KPROBE;

maybe use "kretprobe" and "kprobe" strings?

> +
> +       seq_printf(seq,
> +                  "name:\t%s\n"
> +                  "offset:\t%llu\n"

llx, hex makes most sense (we had similar discussion within the
context of bpftool reporting)

pw-bot: cr

> +                  "missed:\t%lu\n"
> +                  "addr:\t%llx\n"

ditto, address -> hex

> +                  "event_type:\t%u\n"
> +                  "cookie:\t%llu\n",
> +                  name, offset, missed, addr, type, event->bpf_cookie);
> +}
>  #endif
>
>  #ifdef CONFIG_UPROBE_EVENTS
> @@ -3820,6 +3849,34 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event,
>         info->perf_event.uprobe.cookie = event->bpf_cookie;
>         return 0;
>  }
> +
> +static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event,
> +                                       struct seq_file *seq)
> +{
> +       const char *name;
> +       int err;
> +       u32 prog_id, type;
> +       u64 offset, addr;
> +       unsigned long missed;
> +
> +       err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
> +                                     &offset, &addr, &missed);
> +       if (err)
> +               return;
> +
> +       if (type == BPF_FD_TYPE_URETPROBE)
> +               type = BPF_PERF_EVENT_URETPROBE;
> +       else
> +               type = BPF_PERF_EVENT_UPROBE;

strings, just as above

> +
> +       seq_printf(seq,
> +                  "name:\t%s\n"
> +                  "offset:\t%llu\n"

hex

> +                  "event_type:\t%u\n"
> +                  "cookie:\t%llu\n",
> +                  name, offset, type, event->bpf_cookie);
> +
> +}
>  #endif
>
>  static int bpf_perf_link_fill_probe(const struct perf_event *event,
> @@ -3888,10 +3945,79 @@ static int bpf_perf_link_fill_link_info(const struct bpf_link *link,
>         }
>  }
>
> +static void bpf_perf_event_link_show_fdinfo(const struct perf_event *event,
> +                                           struct seq_file *seq)
> +{
> +       seq_printf(seq,
> +                  "type:\t%u\n"
> +                  "config:\t%llu\n"
> +                  "event_type:\t%u\n"

string?

> +                  "cookie:\t%llu\n",
> +                  event->attr.type, event->attr.config,
> +                  BPF_PERF_EVENT_EVENT, event->bpf_cookie);
> +}
> +
> +static void bpf_tracepoint_link_show_fdinfo(const struct perf_event *event,
> +                                           struct seq_file *seq)
> +{
> +       int err;
> +       const char *name;
> +       u32 prog_id;
> +
> +       err = bpf_get_perf_event_info(event, &prog_id, NULL, &name, NULL,
> +                                     NULL, NULL);
> +       if (err)
> +               return;
> +
> +       seq_printf(seq,
> +                  "tp_name:\t%s\n"
> +                  "event_type:\t%u\n"

string

> +                  "cookie:\t%llu\n",
> +                  name, BPF_PERF_EVENT_TRACEPOINT, event->bpf_cookie);
> +}
> +
> +static void bpf_probe_link_show_fdinfo(const struct perf_event *event,
> +                                      struct seq_file *seq)
> +{
> +#ifdef CONFIG_KPROBE_EVENTS
> +       if (event->tp_event->flags & TRACE_EVENT_FL_KPROBE)
> +               return bpf_perf_link_fdinfo_kprobe(event, seq);
> +#endif
> +
> +#ifdef CONFIG_UPROBE_EVENTS
> +       if (event->tp_event->flags & TRACE_EVENT_FL_UPROBE)
> +               return bpf_perf_link_fdinfo_uprobe(event, seq);
> +#endif
> +}
> +
> +static void bpf_perf_link_show_fdinfo(const struct bpf_link *link,
> +                                     struct seq_file *seq)
> +{
> +       struct bpf_perf_link *perf_link;
> +       const struct perf_event *event;
> +
> +       perf_link = container_of(link, struct bpf_perf_link, link);
> +       event = perf_get_event(perf_link->perf_file);
> +       if (IS_ERR(event))
> +               return;
> +
> +       switch (event->prog->type) {
> +       case BPF_PROG_TYPE_PERF_EVENT:
> +               return bpf_perf_event_link_show_fdinfo(event, seq);
> +       case BPF_PROG_TYPE_TRACEPOINT:
> +               return bpf_tracepoint_link_show_fdinfo(event, seq);
> +       case BPF_PROG_TYPE_KPROBE:
> +               return bpf_probe_link_show_fdinfo(event, seq);
> +       default:
> +               return;
> +       }
> +}
> +
>  static const struct bpf_link_ops bpf_perf_link_lops = {
>         .release = bpf_perf_link_release,
>         .dealloc = bpf_perf_link_dealloc,
>         .fill_link_info = bpf_perf_link_fill_link_info,
> +       .show_fdinfo = bpf_perf_link_show_fdinfo,
>  };
>
>  static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: Add show_fdinfo for perf_event
  2025-06-04 16:37 [PATCH bpf-next] bpf: Add show_fdinfo for perf_event Tao Chen
  2025-06-05 18:41 ` Andrii Nakryiko
@ 2025-06-05 21:53 ` Jiri Olsa
  2025-06-06  2:31   ` Tao Chen
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2025-06-05 21:53 UTC (permalink / raw)
  To: Tao Chen
  Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, bpf, linux-kernel

On Thu, Jun 05, 2025 at 12:37:22AM +0800, Tao Chen wrote:

SNIP

> +static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event,
> +					struct seq_file *seq)
> +{
> +	const char *name;
> +	int err;
> +	u32 prog_id, type;
> +	u64 offset, addr;
> +	unsigned long missed;
> +
> +	err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
> +				      &offset, &addr, &missed);

hi,
addr now gets ref_ctr_offset:
  823153334042 bpf: Add support to retrieve ref_ctr_offset for uprobe perf link

so let's display that

thanks,
jirka



> +	if (err)
> +		return;
> +
> +	if (type == BPF_FD_TYPE_URETPROBE)
> +		type = BPF_PERF_EVENT_URETPROBE;
> +	else
> +		type = BPF_PERF_EVENT_UPROBE;
> +
> +	seq_printf(seq,
> +		   "name:\t%s\n"
> +		   "offset:\t%llu\n"
> +		   "event_type:\t%u\n"
> +		   "cookie:\t%llu\n",
> +		   name, offset, type, event->bpf_cookie);
> +
> +}
>  #endif
>  

SNIP

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: Add show_fdinfo for perf_event
  2025-06-05 21:53 ` Jiri Olsa
@ 2025-06-06  2:31   ` Tao Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Tao Chen @ 2025-06-06  2:31 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, bpf, linux-kernel

在 2025/6/6 05:53, Jiri Olsa 写道:
> On Thu, Jun 05, 2025 at 12:37:22AM +0800, Tao Chen wrote:
> 
> SNIP
> 
>> +static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event,
>> +					struct seq_file *seq)
>> +{
>> +	const char *name;
>> +	int err;
>> +	u32 prog_id, type;
>> +	u64 offset, addr;
>> +	unsigned long missed;
>> +
>> +	err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
>> +				      &offset, &addr, &missed);
> 
> hi,
> addr now gets ref_ctr_offset:
>    823153334042 bpf: Add support to retrieve ref_ctr_offset for uprobe perf link
> 
> so let's display that
> 

will add it in v2, thanks.

> thanks,
> jirka
> 
> 
> 
>> +	if (err)
>> +		return;
>> +
>> +	if (type == BPF_FD_TYPE_URETPROBE)
>> +		type = BPF_PERF_EVENT_URETPROBE;
>> +	else
>> +		type = BPF_PERF_EVENT_UPROBE;
>> +
>> +	seq_printf(seq,
>> +		   "name:\t%s\n"
>> +		   "offset:\t%llu\n"
>> +		   "event_type:\t%u\n"
>> +		   "cookie:\t%llu\n",
>> +		   name, offset, type, event->bpf_cookie);
>> +
>> +}
>>   #endif
>>   
> 
> SNIP


-- 
Best Regards
Tao Chen

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] bpf: Add show_fdinfo for perf_event
  2025-06-05 18:41 ` Andrii Nakryiko
@ 2025-06-06  2:36   ` Tao Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Tao Chen @ 2025-06-06  2:36 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa, bpf, linux-kernel

在 2025/6/6 02:41, Andrii Nakryiko 写道:
> On Wed, Jun 4, 2025 at 9:37 AM Tao Chen <chen.dylane@linux.dev> wrote:
>>
>> After commit 1b715e1b0ec5 ("bpf: Support ->fill_link_info for perf_event") add
>> perf_event info, we can also show the info with the method of cat /proc/[fd]/fdinfo.
>>
>> kprobe fdinfo:
>> link_type:      perf
>> link_id:        2
>> prog_tag:       bcf7977d3b93787c
>> prog_id:        18
>> name:   bpf_fentry_test1
>> offset: 0
>> missed: 0
>> addr:   ffffffffaea8d134
>> event_type:     3
>> cookie: 3735928559
>>
>> uprobe fdinfo:
>> link_type:      perf
>> link_id:        6
>> prog_tag:       bcf7977d3b93787c
>> prog_id:        7
>> name:   /proc/self/exe
>> offset: 6507541
>> event_type:     1
>> cookie: 3735928559
>>
>> tracepoint fdinfo:
>> link_type:      perf
>> link_id:        4
>> prog_tag:       bcf7977d3b93787c
>> prog_id:        8
>> tp_name:        sched_switch
>> event_type:     5
>> cookie: 3735928559
>>
>> perf_event fdinfo:
>> link_type:      perf
>> link_id:        5
>> prog_tag:       bcf7977d3b93787c
>> prog_id:        9
>> type:   1
>> config: 2
>> event_type:     6
>> cookie: 3735928559
>>
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>> ---
>>   kernel/bpf/syscall.c | 126 +++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 126 insertions(+)
>>
>> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
>> index 9794446bc8..9af54852eb 100644
>> --- a/kernel/bpf/syscall.c
>> +++ b/kernel/bpf/syscall.c
>> @@ -3793,6 +3793,35 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,
>>          info->perf_event.kprobe.cookie = event->bpf_cookie;
>>          return 0;
>>   }
>> +
>> +static void bpf_perf_link_fdinfo_kprobe(const struct perf_event *event,
>> +                                       struct seq_file *seq)
>> +{
>> +       const char *name;
>> +       int err;
>> +       u32 prog_id, type;
>> +       u64 offset, addr;
>> +       unsigned long missed;
>> +
>> +       err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
>> +                                     &offset, &addr, &missed);
>> +       if (err)
>> +               return;
>> +
>> +       if (type == BPF_FD_TYPE_KRETPROBE)
>> +               type = BPF_PERF_EVENT_KRETPROBE;
>> +       else
>> +               type = BPF_PERF_EVENT_KPROBE;
> 
> maybe use "kretprobe" and "kprobe" strings?
> 

It looks more readable, i will change it in v2, thanks.

>> +
>> +       seq_printf(seq,
>> +                  "name:\t%s\n"
>> +                  "offset:\t%llu\n"
> 
> llx, hex makes most sense (we had similar discussion within the
> context of bpftool reporting)
> 
> pw-bot: cr
> 
>> +                  "missed:\t%lu\n"
>> +                  "addr:\t%llx\n"
> 
> ditto, address -> hex
> 

will change it in v2, thanks.

>> +                  "event_type:\t%u\n"
>> +                  "cookie:\t%llu\n",
>> +                  name, offset, missed, addr, type, event->bpf_cookie);
>> +}
>>   #endif
>>
>>   #ifdef CONFIG_UPROBE_EVENTS
>> @@ -3820,6 +3849,34 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event,
>>          info->perf_event.uprobe.cookie = event->bpf_cookie;
>>          return 0;
>>   }
>> +
>> +static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event,
>> +                                       struct seq_file *seq)
>> +{
>> +       const char *name;
>> +       int err;
>> +       u32 prog_id, type;
>> +       u64 offset, addr;
>> +       unsigned long missed;
>> +
>> +       err = bpf_get_perf_event_info(event, &prog_id, &type, &name,
>> +                                     &offset, &addr, &missed);
>> +       if (err)
>> +               return;
>> +
>> +       if (type == BPF_FD_TYPE_URETPROBE)
>> +               type = BPF_PERF_EVENT_URETPROBE;
>> +       else
>> +               type = BPF_PERF_EVENT_UPROBE;
> 
> strings, just as above
> 

get it.

>> +
>> +       seq_printf(seq,
>> +                  "name:\t%s\n"
>> +                  "offset:\t%llu\n"
> 
> hex

get it.

> 
>> +                  "event_type:\t%u\n"
>> +                  "cookie:\t%llu\n",
>> +                  name, offset, type, event->bpf_cookie);
>> +
>> +}
>>   #endif
>>
>>   static int bpf_perf_link_fill_probe(const struct perf_event *event,
>> @@ -3888,10 +3945,79 @@ static int bpf_perf_link_fill_link_info(const struct bpf_link *link,
>>          }
>>   }
>>
>> +static void bpf_perf_event_link_show_fdinfo(const struct perf_event *event,
>> +                                           struct seq_file *seq)
>> +{
>> +       seq_printf(seq,
>> +                  "type:\t%u\n"
>> +                  "config:\t%llu\n"
>> +                  "event_type:\t%u\n"
> 
> string?
> 

sure.

>> +                  "cookie:\t%llu\n",
>> +                  event->attr.type, event->attr.config,
>> +                  BPF_PERF_EVENT_EVENT, event->bpf_cookie);
>> +}
>> +
>> +static void bpf_tracepoint_link_show_fdinfo(const struct perf_event *event,
>> +                                           struct seq_file *seq)
>> +{
>> +       int err;
>> +       const char *name;
>> +       u32 prog_id;
>> +
>> +       err = bpf_get_perf_event_info(event, &prog_id, NULL, &name, NULL,
>> +                                     NULL, NULL);
>> +       if (err)
>> +               return;
>> +
>> +       seq_printf(seq,
>> +                  "tp_name:\t%s\n"
>> +                  "event_type:\t%u\n"
> 
> string
> 

get it.

>> +                  "cookie:\t%llu\n",
>> +                  name, BPF_PERF_EVENT_TRACEPOINT, event->bpf_cookie);
>> +}
>> +
>> +static void bpf_probe_link_show_fdinfo(const struct perf_event *event,
>> +                                      struct seq_file *seq)
>> +{
>> +#ifdef CONFIG_KPROBE_EVENTS
>> +       if (event->tp_event->flags & TRACE_EVENT_FL_KPROBE)
>> +               return bpf_perf_link_fdinfo_kprobe(event, seq);
>> +#endif
>> +
>> +#ifdef CONFIG_UPROBE_EVENTS
>> +       if (event->tp_event->flags & TRACE_EVENT_FL_UPROBE)
>> +               return bpf_perf_link_fdinfo_uprobe(event, seq);
>> +#endif
>> +}
>> +
>> +static void bpf_perf_link_show_fdinfo(const struct bpf_link *link,
>> +                                     struct seq_file *seq)
>> +{
>> +       struct bpf_perf_link *perf_link;
>> +       const struct perf_event *event;
>> +
>> +       perf_link = container_of(link, struct bpf_perf_link, link);
>> +       event = perf_get_event(perf_link->perf_file);
>> +       if (IS_ERR(event))
>> +               return;
>> +
>> +       switch (event->prog->type) {
>> +       case BPF_PROG_TYPE_PERF_EVENT:
>> +               return bpf_perf_event_link_show_fdinfo(event, seq);
>> +       case BPF_PROG_TYPE_TRACEPOINT:
>> +               return bpf_tracepoint_link_show_fdinfo(event, seq);
>> +       case BPF_PROG_TYPE_KPROBE:
>> +               return bpf_probe_link_show_fdinfo(event, seq);
>> +       default:
>> +               return;
>> +       }
>> +}
>> +
>>   static const struct bpf_link_ops bpf_perf_link_lops = {
>>          .release = bpf_perf_link_release,
>>          .dealloc = bpf_perf_link_dealloc,
>>          .fill_link_info = bpf_perf_link_fill_link_info,
>> +       .show_fdinfo = bpf_perf_link_show_fdinfo,
>>   };
>>
>>   static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
>> --
>> 2.43.0
>>


-- 
Best Regards
Tao Chen

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-06  2:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04 16:37 [PATCH bpf-next] bpf: Add show_fdinfo for perf_event Tao Chen
2025-06-05 18:41 ` Andrii Nakryiko
2025-06-06  2:36   ` Tao Chen
2025-06-05 21:53 ` Jiri Olsa
2025-06-06  2:31   ` Tao Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).