Re: [PATCH bpf-next v3 2/4] bpf: Introduce __bpf_kfunc_mark_deprecated annotation

Kumar Kartikeya Dwivedi
2026-04-18T20:35:25Z

On Sat, 18 Apr 2026 at 19:06, <sashiko-bot@kernel.org> wrote:
>
> Sashiko AI review found 1 potential issue(s):
> - [Medium] Programs loaded without BTF will silently bypass deprecation warnings.
> --
>
> commit 90e501a1948d112dbb3b96a16249f1f76f84b290
> Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>
> bpf: Introduce __bpf_kfunc_mark_deprecated annotation
>
> This commit introduces the __bpf_kfunc_mark_deprecated macro to annotate
> deprecated kfuncs with a replacement. It applies this annotation to existing
> impl-suffixed kfuncs and modifies the verifier to emit warnings when these
> deprecated kfuncs are used.
>
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
>
> [ ... ]
>
> > @@ -12987,6 +12987,45 @@ static int check_return_code(struct bpf_verifier_env *env, int regno, const char
> > static int process_bpf_exit_full(struct bpf_verifier_env *env,
> > bool *do_print_state, bool exception_exit);
> >
> > +static void warn_for_deprecated_kfuncs(struct bpf_verifier_env *env,
> > + struct bpf_kfunc_call_arg_meta *meta,
> > + int insn_idx, s16 offset)
> > +{
> > + const struct bpf_line_info *linfo;
> > + const char *replacement;
> > + const struct btf_type *t;
> > + struct bpf_kfunc_desc *desc;
> > + const char *file;
> > + int line_num;
> > +
> > + if (!env->prog->aux->btf)
> > + return;
>
> Will programs loaded without BTF silently bypass the deprecation warning?
>
> The kfunc deprecation tags are stored in the kernel or module BTF
> (meta->btf), not the program's BTF.
>
> If we return early here, we skip evaluating the tag entirely. There is a
> fallback branch below that handles missing line info which could be used to
> emit the warning even if the program doesn't have BTF.

Programs not using BTF are legacy, it is better to just ignore them.
Program BTF is needed for bpf_get_linfo_file_line().

>
> > +
> > + t = btf_type_by_id(meta->btf, meta->func_id);
> > + replacement = btf_find_decl_tag_value(meta->btf, t, -1, BPF_KFUNC_DECL_TAG_DEPRECATED);
>
> [ ... ]
>
> > + linfo = bpf_find_linfo(env->prog, insn_idx);
> > + if (linfo) {
> > + bpf_get_linfo_file_line(env->prog->aux->btf, linfo, &file, NULL, &line_num);
> > + warn(env, "%s:%d (insn #%d) uses deprecated kfunc %s(), which will be removed.\n",
> > + file, line_num, insn_idx, meta->func_name);
> > + } else {
> > + warn(env, "(insn #%d) uses deprecated kfunc %s(), which will be removed.\n",
> > + insn_idx, meta->func_name);
> > + }
> > +
> > + warn(env, "Switch to kfunc %s() instead.\n", replacement);
> > + warn(env, "For older kernels, choose the correct kfunc using bpf_ksym_exists().\n");
> > +
> > + desc->warned_deprecated = true;
> > +}
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260418171701.610025-1-memxor@gmail.com?part=2