bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Rafael David Tinoco <rafaeldtinoco@ubuntu.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	Vamsi Kodavanty <vamsi@araalinetworks.com>,
	bpf <bpf@vger.kernel.org>
Subject: Re: [BPF CO-RE clarification] Use CO-RE on older kernel versions.
Date: Fri, 12 Mar 2021 10:36:02 -0800	[thread overview]
Message-ID: <CAEf4BzYDNQwTBmd_gG5isqfy0JPrW+ticu=NUvqhvbYmLOWC-g@mail.gmail.com> (raw)
In-Reply-To: <7BEF1010-5D4A-4C6F-8059-BD18A4A9EA6F@ubuntu.com>

On Wed, Mar 10, 2021 at 2:45 PM Rafael David Tinoco
<rafaeldtinoco@ubuntu.com> wrote:
> > From what I see all the CO-RE relocations applied successfully (even
> > though all the offsets stayed the same, so presumably you compiled
> > your BPF program with vmlinux.h from the exact same kernel you are
> > running it on?). Are you sure that vmlinux image you are providing
> > corresponds to the actual kernel you are running on?
> Yep, I have created the following:
> https://pastebin.ubuntu.com/p/h58YyNr4HR/

Ok, I have no idea, tbh. Maybe `pahole -j` is subtly modifying vmlinux
is some way (but then why would kernel start and only fail to
load/verify your BPF program?). It's also clear that CO-RE is doing
exactly the same instruction patching, so shouldn't be some invalid
CO-RE relocation applied, I think. So no idea and not sure how to
investigate this.

But I think I'd never do `pahole -J` on actual vmlinux image you are
going to run. It's much safer and more convenient to make a copy,
generate .BTF and then extract just .BTF section into a small binary,
which can be provided separately.

> to make this easier.
> It is a 4.15.0-1080 kernel and a 4.15.18+. They are pretty close

Also this. Seems like it is two different kernels still, however small
the difference between them is. Have you tried building *exactly* the
same kernel with exactly the same config, but just with pahole -J
during the build on vmlinux.o (which is later linked into a final
vmlinux) vs running pahole -J on final vmlinux after the build. Notice
that two approach differ in terms of which object file is being
modified. With link-vmlinux.sh, kernel linker scripts dictate final
layout, while if you run `pahole -J` on final vmlinux, it can modify
the layout and potentially break something sensitive. pahole is using
llvm-objcopy internally, and llvm-objcopy isn't a very trivial tool.

> despite the versioning (second was generated with make deb-dpkg).
> I’m using same .config file for both, only difference is that the
> 4.15.18+ was compiled with the changed link-vmlinux.sh file.
> The /usr/lib/debug/boot/vmlinux files are generated by the same
> build and I have tried 2 or 3 of the existing packaged kernels. The
> only thing I did was “pahole -J” to /usr/lib/debug/boot/vmlinux-XXX
> files (adding the BTF section to them).
> Running same binary in a 5.8.0-43 kernel works out-of-the-box:
> https://pastebin.ubuntu.com/p/VKTjMcp6Xs/
> >
> > I'd start by comparing libbpf logs for vmlinux you get with modified
> > link-vmlinux.sh script and with just explicit pahole -J. If all the
> > CO-RE parts are identical, the problem is somewhere else most
> > probably.
> The difference between (1) and (2) from the paste (error and success):
> libbpf: CO-RE relocating [0] struct task_struct: found target
> candidate [17361] struct task_struct in [vmlinux]
> libbpf: CO-RE relocating [0] struct task_struct: found target
> candidate [17360] struct task_struct in [vmlinux]
> libbpf: prog 'tcp_connect': relo #0: matching candidate #1 [17361]
> struct task_struct.comm (0:90 @ offset 2640)
> libbpf: prog 'tcp_connect': relo #0: matching candidate #1 [17360]
> struct task_struct.comm (0:90 @ offset 2640)
> Code is at:
> https://github.com/rafaeldtinoco/portablebpf
> and it is not much different than any other libbpf example.
> thanks again for verifying this!
> -rafaeldtinoco

  reply	other threads:[~2021-03-12 18:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 18:02 [BPF CO-RE clarification] Use CO-RE on older kernel versions Vamsi Kodavanty
2021-01-06 23:55 ` Andrii Nakryiko
2021-01-07 18:12   ` Vamsi Kodavanty
2021-01-07 18:52     ` Andrii Nakryiko
2021-01-07 22:45       ` Vamsi Kodavanty
2021-01-07 23:32         ` Andrii Nakryiko
2021-01-08  0:16           ` Vamsi Kodavanty
2021-01-08  1:31             ` Vamsi Kodavanty
2021-03-03 18:14               ` Rafael David Tinoco
2021-03-04  7:05                 ` Andrii Nakryiko
2021-03-04 13:10                   ` Arnaldo Carvalho de Melo
2021-03-05  6:32                   ` Rafael David Tinoco
     [not found]                     ` <67E3C788-2835-4793-8A9C-51C5D807C294@ubuntu.com>
2021-03-10  6:00                       ` Fwd: " Rafael David Tinoco
2021-03-10 19:19                       ` Andrii Nakryiko
2021-03-10 22:45                         ` Rafael David Tinoco
2021-03-12 18:36                           ` Andrii Nakryiko [this message]
2021-03-17  4:39                             ` Rafael David Tinoco
2021-03-17 14:31                               ` Rafael David Tinoco
2021-03-19  4:36                                 ` Andrii Nakryiko
2021-03-19  4:42                                   ` Rafael David Tinoco

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:

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

  git send-email \
    --in-reply-to='CAEf4BzYDNQwTBmd_gG5isqfy0JPrW+ticu=NUvqhvbYmLOWC-g@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@redhat.com \
    --cc=bpf@vger.kernel.org \
    --cc=rafaeldtinoco@ubuntu.com \
    --cc=vamsi@araalinetworks.com \


* 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;
as well as URLs for NNTP newsgroup(s).