Re: [PATCH bpf-next v1 1/4] libbpf: Fall back to kernel ___ flavors when resolving kfuncs
From: Eduard Zingerman
Date: Wed Nov 18 2026 - 17:44:39 EST
On Tue, 2026-11-17 at 12:21 -0700, Ihor Solodrai wrote:
...
> +/* id is a kfunc named <name>___<flavor>, where len is strlen(name) */
> +static bool btf_is_kfunc_flavor(const struct btf *btf, int id, const char *name, size_t len)
> +{
> + const struct btf_type *t = btf__type_by_id(btf, id);
> + const char *kname;
> +
> + if (!btf_is_func(t))
> + return false;
> + kname = btf__name_by_offset(btf, t->name_off);
> + if (strncmp(kname, name, len) != 0)
> + return false;
> + /* kname is <name> itself, already tried by the exact lookup */
> + if (kname[len] == '\0')
> + return false;
> + if (bpf_core_essential_name_len(kname) != len)
> + return false;
> + return btf_is_kfunc(btf, id);
> +}
Why is `btf_is_kfunc` filter necessary?
As far as I understand, main kfunc resolution logic does not check for it.
Having different rules for exact name matches and for flavoured matches
seem to be inconsistent for no good reason.
...
> @@ -9526,6 +9650,17 @@ static int bpf_object__resolve_ksym_func_btf_id(struct bpf_object *obj,
>
> kfunc_id = find_ksym_btf_id(obj, ext->essent_name ?: ext->name, BTF_KIND_FUNC, &kern_btf,
> &mod_btf);
> + if (need_kfunc_flavor(obj, ext, kern_btf, kfunc_id)) {
> + ret = find_kfunc_flavor_btf_id(obj, ext, &kern_btf, &mod_btf);
> + if (ret == -ENOTUNIQ) {
> + /* an error even if declared __weak: ambiguity isn't absence */
> + pr_warn("extern (func ksym) '%s': more than one compatible kfunc flavor\n",
> + ext->name);
> + return ret;
> + }
> + if (ret && ret != -ESRCH)
> + kfunc_id = ret;
> + }
Idk, I don't like that this is implemented as a special case:
- Check exact name match first.
- Check flavours in a separate loop.
It appears that having a single loop looking for name candidates is a
bit better from code structuring point of view.
> if (kfunc_id < 0) {
> if (kfunc_id == -ESRCH && ext->is_weak)
> return 0;
...