diff mbox series

[bpf-next] libbpf: change log level of BTF loading error message

Message ID 20240918193319.1165526-1-ihor.solodrai@pm.me (mailing list archive)
State Accepted
Commit cc475dea00c1d4ec32e70a8c86a7b99c99541cb0
Delegated to: BPF
Headers show
Series [bpf-next] libbpf: change log level of BTF loading error message | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 4 this patch: 4
netdev/cc_maintainers warning 8 maintainers not CCed: sdf@fomichev.me haoluo@google.com jolsa@kernel.org song@kernel.org yonghong.song@linux.dev kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: line length of 105 exceeds 80 columns WARNING: line length of 111 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-7 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-13 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc

Commit Message

Ihor Solodrai Sept. 18, 2024, 7:33 p.m. UTC
Reduce log level of BTF loading error to INFO if BTF is not required.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
---
 tools/lib/bpf/libbpf.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Eduard Zingerman Sept. 18, 2024, 9:03 p.m. UTC | #1
On Wed, 2024-09-18 at 19:33 +0000, Ihor Solodrai wrote:
> Reduce log level of BTF loading error to INFO if BTF is not required.
> 
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
> ---

fwiw, I took verifier_bswap.bpf.o and replaced .BTF section with empty
one inside it:

    for s in .BTF .rel.BTF .BTF.ext .rel.BTF.ext; do objcopy --remove-section $s verifier_bswap.bpf.o; done
    touch empty
    objcopy --add-section .BTF=empty verifier_bswap.bpf.o

And modified veristat to show log level for libbpf messages:

--- a/tools/testing/selftests/bpf/veristat.c
+++ b/tools/testing/selftests/bpf/veristat.c
@@ -187,6 +187,7 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va
                return 0;
        if (level == LIBBPF_DEBUG  && !env.debug)
                return 0;
+       fprintf(stderr, "%d: ", level);
        return vfprintf(stderr, format, args);
 }

And here is the output for veristat loading modified verifier_bswap.bpf.o:

    ./veristat -d /home/eddy/work/tmp/verifier_bswap.bpf.o  -f bswap_16
    PROCESSING /home/eddy/work/tmp/verifier_bswap.bpf.o/bswap_16, DURATION US: 26, VERDICT: success, VERIFIER LOG:
    verification time 26 usec
    stack depth 0
    processed 3 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
    2: libbpf: loading object from /home/eddy/work/tmp/verifier_bswap.bpf.o
    2: libbpf: elf: section(2) socket, size 80, link 0, flags 6, type=1
    2: libbpf: sec 'socket': found program 'bswap_16' at insn offset 0 (0 bytes), code size 3 insns (24 bytes)
    2: libbpf: sec 'socket': found program 'bswap_32' at insn offset 3 (24 bytes), code size 3 insns (24 bytes)
    2: libbpf: sec 'socket': found program 'bswap_64' at insn offset 6 (48 bytes), code size 4 insns (32 bytes)
    2: libbpf: elf: section(3) license, size 4, link 0, flags 3, type=1
    2: libbpf: license of /home/eddy/work/tmp/verifier_bswap.bpf.o is GPL
    2: libbpf: elf: section(18) .BTF, size 0, link 0, flags 0, type=1
    2: libbpf: elf: section(19) .symtab, size 336, link 20, flags 0, type=2
    2: libbpf: BTF header not found
    0: libbpf: Error loading ELF section .BTF: -22.
    ...

Note the log level is 0 which corresponds to LIBBPF_WARN.
So, if the goal is to move all optional invalid BTF messages to info
level there are probably a few more places to modify.
Ihor Solodrai Sept. 18, 2024, 9:45 p.m. UTC | #2
On Wednesday, September 18th, 2024 at 2:03 PM, Eduard Zingerman <eddyz87@gmail.com> wrote:

> 
> fwiw, I took verifier_bswap.bpf.o and replaced .BTF section with empty
> one inside it:

[...]

> So, if the goal is to move all optional invalid BTF messages to info
> level there are probably a few more places to modify.

Eduard, thanks for checking. My understanding is that a user
complained about this particular message being too noisy.

I don't know how to quickly check all the places that might be
relevant to optional BTF, and going through all the warnings feels
like too much work.

  $ grep -r 'pr_warn' | wc -l
  630

