From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 05/11] libbpf: preserve kernel error code and remove kprobe prog type guessing
Date: Sun, 5 Dec 2021 12:32:28 -0800 [thread overview]
Message-ID: <20211205203234.1322242-6-andrii@kernel.org> (raw)
In-Reply-To: <20211205203234.1322242-1-andrii@kernel.org>
Instead of rewriting error code returned by the kernel of prog load with
libbpf-sepcific variants pass through the original error.
There is now also no need to have a backup generic -LIBBPF_ERRNO__LOAD
fallback error as bpf_prog_load() guarantees that errno will be properly
set no matter what.
Also drop a completely outdated and pretty useless BPF_PROG_TYPE_KPROBE
guess logic. It's not necessary and neither it's helpful in modern BPF
applications.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/libbpf.c | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index f07ff39a9d20..3fd4e3d5a11f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6696,34 +6696,19 @@ static int bpf_object_load_prog_instance(struct bpf_object *obj, struct bpf_prog
free(log_buf);
goto retry_load;
}
- ret = errno ? -errno : -LIBBPF_ERRNO__LOAD;
+
+ ret = -errno;
cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
pr_warn("prog '%s': BPF program load failed: %s\n", prog->name, cp);
pr_perm_msg(ret);
if (log_buf && log_buf[0] != '\0') {
- ret = -LIBBPF_ERRNO__VERIFY;
pr_warn("prog '%s': -- BEGIN PROG LOAD LOG --\n%s-- END PROG LOAD LOG --\n",
prog->name, log_buf);
}
if (insns_cnt >= BPF_MAXINSNS) {
pr_warn("prog '%s': program too large (%d insns), at most %d insns\n",
prog->name, insns_cnt, BPF_MAXINSNS);
- ret = -LIBBPF_ERRNO__PROG2BIG;
- } else if (prog->type != BPF_PROG_TYPE_KPROBE) {
- /* Wrong program type? */
- int fd;
-
- load_attr.expected_attach_type = 0;
- load_attr.log_buf = NULL;
- load_attr.log_size = 0;
- fd = bpf_prog_load(BPF_PROG_TYPE_KPROBE, prog_name, license,
- insns, insns_cnt, &load_attr);
- if (fd >= 0) {
- close(fd);
- ret = -LIBBPF_ERRNO__PROGTYPE;
- goto out;
- }
}
out:
--
2.30.2
next prev parent reply other threads:[~2021-12-05 20:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-05 20:32 [PATCH bpf-next 00/11] Enhance and rework logging controls in libbpf Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 01/11] libbpf: add OPTS-based bpf_btf_load() API Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 02/11] libbpf: allow passing preallocated log_buf when loading BTF into kernel Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 03/11] libbpf: allow passing user log setting through bpf_object_open_opts Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 04/11] libbpf: improve logging around BPF program loading Andrii Nakryiko
2021-12-05 20:32 ` Andrii Nakryiko [this message]
2021-12-05 20:32 ` [PATCH bpf-next 06/11] libbpf: add per-program log buffer setter and getter Andrii Nakryiko
2021-12-07 19:41 ` Alexei Starovoitov
2021-12-07 22:48 ` Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 07/11] libbpf: deprecate bpf_object__load_xattr() Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 08/11] selftests/bpf: replace all uses of bpf_load_btf() with bpf_btf_load() Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 09/11] selftests/bpf: add test for libbpf's custom log_buf behavior Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 10/11] selftests/bpf: remove the only use of deprecated bpf_object__load_xattr() Andrii Nakryiko
2021-12-05 20:32 ` [PATCH bpf-next 11/11] bpftool: switch bpf_object__load_xattr() to bpf_object__load() 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=20211205203234.1322242-6-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
/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