public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v1 3/3] libbpf: Wire up verifier warning display logic
Date: Sun, 29 Mar 2026 23:25:33 +0200	[thread overview]
Message-ID: <20260329212534.3270005-4-memxor@gmail.com> (raw)
In-Reply-To: <20260329212534.3270005-1-memxor@gmail.com>

Wire up the flushing of all accumulated messages in a program's stderr
stream after verification is complete. An example is shown below of a
warning printed now about usage of deprecated kfuncs.

$ ./test_progs -t kfunc_implicit_args/test_kfunc_implicit_arg_legacy_impl -v
...
libbpf: prog 'test_kfunc_implicit_arg_legacy_impl': VERIFIER WARNINGS:
WARNING: kfunc_implicit_args.c:40 calls deprecated kfunc bpf_kfunc_implicit_arg_legacy_impl(), which will be removed.
WARNING: Switch to kfunc bpf_kfunc_implicit_arg_legacy() instead.
WARNING: For older kernels, choose the kfunc using bpf_ksym_exists(bpf_kfunc_implicit_arg_legacy).
...

Note that test_progs overrides the default logging function, hence -v is
necessary. By default these messages would be printed for the user.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 tools/lib/bpf/libbpf.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 9ea41f40dc82..f308bacd083f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7826,6 +7826,27 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
 
 static void fixup_verifier_log(struct bpf_program *prog, char *buf, size_t buf_sz);
 
+static void bpf_object_load_prog_emit_stderr(struct bpf_program *prog, int prog_fd)
+{
+	char chunk[256];
+	bool emitted = false;
+	int ret;
+
+	while ((ret = bpf_prog_stream_read(prog_fd, BPF_STREAM_STDERR, chunk,
+					   sizeof(chunk), NULL)) > 0) {
+		if (!emitted) {
+			pr_warn("prog '%s': VERIFIER WARNINGS:\n", prog->name);
+			emitted = true;
+		}
+		libbpf_print(LIBBPF_WARN, "%.*s", ret, chunk);
+	}
+
+	if (ret < 0) {
+		pr_debug("prog '%s': failed to read BPF stderr stream: %s\n",
+			 prog->name, errstr(ret));
+	}
+}
+
 static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog,
 				struct bpf_insn *insns, int insns_cnt,
 				const char *license, __u32 kern_version, int *prog_fd)
@@ -7950,6 +7971,8 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
 				 prog->name, log_buf);
 		}
 
+		bpf_object_load_prog_emit_stderr(prog, ret);
+
 		if (obj->has_rodata && kernel_supports(obj, FEAT_PROG_BIND_MAP)) {
 			struct bpf_map *map;
 			int i;
-- 
2.52.0


  parent reply	other threads:[~2026-03-29 21:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-29 21:25 [PATCH bpf-next v1 0/3] Add support to emit verifier warnings Kumar Kartikeya Dwivedi
2026-03-29 21:25 ` [PATCH bpf-next v1 1/3] bpf: Extract bpf_get_linfo_file_line Kumar Kartikeya Dwivedi
2026-03-30 11:28   ` Mykyta Yatsenko
2026-03-30 12:27   ` Puranjay Mohan
2026-03-30 12:35   ` Puranjay Mohan
2026-03-29 21:25 ` [PATCH bpf-next v1 2/3] bpf: Emit verifier warnings through prog stderr Kumar Kartikeya Dwivedi
2026-03-30 11:39   ` Mykyta Yatsenko
2026-03-30 12:39     ` Puranjay Mohan
2026-03-30 15:02   ` Alexei Starovoitov
2026-03-29 21:25 ` Kumar Kartikeya Dwivedi [this message]
2026-03-30 12:56   ` [PATCH bpf-next v1 3/3] libbpf: Wire up verifier warning display logic Mykyta Yatsenko
2026-03-30 23:46   ` 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=20260329212534.3270005-4-memxor@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=martin.lau@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