public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Edwards <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: Sat, 19 Jun 2021 11:10:07 -0400	[thread overview]
Message-ID: <20210619151007.GA6963@165gc.onmicrosoft.com> (raw)
In-Reply-To: <CAEf4BzZxHSAn6d7M9O5_HE7p5K-Z2OJ1E9f0YGXfAbdWhsZ1GQ@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

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jonathan Edwards <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-19 15:10 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   ` [PATCH bpf-next] libbpf: add extra BPF_PROG_TYPE check " jjedwa165
2021-06-19  3:26     ` Andrii Nakryiko
2021-06-19 15:10       ` Jonathan Edwards [this message]
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=20210619151007.GA6963@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox