Re: [PATCH bpf-next v1 3/4] resolve_btfids: Reject kfunc families that libbpf can't disambiguate

From: Eduard Zingerman

Date: Wed Nov 18 2026 - 18:00:05 EST


On Tue, 2026-11-17 at 12:21 -0700, Ihor Solodrai wrote:
> Kfuncs sharing an essential name, foo and foo___<flavor>, form a family.
> When resolving a kfunc foo, libbpf binds the kernel's foo if the
> prototypes are compatible, and otherwise the only family member whose
> prototype passes bpf_core_types_are_compat() against the declaration.
> That is only safe if no declaration can be compatible with two members
> at once.
>
> bpf_core_types_are_compat() compares prototypes kind by kind, so it
> acts as an equivalence and a pairwise check is enough. Run it on every
> pair of family members after dedup, using libbpf's own function, and
> fail the build if any pair is compatible. A foo___<flavor> with the
> same deduplicated FUNC_PROTO as foo is an alias and is allowed: libbpf
> binds foo first, so the alias is never picked in its place. There is
> only one foo: btf_check_kfunc_name() refuses to register a module kfunc
> named like a function in vmlinux or in another module. Dedup compares
> parameter names too, so an alias has to copy the signature verbatim.
>
> Recognize family members by their bpf_kfunc decl tags rather than by
> the BTF ID sets. The tags are what libbpf filters candidates on, and for
> a module they also cover the vmlinux kfuncs in base BTF, so module
> kfuncs get checked against vmlinux kfuncs of the same family.
>
> The bpf_kfunc_flavor family in bpf_testmod passes: ___v1 differs in
> arity and ___v2 is an alias.
>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
> ---

Acked-by: Eduard Zingerman <eddyz87@xxxxxxxxx>

>  tools/bpf/resolve_btfids/btf_colors.c |  11 +++
>  tools/bpf/resolve_btfids/btf_colors.h |   3 +
>  tools/bpf/resolve_btfids/main.c       | 134 ++++++++++++++++++++++++++
>  3 files changed, 148 insertions(+)
>
> diff --git a/tools/bpf/resolve_btfids/btf_colors.c b/tools/bpf/resolve_btfids/btf_colors.c
> index 5d307d70e7f2..91c10106319e 100644
> --- a/tools/bpf/resolve_btfids/btf_colors.c
> +++ b/tools/bpf/resolve_btfids/btf_colors.c
> @@ -13,6 +13,17 @@ void btf_sha256(const void *data, size_t len,
>   libbpf_sha256(data, len, out);
>  }
>  
> +size_t btf_essential_name_len(const char *name)
> +{
> + return bpf_core_essential_name_len(name);
> +}
> +
> +int btf_types_are_compat(const struct btf *btf1, __u32 id1,
> + const struct btf *btf2, __u32 id2)
> +{
> + return bpf_core_types_are_compat(btf1, id1, btf2, id2);
> +}

Can main.c include bpf/relo_core.h instead of this symbol-laundering scheme?
Or just define two extern prototypes?

...