From: bot+bpf-ci@kernel.org
To: ihor.solodrai@linux.dev,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,eddyz87@gmail.com,memxor@gmail.com
Cc: alan.maguire@oracle.com,emil@etsalapatis.com,jolsa@kernel.org,song@kernel.org,tj@kernel.org,yonghong.song@linux.dev,bpf@vger.kernel.org,linux-kernel@vger.kernel.org,sched-ext@lists.linux.dev,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 3/6] libbpf: Resolve kfunc variants by prototype
Date: Sat, 21 Nov 2026 01:14:01 +0000 (UTC) [thread overview]
Message-ID: <fbfaa7de60fbbd5b5c495fed0005daa700d1da496bf37c6a7d86f443493b8a89@mail.kernel.org> (raw)
In-Reply-To: <20261121003403.2928928-4-ihor.solodrai@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 2869 bytes --]
> libbpf: Resolve kfunc variants by prototype
TL;DR: A module BTF load error in find_kfunc_btf_id() may be returned as
-EINVAL and mistaken for "no compatible prototype", so a weak kfunc in vmlinux
could be treated as missing and strong ones get a misleading error.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> +/*
> + * Search vmlinux and module BTFs. Return:
> + * - a BTF ID for a unique match;
> + * - -ESRCH if the family is absent;
> + * - -EINVAL if no candidate has a compatible prototype;
> + * - -ENOTUNIQ if more than one candidate has a compatible prototype;
> + * - another negative error on failure.
> + */
> +static int find_kfunc_btf_id(struct bpf_object *obj, const struct extern_desc *ext,
> + struct btf **res_btf, struct module_btf **res_mod_btf)
> +{
> + size_t name_len = bpf_core_essential_name_len(ext->name);
> + int kfunc_id = 0, nr_cands = 0, err;
> + size_t i;
> +
> + err = load_module_btfs(obj);
> + if (err)
> + return err;
Can this return -EINVAL for a reason other than a prototype mismatch?
load_module_btfs() calls btf_get_from_fd(), which goes through btf_new()
and can return -EINVAL from btf_parse_hdr(), btf_parse_type_sec() or
btf_sanity_check() when libbpf rejects a module's BTF. That error is
returned here unchanged.
[ ... ]
> + if (kfunc_id == -EINVAL) {
> if (ext->is_weak)
> return 0;
> + pr_warn("extern (func ksym) '%s': no compatible prototype in kernel or module BTFs\n",
> + ext->name);
> + return kfunc_id;
> }
bpf_object__resolve_ksym_func_btf_id() treats that -EINVAL as "no
compatible prototype". A __weak kfunc is then left unresolved even if it
exists in vmlinux, so bpf_ksym_exists() reports it as missing. A strong
kfunc fails with the misleading "no compatible prototype" message.
Also, load_module_btfs() has already set obj->btf_modules_loaded = true by
then, so later kfuncs and the CO-RE lookups in bpf_core_find_cands() would
continue with a partial module list instead of failing the load.
Before this patch, a kfunc found in vmlinux never called
load_module_btfs(). When the lookup did reach it, find_ksym_btf_id()
returned the error as is, and only -ESRCH was treated as absence.
Other errors from load_module_btfs() (-ENOMEM, errors from the BTF
syscalls) also return here without a message naming the extern, because
the generic "if (kfunc_id < 0) return kfunc_id;" path prints nothing.
Would it make sense to call load_module_btfs() in the caller, or to keep
its error apart from the -ESRCH/-EINVAL/-ENOTUNIQ results?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44845964556
next prev parent reply other threads:[~2026-11-21 1:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 0:33 [PATCH bpf-next v2 0/6] libbpf: Support kernel-side kfunc variants Ihor Solodrai
2026-11-21 0:33 ` [PATCH bpf-next v2 1/6] libbpf: Separate interfaces shared with in-tree tools Ihor Solodrai
2026-11-21 0:33 ` [PATCH bpf-next v2 2/6] sched_ext: Prefer ___v2 kfunc names in compat.bpf.h Ihor Solodrai
2026-11-21 1:13 ` bot+bpf-ci
2026-11-21 0:34 ` [PATCH bpf-next v2 3/6] libbpf: Resolve kfunc variants by prototype Ihor Solodrai
2026-11-21 1:14 ` bot+bpf-ci [this message]
2026-11-21 0:34 ` [PATCH bpf-next v2 4/6] selftests/bpf: Test kfunc variant selection " Ihor Solodrai
2026-11-21 0:34 ` [PATCH bpf-next v2 5/6] resolve_btfids: Reject ambiguous kfunc variants Ihor Solodrai
2026-11-21 0:34 ` [PATCH bpf-next v2 6/6] docs/bpf: Describe how to change a kfunc's prototype Ihor Solodrai
2026-11-21 0:58 ` bot+bpf-ci
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=fbfaa7de60fbbd5b5c495fed0005daa700d1da496bf37c6a7d86f443493b8a89@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=mason@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®