mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v3 3/6] libbpf: Resolve kfunc variants by prototype
Date: Tue, 24 Nov 2026 23:40:10 +0000 (UTC)	[thread overview]
Message-ID: <bdaa5b918a0e59230fcce839fea102b598efeb3a65de54f668c15f29573370df@mail.kernel.org> (raw)
In-Reply-To: <20261124224811.16134-4-ihor.solodrai@linux.dev>

[-- Attachment #1: Type: text/plain, Size: 3345 bytes --]

> libbpf: Resolve kfunc variants by prototype

TL;DR: The stricter struct-name check in libbpf kfunc resolution may make
programs using UAPI aliases (e.g. struct __sk_buff in bpf_dynptr_from_skb)
fail to load with -EINVAL on v6.3-v6.10 kernels.

> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c

[ ... ]

> +static int kfunc_type_match(const struct btf *a, __u32 a_id,
> +			    const struct btf *b, __u32 b_id, int depth)
> +{

[ ... ]

> +	switch (kind) {
> +	case BTF_KIND_STRUCT:
> +	case BTF_KIND_UNION: {
> +		const char *an = btf__name_by_offset(a, at->name_off);
> +		const char *bn = btf__name_by_offset(b, bt->name_off);
> +		size_t name_len = bpf_core_essential_name_len(an);
> +
> +		return name_len == bpf_core_essential_name_len(bn) &&
> +		       strncmp(an, bn, name_len) == 0;
> +	}

Can this break loading of existing programs on older kernels?  Before this
patch, bpf_object__resolve_ksym_func_btf_id() used
bpf_core_types_are_compat(), which treats any two structs as compatible
without comparing names.

Until commit cce4c40b9606 ("bpf: treewide: Align kfunc signatures to
prog point-of-view"), several kfuncs were defined with kernel-facing
types, while BPF programs declared them with UAPI types:

  -__bpf_kfunc int bpf_dynptr_from_skb(struct sk_buff *skb, u64 flags,
  -__bpf_kfunc int bpf_dynptr_from_xdp(struct xdp_buff *xdp, u64 flags,
  -__bpf_kfunc int bpf_dynptr_adjust(struct bpf_dynptr_kern *ptr, u32 start, u32 end)
  -__bpf_kfunc int bpf_verify_pkcs7_signature(struct bpf_dynptr_kern *data_ptr,

and tools/testing/selftests/bpf/bpf_kfuncs.h still has:

  extern int bpf_dynptr_from_skb(struct __sk_buff *skb, __u64 flags,
                                 struct bpf_dynptr *ptr__uninit) __ksym;

The commit message of cce4c40b9606 says "It wasn't an issue before, as the
verifier allows aliased types."  A vmlinux.h generated on v6.11 or later
declares them the same way.

On a v6.3 to v6.10 kernel, this now goes:

  bpf_object__resolve_ksym_func_btf_id()
    -> find_kfunc_btf_id(): one candidate, bpf_dynptr_from_skb
    -> btf_kfunc_proto_match() -> kfunc_type_match(FUNC_PROTO)
       -> param 0: PTR -> STRUCT "__sk_buff" vs STRUCT "sk_buff"
          essential name lengths 9 != 7 -> return 0
    -> nr_cands == 1, kfunc_id == 0 -> return -EINVAL

so bpf_object__load() fails with -EINVAL, where the old code resolved the
same declaration on the same kernel.  For a __weak declaration the kfunc
now stays unresolved silently, so bpf_ksym_exists() is false on kernels
that do provide the kfunc.

The commit message says "a declaration with an outdated struct name no
longer resolves" and uses bpf_cpumask_populate() as the example.  There the
kernel changed which type it accepts.  Here the declaration is not
outdated: it uses the UAPI alias that the verifier accepts on those kernels.

Nothing later in the series (ea0b8db17e5e, 7848a838c614, 88fb7cd2ca9c)
seems to handle these aliases.  Will existing binaries that load today on
still-supported LTS kernels start failing after a libbpf upgrade?


---
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/45506767613

  reply	other threads:[~2026-11-24 23:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 22:48 [PATCH bpf-next v3 0/6] libbpf: Support kernel-side kfunc variants Ihor Solodrai
2026-11-24 22:48 ` [PATCH bpf-next v3 1/6] libbpf: Separate interfaces shared with in-tree tools Ihor Solodrai
2026-11-24 22:50   ` Ihor Solodrai
2026-11-24 22:53     ` Andrii Nakryiko
2026-11-24 23:40   ` bot+bpf-ci
2026-11-24 22:48 ` [PATCH bpf-next v3 2/6] sched_ext: Prefer ___v2 kfunc names in compat.bpf.h Ihor Solodrai
2026-11-24 22:48 ` [PATCH bpf-next v3 3/6] libbpf: Resolve kfunc variants by prototype Ihor Solodrai
2026-11-24 23:40   ` bot+bpf-ci [this message]
2026-11-24 22:48 ` [PATCH bpf-next v3 4/6] selftests/bpf: Test kfunc variant selection " Ihor Solodrai
2026-11-24 22:48 ` [PATCH bpf-next v3 5/6] resolve_btfids: Reject ambiguous kfunc variants Ihor Solodrai
2026-11-24 22:48 ` [PATCH bpf-next v3 6/6] docs/bpf: Describe how to change a kfunc's prototype Ihor Solodrai

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=bdaa5b918a0e59230fcce839fea102b598efeb3a65de54f668c15f29573370df@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®