From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Haowen Deng" <denghaowen59@gmail.com>, <bpf@vger.kernel.org>
Cc: linux-kselftest@vger.kernel.org,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Shuah Khan" <shuah@kernel.org>,
"Daniel Müller" <deso@posteo.net>
Subject: Re: [PATCH bpf] libbpf: Ignore integer type names in CO-RE type matching
Date: Fri, 04 Dec 2026 04:07:38 +0000 [thread overview]
Message-ID: <DNBNI47GL7FY.2DWVKH64AY4SL@gmail.com> (raw)
In-Reply-To: <20261202141620.366-1-denghaowen59@gmail.com>
On Wed, Dec 02, 2026 at 06:16 AM Haowen Deng <denghaowen59@gmail.com> wrote:
> Skip the integer name comparison and use the existing size and
> signedness checks. Add a BPF selftest that checks differently named
> integer parameters and verifies that a change in size or signedness
> still prevents a match.
That's not enough for char.
The kernel uses -funsigned-char since
commit 3bc753c06dd0 ("kbuild: treat char as always unsigned").
char is signed in bpf progs.
So local_sgn is 1, targ_sgn is 0 and this line returns 0:
return local_t->size == targ_t->size && local_sgn == targ_sgn;
prog type vmlinux type today patch
-------------- ------------------ ----- -----
unsigned short short unsigned int 0 1
char char 0 0
bool char 0 1
'char comm[16]' and 'const char *' args still don't match.
Same for trace_event_raw_* from vmlinux.h. They end with 'char __data[]'.
Same name and size is the same C type. Lets ignore the sign in that case.
> +static void test_integer_type_names(void)
> +{
No need for 47 lines that call libbpf internals.
With the fix the existing cases check the size and the sign.
a_struct___diff_sz is int vs long. int_typedef___diff is int vs unsigned.
Two lines in the existing progs cover the rest.
With these two lines I expect this from reading the code:
subtest today patch patch + diff
----------------- ----- ----- ------------
type_based___diff FAIL OK OK
kernel FAIL FAIL OK
The diff is on top of your patch. relo_core.c and both progs compile.
diff --git a/Documentation/bpf/llvm_reloc.rst b/Documentation/bpf/llvm_reloc.rst
index 44188e2..c420980 100644
--- a/Documentation/bpf/llvm_reloc.rst
+++ b/Documentation/bpf/llvm_reloc.rst
@@ -323,7 +323,8 @@ Notes:
* The ``BPF_CORE_TYPE_MATCHES`` queries matching relation, defined as
follows:
- * for integers: types match if size and signedness match;
+ * for integers: types match if size and signedness match, ``char`` matches
+ ``char`` of any signedness;
* for arrays & pointers: target types are recursively matched;
* for structs & unions:
diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index 9d81688..9c287cd 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/relo_core.c
@@ -1548,6 +1548,7 @@ static int bpf_core_composites_match(const struct btf *local_btf, const struct b
* Then, depending on type:
* - integers:
* - match if size and signedness match
+ * - char matches char of any signedness
* - arrays & pointers:
* - target types are recursively matched
* - structs & unions:
@@ -1654,7 +1655,13 @@ recur:
local_sgn = btf_int_encoding(local_t) & BTF_INT_SIGNED;
targ_sgn = btf_int_encoding(targ_t) & BTF_INT_SIGNED;
- return local_t->size == targ_t->size && local_sgn == targ_sgn;
+ if (local_t->size != targ_t->size)
+ return 0;
+
+ /* signedness of plain char depends on compiler flags */
+ return local_sgn == targ_sgn ||
+ bpf_core_names_match(local_btf, local_t->name_off,
+ targ_btf, targ_t->name_off);
}
case BTF_KIND_PTR:
if (local_k != targ_k)
diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
index a6690a3..80432c4 100644
--- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
@@ -7,7 +7,6 @@
#include <sys/mman.h>
#include <sys/syscall.h>
#include <bpf/btf.h>
-#include "bpf/relo_core.h"
#include "bpftool_helpers.h"
static int duration = 0;
@@ -1148,54 +1147,8 @@ cleanup:
}
}
-static void test_integer_type_names(void)
-{
- static const struct {
- const char *label;
- int size;
- int encoding;
- int expected;
- } cases[] = {
- { "same_size_and_signedness", 2, 0, 1 },
- { "different_size", 4, 0, 0 },
- { "different_signedness", 2, BTF_INT_SIGNED, 0 },
- };
- int i, local_int, local_proto, targ_int, targ_proto;
- struct btf *btf;
-
- btf = btf__new_empty();
- if (!ASSERT_OK_PTR(btf, "btf_new"))
- return;
-
- local_int = btf__add_int(btf, "unsigned short", 2, 0);
- if (!ASSERT_GT(local_int, 0, "local_int"))
- goto out;
- local_proto = btf__add_func_proto(btf, 0);
- if (!ASSERT_GT(local_proto, 0, "local_proto") ||
- !ASSERT_OK(btf__add_func_param(btf, "mode", local_int), "local_param"))
- goto out;
-
- for (i = 0; i < ARRAY_SIZE(cases); i++) {
- targ_int = btf__add_int(btf, "short unsigned int", cases[i].size,
- cases[i].encoding);
- if (!ASSERT_GT(targ_int, 0, "targ_int"))
- goto out;
- targ_proto = btf__add_func_proto(btf, 0);
- if (!ASSERT_GT(targ_proto, 0, "targ_proto") ||
- !ASSERT_OK(btf__add_func_param(btf, "mode", targ_int), "targ_param"))
- goto out;
-
- ASSERT_EQ(bpf_core_types_match(btf, local_proto, btf, targ_proto),
- cases[i].expected, cases[i].label);
- }
-out:
- btf__free(btf);
-}
-
void test_core_reloc(void)
{
- if (test__start_subtest("integer_type_names"))
- test_integer_type_names();
run_core_reloc_tests(false);
}
diff --git a/tools/testing/selftests/bpf/progs/core_reloc_types.h b/tools/testing/selftests/bpf/progs/core_reloc_types.h
index 5760ae0..db768b9 100644
--- a/tools/testing/selftests/bpf/progs/core_reloc_types.h
+++ b/tools/testing/selftests/bpf/progs/core_reloc_types.h
@@ -990,7 +990,7 @@ struct a_complex_struct___diff {
struct a_struct___forward *a;
void *b;
} x;
- volatile long y;
+ volatile long long y;
};
union a_union___diff {
diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c b/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c
index ee4a601..31e6f4b 100644
--- a/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c
+++ b/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c
@@ -37,6 +37,7 @@ struct mm_struct___wrong {
struct task_struct___local {
int pid;
+ char comm[16];
struct mm_struct___wrong *mm;
};
Also say in the commit log that bool now matches u8
and long matches long long.
Pls split libbpf and selftests changes and target bpf-next.
pw-bot: cr
prev parent reply other threads:[~2026-12-04 4:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 14:16 [PATCH bpf] libbpf: Ignore integer type names in CO-RE type matching Haowen Deng
2026-12-04 4:07 ` Alexei Starovoitov [this message]
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=DNBNI47GL7FY.2DWVKH64AY4SL@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=denghaowen59@gmail.com \
--cc=deso@posteo.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox