@@ -3795,6 +3795,32 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,
3795
3795
info -> perf_event .kprobe .cookie = event -> bpf_cookie ;
3796
3796
return 0 ;
3797
3797
}
3798
+
3799
+ static void bpf_perf_link_fdinfo_kprobe (const struct perf_event * event ,
3800
+ struct seq_file * seq )
3801
+ {
3802
+ const char * name ;
3803
+ int err ;
3804
+ u32 prog_id , type ;
3805
+ u64 offset , addr ;
3806
+ unsigned long missed ;
3807
+
3808
+ err = bpf_get_perf_event_info (event , & prog_id , & type , & name ,
3809
+ & offset , & addr , & missed );
3810
+ if (err )
3811
+ return ;
3812
+
3813
+ seq_printf (seq ,
3814
+ "name:\t%s\n"
3815
+ "offset:\t%#llx\n"
3816
+ "missed:\t%lu\n"
3817
+ "addr:\t%#llx\n"
3818
+ "event_type:\t%s\n"
3819
+ "cookie:\t%llu\n" ,
3820
+ name , offset , missed , addr ,
3821
+ type == BPF_FD_TYPE_KRETPROBE ? "kretprobe" : "kprobe" ,
3822
+ event -> bpf_cookie );
3823
+ }
3798
3824
#endif
3799
3825
3800
3826
#ifdef CONFIG_UPROBE_EVENTS
@@ -3823,6 +3849,31 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event,
3823
3849
info -> perf_event .uprobe .ref_ctr_offset = ref_ctr_offset ;
3824
3850
return 0 ;
3825
3851
}
3852
+
3853
+ static void bpf_perf_link_fdinfo_uprobe (const struct perf_event * event ,
3854
+ struct seq_file * seq )
3855
+ {
3856
+ const char * name ;
3857
+ int err ;
3858
+ u32 prog_id , type ;
3859
+ u64 offset , ref_ctr_offset ;
3860
+ unsigned long missed ;
3861
+
3862
+ err = bpf_get_perf_event_info (event , & prog_id , & type , & name ,
3863
+ & offset , & ref_ctr_offset , & missed );
3864
+ if (err )
3865
+ return ;
3866
+
3867
+ seq_printf (seq ,
3868
+ "name:\t%s\n"
3869
+ "offset:\t%#llx\n"
3870
+ "ref_ctr_offset:\t%#llx\n"
3871
+ "event_type:\t%s\n"
3872
+ "cookie:\t%llu\n" ,
3873
+ name , offset , ref_ctr_offset ,
3874
+ type == BPF_FD_TYPE_URETPROBE ? "uretprobe" : "uprobe" ,
3875
+ event -> bpf_cookie );
3876
+ }
3826
3877
#endif
3827
3878
3828
3879
static int bpf_perf_link_fill_probe (const struct perf_event * event ,
@@ -3891,10 +3942,79 @@ static int bpf_perf_link_fill_link_info(const struct bpf_link *link,
3891
3942
}
3892
3943
}
3893
3944
3945
+ static void bpf_perf_event_link_show_fdinfo (const struct perf_event * event ,
3946
+ struct seq_file * seq )
3947
+ {
3948
+ seq_printf (seq ,
3949
+ "type:\t%u\n"
3950
+ "config:\t%llu\n"
3951
+ "event_type:\t%s\n"
3952
+ "cookie:\t%llu\n" ,
3953
+ event -> attr .type , event -> attr .config ,
3954
+ "event" , event -> bpf_cookie );
3955
+ }
3956
+
3957
+ static void bpf_tracepoint_link_show_fdinfo (const struct perf_event * event ,
3958
+ struct seq_file * seq )
3959
+ {
3960
+ int err ;
3961
+ const char * name ;
3962
+ u32 prog_id ;
3963
+
3964
+ err = bpf_get_perf_event_info (event , & prog_id , NULL , & name , NULL ,
3965
+ NULL , NULL );
3966
+ if (err )
3967
+ return ;
3968
+
3969
+ seq_printf (seq ,
3970
+ "tp_name:\t%s\n"
3971
+ "event_type:\t%s\n"
3972
+ "cookie:\t%llu\n" ,
3973
+ name , "tracepoint" , event -> bpf_cookie );
3974
+ }
3975
+
3976
+ static void bpf_probe_link_show_fdinfo (const struct perf_event * event ,
3977
+ struct seq_file * seq )
3978
+ {
3979
+ #ifdef CONFIG_KPROBE_EVENTS
3980
+ if (event -> tp_event -> flags & TRACE_EVENT_FL_KPROBE )
3981
+ return bpf_perf_link_fdinfo_kprobe (event , seq );
3982
+ #endif
3983
+
3984
+ #ifdef CONFIG_UPROBE_EVENTS
3985
+ if (event -> tp_event -> flags & TRACE_EVENT_FL_UPROBE )
3986
+ return bpf_perf_link_fdinfo_uprobe (event , seq );
3987
+ #endif
3988
+ }
3989
+
3990
+ static void bpf_perf_link_show_fdinfo (const struct bpf_link * link ,
3991
+ struct seq_file * seq )
3992
+ {
3993
+ struct bpf_perf_link * perf_link ;
3994
+ const struct perf_event * event ;
3995
+
3996
+ perf_link = container_of (link , struct bpf_perf_link , link );
3997
+ event = perf_get_event (perf_link -> perf_file );
3998
+ if (IS_ERR (event ))
3999
+ return ;
4000
+
4001
+ switch (event -> prog -> type ) {
4002
+ case BPF_PROG_TYPE_PERF_EVENT :
4003
+ return bpf_perf_event_link_show_fdinfo (event , seq );
4004
+ case BPF_PROG_TYPE_TRACEPOINT :
4005
+ return bpf_tracepoint_link_show_fdinfo (event , seq );
4006
+ case BPF_PROG_TYPE_KPROBE :
4007
+ return bpf_probe_link_show_fdinfo (event , seq );
4008
+ default :
4009
+ return ;
4010
+ }
4011
+ }
4012
+
3894
4013
static const struct bpf_link_ops bpf_perf_link_lops = {
3895
4014
.release = bpf_perf_link_release ,
3896
4015
.dealloc = bpf_perf_link_dealloc ,
3897
4016
.fill_link_info = bpf_perf_link_fill_link_info ,
4017
+ .show_fdinfo = bpf_perf_link_show_fdinfo ,
3898
4018
};
3899
4019
3900
4020
static int bpf_perf_link_attach (const union bpf_attr * attr , struct bpf_prog * prog )
0 commit comments