Linux Perf Users
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Leo Yan <leo.yan@arm.com>, Lorenz Bauer <lmb@isovalent.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Alan Maguire <alan.maguire@oracle.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	bpf@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: BTF loading failing on perf
Date: Tue, 10 Jun 2025 17:27:49 -0300	[thread overview]
Message-ID: <aEiVRcpvllECCrwS@x1> (raw)
In-Reply-To: <aENKD6yUCN9UXves@x1>

On Fri, Jun 06, 2025 at 05:05:35PM -0300, Arnaldo Carvalho de Melo wrote:
> On Fri, Jun 06, 2025 at 09:20:57AM -0700, Andrii Nakryiko wrote:
> > On Fri, Jun 6, 2025 at 9:14 AM Leo Yan <leo.yan@arm.com> wrote:
> > > On Fri, Jun 06, 2025 at 12:37:55PM -0300, Arnaldo Carvalho de Melo wrote:
> > > > root@number:~# perf trace -e openat --max-events=1
> > > > libbpf: failed to read kernel BTF from '/sys/kernel/btf/vmlinux': -ENODEV
> > > > libbpf: failed to read kernel BTF from '/sys/kernel/btf/vmlinux': -ENODEV
> > > >      0.000 ( 0.016 ms): ptyxis-agent/4375 openat(dfd: CWD, filename: "/proc/6593/cmdline", flags: RDONLY|CLOEXEC) = 13
> > > > root@number:~#
> > > >
> > > > openat(AT_FDCWD, "/sys/kernel/btf/vmlinux", O_RDONLY) = 258
> > > > mmap(NULL, 6519699, PROT_READ, MAP_PRIVATE, 258, 0) = -1 ENODEV (No such device)
> > > > libbpf: failed to read kernel BTF from '/sys/kernel/btf/vmlinux': -ENODEV
> > >
> > > Have you included the commit below in the kernel side?
> > 
> > It doesn't matter, libbpf should silently fallback to non-mmap() way,
> 
> Right, it has to work with older kernels, etc.
> 
> > and it clearly doesn't.
> 
> > We need something like this:
> > +++ b/tools/lib/bpf/btf.c
> > @@ -1384,12 +1384,12 @@ static struct btf *btf_parse_raw_mmap(const
> > char *path, struct btf *base_btf)
> > 
> >         fd = open(path, O_RDONLY);
> >         if (fd < 0)
> > -               return libbpf_err_ptr(-errno);
> > +               return ERR_PTR(-errno);
> > 
> >         if (fstat(fd, &st) < 0) {
> >                 err = -errno;
> >                 close(fd);
> > -               return libbpf_err_ptr(err);
> > +               return ERR_PTR(err);
> >         }
> > 
> >         data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
> > @@ -1397,7 +1397,7 @@ static struct btf *btf_parse_raw_mmap(const char
> > *path, struct btf *base_btf)
> >         close(fd);
> > 
> >         if (data == MAP_FAILED)
> > -               return libbpf_err_ptr(err);
> > +               return ERR_PTR(err);
> > 
> >         btf = btf_new(data, st.st_size, base_btf, true);
> >         if (IS_ERR(btf))
> > 
> > libbpf_err_ptr() should be used for user-facing API functions, they
> > return NULL on error and set errno, so checking for IS_ERR() is wrong
> > here.
> 
> And the only user of the above function is:
> 
>                 btf = btf_parse_raw_mmap(sysfs_btf_path, NULL);
>                 if (IS_ERR(btf))
>                         btf = btf__parse(sysfs_btf_path, NULL);
> 
> That expects ERR_PTR() to then use IS_ERR().
> 
> I think this could be automated with something like coccinnele(sp)?
 
> Anyway, I tested the patch above and it seems to fix the issue, so:
 
> Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Was this fixed/merged?

- Arnaldo

  parent reply	other threads:[~2025-06-10 20:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06 15:37 BTF loading failing on perf Arnaldo Carvalho de Melo
2025-06-06 16:14 ` Leo Yan
2025-06-06 16:20   ` Andrii Nakryiko
2025-06-06 20:05     ` Arnaldo Carvalho de Melo
2025-06-06 20:22       ` Andrii Nakryiko
2025-06-10 20:27       ` Arnaldo Carvalho de Melo [this message]
2025-06-10 23:12         ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aEiVRcpvllECCrwS@x1 \
    --to=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=leo.yan@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=lmb@isovalent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox