All of lore.kernel.org
 help / color / mirror / Atom feed
From: jjedwa165 <jonathan.edwards@165gc.onmicrosoft.com>
To: andrii.nakryiko@gmail.com
Cc: bpf@vger.kernel.org, jonathan.edwards@165gc.onmicrosoft.com
Subject: [PATCH bpf-next] libbpf: add extra BPF_PROG_TYPE check to bpf_object__probe_loading
Date: Fri, 18 Jun 2021 19:13:22 -0400	[thread overview]
Message-ID: <20210618231322.GA27742@165gc.onmicrosoft.com> (raw)
In-Reply-To: <CAEf4BzYtuJKaOSk6nqkMbb4vwmTAXjSWOZUJ8FnRUf_7LKkO1w@mail.gmail.com>

eBPF has been backported for RHEL 7 w/ kernel 3.10-940+ [0]. However 
only the following program types are supported [1]

BPF_PROG_TYPE_KPROBE
BPF_PROG_TYPE_TRACEPOINT
BPF_PROG_TYPE_PERF_EVENT

For libbpf this causes an EINVAL return during the bpf_object__probe_loading
call which only checks to see if programs of type BPF_PROG_TYPE_SOCKET_FILTER
can load.

The following will try BPF_PROG_TYPE_TRACEPOINT as a fallback attempt before 
erroring out. BPF_PROG_TYPE_KPROBE was not a good candidate because on some
kernels it requires knowledge of the LINUX_VERSION_CODE.

[0] https://www.redhat.com/en/blog/introduction-ebpf-red-hat-enterprise-linux-7
[1] https://access.redhat.com/articles/3550581

Signed-off-by: jjedwa165 <jonathan.edwards@165gc.onmicrosoft.com>
---
 tools/lib/bpf/libbpf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 48c0ade05..1e04ce724 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4000,6 +4000,10 @@ bpf_object__probe_loading(struct bpf_object *obj)
 	attr.license = "GPL";
 
 	ret = bpf_load_program_xattr(&attr, NULL, 0);
+	if (ret < 0) {
+		attr.prog_type = BPF_PROG_TYPE_TRACEPOINT;
+		ret = bpf_load_program_xattr(&attr, NULL, 0);
+	}
 	if (ret < 0) {
 		ret = errno;
 		cp = libbpf_strerror_r(ret, errmsg, sizeof(errmsg));
-- 
2.17.1


  reply	other threads:[~2021-06-18 23:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 20:22 [PATCH] add multiple program checks to bpf_object__probe_loading Jonathan Edwards
2021-06-17  5:12 ` Andrii Nakryiko
2021-06-18 23:13   ` jjedwa165 [this message]
2021-06-19  3:26     ` [PATCH bpf-next] libbpf: add extra BPF_PROG_TYPE check " Andrii Nakryiko
2021-06-19 15:10       ` Jonathan Edwards
2021-06-21 15:30         ` patchwork-bot+netdevbpf

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=20210618231322.GA27742@165gc.onmicrosoft.com \
    --to=jonathan.edwards@165gc.onmicrosoft.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 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.