From: Jordan Rome <linux@jordanrome.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Kernel Team <kernel-team@fb.com>
Subject: [bpf-next v2] bpf: adjust btf load error logging
Date: Wed, 5 Mar 2025 20:07:56 -0800 [thread overview]
Message-ID: <20250306040756.3191271-1-linux@jordanrome.com> (raw)
For kernels where btf is not mandatory
we don't need to log btf loading errors
if a log buf is not provided and the
log_level is 0. This is unneeded noise.
Signed-off-by: Jordan Rome <linux@jordanrome.com>
---
tools/lib/bpf/btf.c | 11 ++++++-----
tools/lib/bpf/libbpf.c | 3 ++-
tools/lib/bpf/libbpf_internal.h | 2 +-
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index eea99c766a20..64af279c36d9 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1379,7 +1379,7 @@ static void *btf_get_raw_data(const struct btf *btf, __u32 *size, bool swap_endi
int btf_load_into_kernel(struct btf *btf,
char *log_buf, size_t log_sz, __u32 log_level,
- int token_fd)
+ int token_fd, bool btf_mandatory)
{
LIBBPF_OPTS(bpf_btf_load_opts, opts);
__u32 buf_sz = 0, raw_size;
@@ -1436,7 +1436,7 @@ int btf_load_into_kernel(struct btf *btf,
btf->fd = bpf_btf_load(raw_data, raw_size, &opts);
if (btf->fd < 0) {
/* time to turn on verbose mode and try again */
- if (log_level == 0) {
+ if (log_level == 0 && btf_mandatory) {
log_level = 1;
goto retry_load;
}
@@ -1447,10 +1447,11 @@ int btf_load_into_kernel(struct btf *btf,
goto retry_load;
err = -errno;
- pr_warn("BTF loading error: %s\n", errstr(err));
/* don't print out contents of custom log_buf */
- if (!log_buf && buf[0])
+ if (!log_buf && buf[0]) {
+ pr_warn("BTF loading error: %s\n", errstr(err));
pr_warn("-- BEGIN BTF LOAD LOG ---\n%s\n-- END BTF LOAD LOG --\n", buf);
+ }
}
done:
@@ -1460,7 +1461,7 @@ int btf_load_into_kernel(struct btf *btf,
int btf__load_into_kernel(struct btf *btf)
{
- return btf_load_into_kernel(btf, NULL, 0, 0, 0);
+ return btf_load_into_kernel(btf, NULL, 0, 0, 0, true);
}
int btf__fd(const struct btf *btf)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 8e32286854ef..2cb3f067a12e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -3604,9 +3604,10 @@ static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj)
*/
btf__set_fd(kern_btf, 0);
} else {
+ btf_mandatory = kernel_needs_btf(obj);
/* currently BPF_BTF_LOAD only supports log_level 1 */
err = btf_load_into_kernel(kern_btf, obj->log_buf, obj->log_size,
- obj->log_level ? 1 : 0, obj->token_fd);
+ obj->log_level ? 1 : 0, obj->token_fd, btf_mandatory);
}
if (sanitize) {
if (!err) {
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index de498e2dd6b0..f1de2ba462c3 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -408,7 +408,7 @@ int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
int token_fd);
int btf_load_into_kernel(struct btf *btf,
char *log_buf, size_t log_sz, __u32 log_level,
- int token_fd);
+ int token_fd, bool btf_mandatory);
struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf);
void btf_get_kernel_prefix_kind(enum bpf_attach_type attach_type,
--
2.43.5
reply other threads:[~2025-03-06 4:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20250306040756.3191271-1-linux@jordanrome.com \
--to=linux@jordanrome.com \
--cc=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