From: Eduard Zingerman <eddyz87@gmail.com>
To: Ihor Solodrai <ihor.solodrai@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Alan Maguire <alan.maguire@oracle.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Jiri Olsa <jolsa@kernel.org>, Song Liu <song@kernel.org>,
Tejun Heo <tj@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
sched-ext@lists.linux.dev
Subject: Re: [PATCH bpf-next v1 1/4] libbpf: Fall back to kernel ___ flavors when resolving kfuncs
Date: Wed, 18 Nov 2026 15:44:31 -0700 [thread overview]
Message-ID: <9e6ac7882314fdb1215dcebff1c35db72380ad0c.camel@gmail.com> (raw)
In-Reply-To: <20261117192153.3384031-2-ihor.solodrai@linux.dev>
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;
...
next prev parent reply other threads:[~2026-11-18 22:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 19:21 [PATCH bpf-next v1 0/4] libbpf: Support kernel-side kfunc flavors Ihor Solodrai
2026-11-17 19:21 ` [PATCH bpf-next v1 1/4] libbpf: Fall back to kernel ___ flavors when resolving kfuncs Ihor Solodrai
2026-11-18 22:44 ` Eduard Zingerman [this message]
2026-11-17 19:21 ` [PATCH bpf-next v1 2/4] selftests/bpf: Test kfunc flavor resolution Ihor Solodrai
2026-11-17 19:21 ` [PATCH bpf-next v1 3/4] resolve_btfids: Reject kfunc families that libbpf can't disambiguate Ihor Solodrai
2026-11-18 22:59 ` Eduard Zingerman
2026-11-17 19:21 ` [PATCH bpf-next v1 4/4] docs/bpf: Describe how to change a kfunc's prototype Ihor Solodrai
2026-11-17 20:53 ` [PATCH bpf-next v1 0/4] libbpf: Support kernel-side kfunc flavors Tejun Heo
2026-11-18 21:12 ` Eduard Zingerman
2026-11-18 21:37 ` Ihor Solodrai
2026-11-18 22:11 ` Eduard Zingerman
2026-11-18 23:13 ` Ihor Solodrai
2026-11-18 21:42 ` Eduard Zingerman
2026-11-18 21:48 ` Ihor Solodrai
2026-11-18 21:57 ` Eduard Zingerman
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=9e6ac7882314fdb1215dcebff1c35db72380ad0c.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=memxor@gmail.com \
--cc=sched-ext@lists.linux.dev \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®