From: Alan Maguire <alan.maguire@oracle.com>
To: bot+bpf-ci@kernel.org, andrii@kernel.org
Cc: ast@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, john.fastabend@gmail.com, kpsingh@kernel.org,
sdf@fomichev.me, haoluo@google.com, nilay@linux.ibm.com,
bvanassche@acm.org, bpf@vger.kernel.org, martin.lau@kernel.org,
clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf] libbpf: BTF dedup should ignore modifiers in type equivalence checks
Date: Fri, 9 Jan 2026 12:24:33 +0000 [thread overview]
Message-ID: <e2019eca-e360-41c4-b582-ff7c3704c854@oracle.com> (raw)
In-Reply-To: <30e36e721900df2580a112faeba7c725911347d2bc925656d241a7a42d754727@mail.kernel.org>
On 09/01/2026 10:33, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
>> index 84a4b0abc8be..8ef0354e66cc 100644
>> --- a/tools/lib/bpf/btf.c
>> +++ b/tools/lib/bpf/btf.c
>
> [ ... ]
>
>> @@ -4688,7 +4686,24 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
>> return fwd_kind == real_kind;
>> }
>>
>> - if (cand_kind != canon_kind)
>> + /*
>> + * Types are considered equivalent if modifiers (const, volatile,
>> + * restrict) are present for one but not the other.
>> + */
>> + if (cand_kind != canon_kind) {
>> + __u32 next_cand_id = cand_id;
>> + __u32 next_canon_id = canon_id;
>> +
>> + if (btf_is_mod(cand_type) && !btf_is_type_tag(cand_type))
>> + next_cand_id = cand_type->type;
>> + if (btf_is_mod(canon_type) && !btf_is_type_tag(canon_type))
>> + next_canon_id = canon_type->type;
>> + if (cand_id == next_cand_id && canon_id == next_canon_id)
>> + return 0;
>> + return btf_dedup_is_equiv(d, next_cand_id, next_canon_id);
>> + }
>
> Can this recursive call fail when there are multiple levels of modifiers?
>
> Consider comparing "volatile const int" (cand_id=20) against "int" (canon_id=5):
>
> 1. The first call adds hypot_map[5] = 20 via btf_dedup_hypot_map_add()
> earlier in btf_dedup_is_equiv() before the kinds are checked.
>
> 2. btf_is_mod(VOLATILE) is true, so next_cand_id becomes the underlying
> "const int" (ID=15), while next_canon_id stays at 5 since INT is not
> a modifier.
>
> 3. The recursive call btf_dedup_is_equiv(d, 15, 5) is made.
>
> 4. In the recursive call, hypot_map[5] is already set to 20 (from step 1).
> Since 20 != 15, the code falls through to btf_dedup_identical_types().
>
> 5. btf_dedup_identical_types(d, 20, 15) compares VOLATILE vs CONST kinds,
> which differ, so it returns false.
>
> 6. The function returns 0, incorrectly reporting the types as not equivalent.
>
> This appears to break the intended behavior for types with nested modifiers
> like "volatile const X" vs "X", even though single modifiers like
> "volatile X" vs "X" would work correctly (because next_cand_id and
> next_canon_id would both resolve to the same underlying type).
>
>
The above is all true, but I _think_ it neglects an aspect of deduplication;
that it is symmetric; i.e. in one case a type id is canonical, and in another
it is a candidate. So for the above case, consider what happens when
cand_id=5 ("int") and canon_id=20 ("volatile const int"):
1. we add hypot_map[20] = 5 (i.e hypot_map["volatile const int"] = "int";
2. btf_is_mod(VOLATILE) is true so we recurse to btf_dedup_is_equiv(d, 5, 15)
(where 15 is "const int")
3. hypot_map[15] is not set so we do equivalence checking and recurse to
btf_dedup_is_equiv(d, 5, 5) ("int") and return 1.
4. As a result the original hypot_map["volatile const int"] = "int" is
verified.
So unless I'm missing something we end up deduplicating successfully in
this case, but the deduplication is weighted towards making the more complex
type canonical. That's what we want I think since these equivalence checks
will be just used to validate struct/union equivalence.
> ---
> 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/20848783658
next prev parent reply other threads:[~2026-01-09 12:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 10:13 [PATCH bpf] libbpf: BTF dedup should ignore modifiers in type equivalence checks Alan Maguire
2026-01-09 10:33 ` bot+bpf-ci
2026-01-09 12:24 ` Alan Maguire [this message]
2026-01-09 16:28 ` Yonghong Song
2026-01-09 17:28 ` Andrii Nakryiko
2026-01-10 14:05 ` Alan Maguire
2026-01-13 21:48 ` Andrii Nakryiko
2026-01-14 18:41 ` Alan Maguire
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=e2019eca-e360-41c4-b582-ff7c3704c854@oracle.com \
--to=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=bvanassche@acm.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=nilay@linux.ibm.com \
--cc=sdf@fomichev.me \
--cc=song@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.