bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* libbpf: Loading kprobes fail on some distros
@ 2020-10-11 19:28 Yaniv Agman
  2020-10-12 17:01 ` Andrii Nakryiko
  0 siblings, 1 reply; 4+ messages in thread
From: Yaniv Agman @ 2020-10-11 19:28 UTC (permalink / raw)
  To: bpf

Trying to load kprobes on ubuntu 4.15.0, I get the following error:
libbpf: load bpf program failed: Invalid argument

The same kprobes load successfully using bcc

After some digging, I found that the issue was with the kernel version
given to the bpf syscall. While libbpf calculated the value 265984 for
the kern_version argument, bcc used 266002.
It turns out that some distros (e.g. ubuntu, debian) change the patch
number of the kernel version, as detailed in:
https://github.com/ajor/bpftrace/issues/8

I didn't find a proper API in libbpf to load kprobes in such cases -
is there any?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libbpf: Loading kprobes fail on some distros
  2020-10-11 19:28 libbpf: Loading kprobes fail on some distros Yaniv Agman
@ 2020-10-12 17:01 ` Andrii Nakryiko
  2020-10-12 21:20   ` Yaniv Agman
  0 siblings, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2020-10-12 17:01 UTC (permalink / raw)
  To: Yaniv Agman; +Cc: bpf

On Sun, Oct 11, 2020 at 7:10 PM Yaniv Agman <yanivagman@gmail.com> wrote:
>
> Trying to load kprobes on ubuntu 4.15.0, I get the following error:
> libbpf: load bpf program failed: Invalid argument
>
> The same kprobes load successfully using bcc
>
> After some digging, I found that the issue was with the kernel version
> given to the bpf syscall. While libbpf calculated the value 265984 for
> the kern_version argument, bcc used 266002.
> It turns out that some distros (e.g. ubuntu, debian) change the patch
> number of the kernel version, as detailed in:
> https://github.com/ajor/bpftrace/issues/8
>
> I didn't find a proper API in libbpf to load kprobes in such cases -
> is there any?

Yes, you can override kernel version that libbpf determines from
utsname with a special variable in your BPF code:

int KERNEL_VERSION SEC("version") = 123;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libbpf: Loading kprobes fail on some distros
  2020-10-12 17:01 ` Andrii Nakryiko
@ 2020-10-12 21:20   ` Yaniv Agman
  2020-10-12 22:10     ` Andrii Nakryiko
  0 siblings, 1 reply; 4+ messages in thread
From: Yaniv Agman @ 2020-10-12 21:20 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf

‫בתאריך יום ב׳, 12 באוק׳ 2020 ב-20:02 מאת ‪Andrii Nakryiko‬‏
<‪andrii.nakryiko@gmail.com‬‏>:‬
>
> On Sun, Oct 11, 2020 at 7:10 PM Yaniv Agman <yanivagman@gmail.com> wrote:
> >
> > Trying to load kprobes on ubuntu 4.15.0, I get the following error:
> > libbpf: load bpf program failed: Invalid argument
> >
> > The same kprobes load successfully using bcc
> >
> > After some digging, I found that the issue was with the kernel version
> > given to the bpf syscall. While libbpf calculated the value 265984 for
> > the kern_version argument, bcc used 266002.
> > It turns out that some distros (e.g. ubuntu, debian) change the patch
> > number of the kernel version, as detailed in:
> > https://github.com/ajor/bpftrace/issues/8
> >
> > I didn't find a proper API in libbpf to load kprobes in such cases -
> > is there any?
>
> Yes, you can override kernel version that libbpf determines from
> utsname with a special variable in your BPF code:
>
> int KERNEL_VERSION SEC("version") = 123;

Thanks! This is trivial, I should have thought about it myself.
For some reason, I thought that the loader should handle that, but if I include
int KERNEL_VERSION SEC("version") = LINUX_VERSION_CODE;
It should just work

Thanks again!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libbpf: Loading kprobes fail on some distros
  2020-10-12 21:20   ` Yaniv Agman
@ 2020-10-12 22:10     ` Andrii Nakryiko
  0 siblings, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2020-10-12 22:10 UTC (permalink / raw)
  To: Yaniv Agman; +Cc: bpf

On Mon, Oct 12, 2020 at 2:21 PM Yaniv Agman <yanivagman@gmail.com> wrote:
>
> ‫בתאריך יום ב׳, 12 באוק׳ 2020 ב-20:02 מאת ‪Andrii Nakryiko‬‏
> <‪andrii.nakryiko@gmail.com‬‏>:‬
> >
> > On Sun, Oct 11, 2020 at 7:10 PM Yaniv Agman <yanivagman@gmail.com> wrote:
> > >
> > > Trying to load kprobes on ubuntu 4.15.0, I get the following error:
> > > libbpf: load bpf program failed: Invalid argument
> > >
> > > The same kprobes load successfully using bcc
> > >
> > > After some digging, I found that the issue was with the kernel version
> > > given to the bpf syscall. While libbpf calculated the value 265984 for
> > > the kern_version argument, bcc used 266002.
> > > It turns out that some distros (e.g. ubuntu, debian) change the patch
> > > number of the kernel version, as detailed in:
> > > https://github.com/ajor/bpftrace/issues/8
> > >
> > > I didn't find a proper API in libbpf to load kprobes in such cases -
> > > is there any?
> >
> > Yes, you can override kernel version that libbpf determines from
> > utsname with a special variable in your BPF code:
> >
> > int KERNEL_VERSION SEC("version") = 123;
>
> Thanks! This is trivial, I should have thought about it myself.
> For some reason, I thought that the loader should handle that, but if I include

libbpf does handle that automatically, but it has to get the kernel
version from utsname() call, which apparently doesn't always match
what kernel believes LINUX_VERSION_CODE is.

> int KERNEL_VERSION SEC("version") = LINUX_VERSION_CODE;
> It should just work
>
> Thanks again!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-12 22:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-11 19:28 libbpf: Loading kprobes fail on some distros Yaniv Agman
2020-10-12 17:01 ` Andrii Nakryiko
2020-10-12 21:20   ` Yaniv Agman
2020-10-12 22:10     ` Andrii Nakryiko

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).