Re: [PATCH bpf-next v1 2/3] bpf: Emit verifier warnings through prog stderr

Alexei Starovoitov
2026-03-30T15:02:51Z

On Sun, Mar 29, 2026 at 2:25 PM Kumar Kartikeya Dwivedi
<memxor@gmail.com> wrote:
>
> There is a class of messages that aren't treated as hard errors, such
> that the program must be rejected, but should be surfaced to the user to
> make them aware that while the program succeeded, parts of their program
> are exhibiting behavior that needs attention. One example is usage of
> kfuncs that are supposed to be deprecated, and may be dropped in the
> future, though are preserved for now for backwards compatibility.
>
> Add support for emitting a warning message to the BPF program's stderr
> stream whenever we detect usage of a _impl suffixed kfunc, which have
> now been replaced with KF_IMPLICIT_ARGS variants. For this purpose,
> introduce bpf_stream_pr_warn() as a convenience wrapper, and then mark
> bpf_find_linfo() as global to allow its usage in the verifier to find
> the linfo corresponding to an instruction index.
>
> To make the message more helpful, recommend usage of bpf_ksym_exists()
> as a way for the user to write backwards compatible BPF code that works
> on older kernels offering _impl suffixed kfuncs.
>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
> include/linux/bpf.h | 9 ++++++
> include/linux/bpf_verifier.h | 3 +-
> kernel/bpf/log.c | 6 ++--
> kernel/bpf/verifier.c | 53 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 67 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 2c4f92085d79..d0158edd27b2 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -3912,6 +3912,15 @@ int bpf_stream_stage_dump_stack(struct bpf_stream_stage *ss);
> bpf_stream_stage_free(&ss); \
> })
>
> +#define bpf_stream_pr_warn(prog, fmt, ...) \
> + ({ \
> + struct bpf_stream_stage __ss; \
> + \
> + bpf_stream_stage(__ss, prog, BPF_STDERR, ({ \
> + bpf_stream_printk(__ss, fmt, ##__VA_ARGS__); \

Warnings are helpful, but delivering them via streams feels odd.
streams should have been an interface for run-time where
either bpf core, kfuncs, or progs themselves send messages to user space.

These warns come from the verifier. So conceptually fit better
into verifier log. libbpf doesn't use it by default, but maybe it should.
Eventually we will have common_attr in sys_bpf and other commands
like map_create will print human readable errors.

pw-bot: cr