Maybe Andrii or others have a comment on this.
Andrii Nakryiko Sept. 19, 2024, 4:25 a.m. UTC | #3
On Wed, Sep 18, 2024 at 11:04 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
>
> On Wed, 2024-09-18 at 19:33 +0000, Ihor Solodrai wrote:
> > Reduce log level of BTF loading error to INFO if BTF is not required.
> >
> > Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> > Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
> > ---
>
> fwiw, I took verifier_bswap.bpf.o and replaced .BTF section with empty
> one inside it:
>
>     for s in .BTF .rel.BTF .BTF.ext .rel.BTF.ext; do objcopy --remove-section $s verifier_bswap.bpf.o; done
>     touch empty
>     objcopy --add-section .BTF=empty verifier_bswap.bpf.o
>
> And modified veristat to show log level for libbpf messages:
>
> --- a/tools/testing/selftests/bpf/veristat.c
> +++ b/tools/testing/selftests/bpf/veristat.c
> @@ -187,6 +187,7 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va
>                 return 0;
>         if (level == LIBBPF_DEBUG  && !env.debug)
>                 return 0;
> +       fprintf(stderr, "%d: ", level);
>         return vfprintf(stderr, format, args);
>  }
>
> And here is the output for veristat loading modified verifier_bswap.bpf.o:
>
>     ./veristat -d /home/eddy/work/tmp/verifier_bswap.bpf.o  -f bswap_16
>     PROCESSING /home/eddy/work/tmp/verifier_bswap.bpf.o/bswap_16, DURATION US: 26, VERDICT: success, VERIFIER LOG:
>     verification time 26 usec
>     stack depth 0
>     processed 3 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
>     2: libbpf: loading object from /home/eddy/work/tmp/verifier_bswap.bpf.o
>     2: libbpf: elf: section(2) socket, size 80, link 0, flags 6, type=1
>     2: libbpf: sec 'socket': found program 'bswap_16' at insn offset 0 (0 bytes), code size 3 insns (24 bytes)
>     2: libbpf: sec 'socket': found program 'bswap_32' at insn offset 3 (24 bytes), code size 3 insns (24 bytes)
>     2: libbpf: sec 'socket': found program 'bswap_64' at insn offset 6 (48 bytes), code size 4 insns (32 bytes)
>     2: libbpf: elf: section(3) license, size 4, link 0, flags 3, type=1
>     2: libbpf: license of /home/eddy/work/tmp/verifier_bswap.bpf.o is GPL
>     2: libbpf: elf: section(18) .BTF, size 0, link 0, flags 0, type=1
>     2: libbpf: elf: section(19) .symtab, size 336, link 20, flags 0, type=2
>     2: libbpf: BTF header not found
>     0: libbpf: Error loading ELF section .BTF: -22.
>     ...
>
> Note the log level is 0 which corresponds to LIBBPF_WARN.
> So, if the goal is to move all optional invalid BTF messages to info
> level there are probably a few more places to modify.
>

Nowadays the expectation is that the BPF program will have a valid
.BTF section, so even though .BTF is "optional", I think it's fine to
emit a warning for that case (any reasonably recent Clang will produce
valid BTF).

Ihor's patch is fixing the situation with an outdated host kernel that
doesn't understand BTF. libbpf will try to "upload" the program's BTF,
but if that fails and the BPF object doesn't use any features that
require having BTF uploaded, then it's just an information message to
the user, but otherwise can be ignored.

tl;dr, I think Ihor's patch is fine and sufficient. bpf-next is
closed, will apply when it reopens.
Eduard Zingerman Sept. 19, 2024, 4:32 a.m. UTC | #4
On Thu, 2024-09-19 at 06:25 +0200, Andrii Nakryiko wrote:

[...]

> Nowadays the expectation is that the BPF program will have a valid
> .BTF section, so even though .BTF is "optional", I think it's fine to
> emit a warning for that case (any reasonably recent Clang will produce
> valid BTF).
> 
> Ihor's patch is fixing the situation with an outdated host kernel that
> doesn't understand BTF. libbpf will try to "upload" the program's BTF,
> but if that fails and the BPF object doesn't use any features that
> require having BTF uploaded, then it's just an information message to
> the user, but otherwise can be ignored.
> 
> tl;dr, I think Ihor's patch is fine and sufficient. bpf-next is
> closed, will apply when it reopens.

Understood, thank you for explaining.
patchwork-bot+netdevbpf@kernel.org Sept. 25, 2024, 10:20 a.m. UTC | #5
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Wed, 18 Sep 2024 19:33:22 +0000 you wrote:
> Reduce log level of BTF loading error to INFO if BTF is not required.
> 
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
> ---
>  tools/lib/bpf/libbpf.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Here is the summary with links:
  - [bpf-next] libbpf: change log level of BTF loading error message
    https://git.kernel.org/bpf/bpf-next/c/cc475dea00c1

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 219facd0e66e..b8d72b5fbc79 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -3581,11 +3581,12 @@  static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj)
 report:
 	if (err) {
 		btf_mandatory = kernel_needs_btf(obj);
-		pr_warn("Error loading .BTF into kernel: %d. %s\n", err,
-			btf_mandatory ? "BTF is mandatory, can't proceed."
-				      : "BTF is optional, ignoring.");
-		if (!btf_mandatory)
+		if (btf_mandatory) {
+			pr_warn("Error loading .BTF into kernel: %d. BTF is mandatory, can't proceed.\n", err);
+		} else {
+			pr_info("Error loading .BTF into kernel: %d. BTF is optional, ignoring.\n", err);
 			err = 0;
+		}
 	}
 	return err;
 }