All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: Kevin Sheldrake <Kevin.Sheldrake@microsoft.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: BTF without CONFIG_DEBUG_INFO_BTF=y
Date: Thu, 1 Oct 2020 12:03:40 -0300	[thread overview]
Message-ID: <20201001150340.GB18693@kernel.org> (raw)
In-Reply-To: <87v9fuhxt9.fsf@toke.dk>

Em Thu, Oct 01, 2020 at 03:37:22PM +0200, Toke Høiland-Jørgensen escreveu:
> Arnaldo Carvalho de Melo <acme@kernel.org> writes:
> 
> > Em Thu, Oct 01, 2020 at 09:50:29AM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Thu, Oct 01, 2020 at 12:33:18PM +0200, Toke Høiland-Jørgensen escreveu:
> >> > Kevin Sheldrake <Kevin.Sheldrake@microsoft.com> writes:
> >> > > I've seen mention a few times that BTF information can be made
> >> > > available from a kernel that wasn't configured with
> >> > > CONFIG_DEBUG_INFO_BTF. Please can someone tell me if this is true and,
> >> > > if so, how I could go about accessing and using it in kernels 4.15 to
> >> > > 5.8?
> >
> >> > > I have built the dwarves package from the github latest and run pahole
> >> > > with '-J' against my kernel image to no avail - it actually seg
> >> > > faults:
> >
> >> > > ~/dwarves/build $ sudo ./pahole /boot/vmlinuz-5.3.0-1022-azure
> >> > > btf_elf__new: cannot get elf header.
> >> > > ctf__new: cannot get elf header.
> >> > > ~/dwarves/build $ sudo ./pahole -J /boot/vmlinuz-5.3.0-1022-azure
> >> > > btf_elf__new: cannot get elf header.
> >> > > ctf__new: cannot get elf header.
> >> > > Segmentation fault
> >> > > ~/dwarves/build $ sudo ./pahole --version
> >> > > v1.17
> >
> >> > > Judging by the output, I'm guessing that my kernel image isn't the
> >> > > right kind of file. Can someone point me in the right direction?
> >
> >> > vmlinuz is a compressed image. There's a script in the kernel source
> >> > tree (scripts/extract-vmlinux), however the kernel image in /boot/
> >> > probably also has debug information stripped from it, so that likely
> >> > won't help you. You'll need to get hold of a kernel image with debug
> >> > information still intact somehow...
> >
> >> > (Either way, pahole shouldn't be segfaulting, so hopefully someone can
> >> > take a look at that).
> >
> >> Reproduced:
> >
> >> [acme@five pahole]$ cp /boot/vmlinuz-5.9.0-rc6+ .
> >> [acme@five pahole]$ pahole -J vmlinuz-5.9.0-rc6+
> >> btf_elf__new: cannot get elf header.
> >> ctf__new: cannot get elf header.
> >> tag__check_id_drift: subroutine_type id drift, core_id: 1145, btf_type_id: 1143, type_id_off: 0
> >> pahole: type 'vmlinuz-5.9.0-rc6+' not found
> >> libbpf: Unsupported BTF_KIND:0
> >> btf_elf__encode: btf__new failed!
> >> free(): double free detected in tcache 2
> >> Aborted (core dumped)
> >> [acme@five pahole]$
> >  
> >> Working on a fix. Thanks for the report!
> >
> > commit 4e55425d9eaac78689fbd296283e1557bb6ca725
> > Author: Arnaldo Carvalho de Melo <acme@redhat.com>
> > Date:   Thu Oct 1 10:10:50 2020 -0300
> >
> >     pahole: Only try using a single file name as a type name if not encoding BTF or CTF
> >     
> >     Otherwise we end up trying to encode without any debug info and this
> >     causes a segfault:
> >     
> >     Before:
> >     
> >       $ pahole -J vmlinuz-5.9.0-rc6+
> >       tag__check_id_drift: subroutine_type id drift, core_id: 1145, btf_type_id: 1143, type_id_off: 0
> >       pahole: type 'vmlinuz-5.9.0-rc6+' not found
> >       libbpf: Unsupported BTF_KIND:0
> >       btf_elf__encode: btf__new failed!
> >       free(): double free detected in tcache 2
> >       Aborted (core dumped)
> >       $
> >     
> >     The vmlinuz file doesn't contain any debugging info, fixing it we get:
> >     
> >       $ pahole -J vmlinuz-5.9.0-rc6+
> >       pahole: vmlinuz-5.9.0-rc6+: No debugging information found
> >       $
> >     
> >     If debugging info is available, it all works as before:
> >     
> >     Using /sys/kernel/btf/vmlinux
> >     
> >     $ ls -la /sys/kernel/btf/vmlinux
> >     -r--r--r--. 1 root root 3393761 Oct  1 09:50 /sys/kernel/btf/vmlinux
> >     
> >       $ pahole -E fw_cache_entry
> >       struct fw_cache_entry {
> >             struct list_head {
> >                     struct list_head * next;          /*     0     8 */
> >                     struct list_head * prev;          /*     8     8 */
> >             } list; /*     0    16 */
> >             const char  *              name;          /*    16     8 */
> >     
> >             /* size: 24, cachelines: 1, members: 2 */
> >             /* last cacheline: 24 bytes */
> >       };
> >       $
> >     
> >     Or explicitely asking for DWARF, where it will find the appropriate
> >     vmlinux according to its buildid in /sys/kernel/notes:
> >     
> >       $ pahole -F dwarf pm_clock_entry
> >       struct pm_clock_entry {
> >             struct list_head           node;          /*     0    16 */
> >             char *                     con_id;        /*    16     8 */
> >             struct clk *               clk;           /*    24     8 */
> >             enum pce_status            status;        /*    32     4 */
> >     
> >             /* size: 40, cachelines: 1, members: 4 */
> >             /* padding: 4 */
> >             /* last cacheline: 40 bytes */
> >       };
> >       $ pahole -F dwarf --expand_types pm_clock_entry
> >       struct pm_clock_entry {
> >             struct list_head {
> >                     struct list_head * next;          /*     0     8 */
> >                     struct list_head * prev;          /*     8     8 */
> >             } node; /*     0    16 */
> >             char *                     con_id;        /*    16     8 */
> >             struct clk *               clk;           /*    24     8 */
> >             enum pce_status            status;        /*    32     4 */
> >     
> >             /* size: 40, cachelines: 1, members: 4 */
> >             /* padding: 4 */
> >             /* last cacheline: 40 bytes */
> >       };
> >       $
> >     
> >     Reported-by: Kevin Sheldrake <Kevin.Sheldrake@microsoft.com>
> >     Cc: Toke Høiland-Jørgensen <toke@redhat.com>
> >     Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Yeah, that's much better!
> 
> Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>

Thanks, adding your Acked-by and pushing it to the public repos at
github and kernel.org

      parent reply	other threads:[~2020-10-01 15:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01 10:22 BTF without CONFIG_DEBUG_INFO_BTF=y Kevin Sheldrake
2020-10-01 10:33 ` Toke Høiland-Jørgensen
2020-10-01 12:50   ` Arnaldo Carvalho de Melo
2020-10-01 13:22     ` Arnaldo Carvalho de Melo
2020-10-01 13:37       ` Toke Høiland-Jørgensen
2020-10-01 13:45         ` [EXTERNAL] " Kevin Sheldrake
2020-10-01 15:03           ` Arnaldo Carvalho de Melo
2020-10-01 15:03         ` Arnaldo Carvalho de Melo [this message]

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=20201001150340.GB18693@kernel.org \
    --to=acme@kernel.org \
    --cc=Kevin.Sheldrake@microsoft.com \
    --cc=bpf@vger.kernel.org \
    --cc=toke@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.