Re: [PATCH v2] tracing/uprobe: Add missing PID filter for uretprobe

Jiri Olsa
2024-09-10T08:45:40Z

On Mon, Sep 09, 2024 at 08:34:36PM +0200, Oleg Nesterov wrote:
> On 09/09, Jiri Olsa wrote:
> >
> > On Fri, Sep 06, 2024 at 09:18:15PM +0200, Oleg Nesterov wrote:
> > >
> > > And btw... Can bpftrace attach to the uprobe tp?
> > >
> > > # perf probe -x ./test -a func
> > > Added new event:
> > > probe_test:func (on func in /root/TTT/test)
> > >
> > > You can now use it in all perf tools, such as:
> > >
> > > perf record -e probe_test:func -aR sleep 1
> > >
> > > # bpftrace -e 'tracepoint:probe_test:func { printf("%d\n", pid); }'
> > > Attaching 1 probe...
> > > ioctl(PERF_EVENT_IOC_SET_BPF): Invalid argument
> > > ERROR: Error attaching probe: tracepoint:probe_test:func
> >
> > the problem here is that bpftrace assumes BPF_PROG_TYPE_TRACEPOINT type
> > for bpf program, but that will fail in perf_event_set_bpf_prog where
> > perf event will be identified as uprobe and demands bpf program type
> > to be BPF_PROG_TYPE_KPROBE
>
> Yes, thanks, I know,
>
> > I don't think
> > there's a way to find out the tracepoint subtype (kprobe/uprobe) from
> > the tracefs record
>
> Hmm, indeed. it seems that it is not possible to derive tp_event->flags
> from tracefs...
>
> Perhaps bpftrace could look for probe_test:func in [uk]probe_events?
> Or simply retry ioctl(PERF_EVENT_IOC_SET_BPF) with BPF_PROG_TYPE_KPROBE
> if BPF_PROG_TYPE_TRACEPOINT returns EINVAL? Ugly, yes.

yep, but will probably work, I created issue https://github.com/bpftrace/bpftrace/issues/3447
so it's not lost

jirka