Re: [PATCH bpf-next] selftests/bpf: make use of PROCMAP_QUERY ioctl if available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 7, 2024 at 2:07 AM Jiri Olsa <olsajiri@xxxxxxxxx> wrote:
>
> On Tue, Aug 06, 2024 at 04:03:19PM -0700, Andrii Nakryiko wrote:
>
> SNIP
>
> >  ssize_t get_uprobe_offset(const void *addr)
> >  {
> > -     size_t start, end, base;
> > -     char buf[256];
> > -     bool found = false;
> > +     size_t start, base, end;
> >       FILE *f;
> > +     char buf[256];
> > +     int err, flags;
> >
> >       f = fopen("/proc/self/maps", "r");
> >       if (!f)
> >               return -errno;
> >
> > -     while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &base) == 4) {
> > -             if (buf[2] == 'x' && (uintptr_t)addr >= start && (uintptr_t)addr < end) {
> > -                     found = true;
> > -                     break;
> > +     /* requested executable VMA only */
> > +     err = procmap_query(fileno(f), addr, PROCMAP_QUERY_VMA_EXECUTABLE, &start, &base, &flags);
> > +     if (err == -EOPNOTSUPP) {
> > +             bool found = false;
> > +
> > +             while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &base) == 4) {
> > +                     if (buf[2] == 'x' && (uintptr_t)addr >= start && (uintptr_t)addr < end) {
> > +                             found = true;
> > +                             break;
> > +                     }
> > +             }
> > +             if (!found) {
> > +                     fclose(f);
> > +                     return -ESRCH;
> >               }
> > +     } else if (err) {
> > +             fclose(f);
> > +             return err;
>
> I feel like I commented on this before, so feel free to ignore me,
> but this seems similar to the code below, could be in one function

Do you mean get_rel_offset()? That one is for data symbols (USDT
semaphores), so it a) doesn't do arch-specific adjustments and b)
doesn't filter by executable flag. So while the logic of parsing and
finding VMA is similar, conditions and adjustments are different. It
feels not worth combining them, tbh.

>
> anyway it's good for follow up
>
> there was another selftest in the original patchset adding benchmark
> for the procfs query interface, is it coming in as well?

I didn't plan to send it, given it's not really a test. But I can put
it on Github somewhere, probably, if it's useful.

>
> Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
>
> jirka
>
> >       }
> > -
> >       fclose(f);
> >
> > -     if (!found)
> > -             return -ESRCH;
> > -
> >  #if defined(__powerpc64__) && defined(_CALL_ELF) && _CALL_ELF == 2
> >
> >  #define OP_RT_RA_MASK   0xffff0000UL
> > @@ -307,15 +371,25 @@ ssize_t get_rel_offset(uintptr_t addr)
> >       size_t start, end, offset;
> >       char buf[256];
> >       FILE *f;
> > +     int err, flags;
> >
> >       f = fopen("/proc/self/maps", "r");
> >       if (!f)
> >               return -errno;
> >
> > -     while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &offset) == 4) {
> > -             if (addr >= start && addr < end) {
> > -                     fclose(f);
> > -                     return (size_t)addr - start + offset;
> > +     err = procmap_query(fileno(f), (const void *)addr, 0, &start, &offset, &flags);
> > +     if (err == 0) {
> > +             fclose(f);
> > +             return (size_t)addr - start + offset;
> > +     } else if (err != -EOPNOTSUPP) {
> > +             fclose(f);
> > +             return err;
> > +     } else if (err) {
> > +             while (fscanf(f, "%zx-%zx %s %zx %*[^\n]\n", &start, &end, buf, &offset) == 4) {
> > +                     if (addr >= start && addr < end) {
> > +                             fclose(f);
> > +                             return (size_t)addr - start + offset;
> > +                     }
> >               }
> >       }
> >
> > --
> > 2.43.5
> >
> >





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux