bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yaniv Agman <yanivagman@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>
Subject: Re: libbpf: Loading kprobes fail on some distros
Date: Tue, 13 Oct 2020 00:20:55 +0300	[thread overview]
Message-ID: <CAMy7=ZUcdu7_nxnUyGZkGyue5rG_0YRMXqhrnvfKW64dio1LpQ@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzYnELT0tE8Y4goPWxuBGN+G-37A8A1yjspFL=LK842geQ@mail.gmail.com>

‫בתאריך יום ב׳, 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!

  reply	other threads:[~2020-10-12 21:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-10-12 22:10     ` 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='CAMy7=ZUcdu7_nxnUyGZkGyue5rG_0YRMXqhrnvfKW64dio1LpQ@mail.gmail.com' \
    --to=yanivagman@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).