From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Quentin Monnet <qmo@kernel.org>
Cc: bpf@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: [PATCH bpf-next v1 3/3] bpftool: Replace the type tag override table with two checks
Date: Fri, 6 Nov 2026 12:57:30 -0700 [thread overview]
Message-ID: <20261106195730.2623973-3-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20261106195730.2623973-1-ihor.solodrai@linux.dev>
btf_c_annotate_type_tags() looks each type tag up in a table of
overrides. The table holds two fixed cases, the "address_space(1)"
string of older kernel BTF and the plain "arena" tag, and is not
expected to grow.
Check for the two tags directly and drop the table.
No functional change.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/CAEf4BzbpVnoqKnGAVKYRffraPpPWjnNFF2oFAnXmBkqd2V6vmg@mail.gmail.com/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
tools/bpf/bpftool/btf.c | 33 ++++++++++++---------------------
1 file changed, 12 insertions(+), 21 deletions(-)
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index c06b01f2c5b3..c51c2efde3ed 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -1096,38 +1096,29 @@ static struct sort_datum *sort_btf_c(const struct btf *btf)
* Kernel BTF keeps its type tags as the kernel expects them. Decl tags in
* the dump split choose how btf_dump prints them.
*/
-static const struct {
- bool kflag;
- const char *name;
- const char *override;
-} btf_c_type_tags[] = {
- /* the arena attribute in older kernel BTF */
- { true, "address_space(1)", "__attribute__((address_space(1)))" },
- /* __arena in include/linux/bpf_compiler_types.h */
- { false, "arena", "__bpf_arena" },
-};
-
static int btf_c_annotate_type_tags(struct btf *btf)
{
__u32 i, cnt = btf__type_cnt(btf);
- size_t j;
int err;
for (i = 1; i < cnt; i++) {
const struct btf_type *t = btf__type_by_id(btf, i);
- const char *name;
+ const char *name, *attr;
if (!btf_is_type_tag(t))
continue;
name = btf__name_by_offset(btf, t->name_off);
- for (j = 0; j < ARRAY_SIZE(btf_c_type_tags); j++) {
- if (btf_kflag(t) != btf_c_type_tags[j].kflag ||
- strcmp(name, btf_c_type_tags[j].name))
- continue;
- err = btf__add_decl_attr(btf, btf_c_type_tags[j].override, i, -1);
- if (err < 0)
- return err;
- }
+ if (btf_kflag(t) && !strcmp(name, "address_space(1)"))
+ /* the arena attribute in older kernel BTF */
+ attr = "__attribute__((address_space(1)))";
+ else if (!btf_kflag(t) && !strcmp(name, "arena"))
+ /* __arena in include/linux/bpf_compiler_types.h */
+ attr = "__bpf_arena";
+ else
+ continue;
+ err = btf__add_decl_attr(btf, attr, i, -1);
+ if (err < 0)
+ return err;
}
return 0;
--
2.56.0
next prev parent reply other threads:[~2026-11-06 19:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 19:57 [PATCH bpf-next v1 1/3] Revert "libbpf: Fix use-after-free in btf__add_type" Ihor Solodrai
2026-11-06 19:57 ` [PATCH bpf-next v1 2/3] libbpf: Drop btf_dump details from the BTF docs Ihor Solodrai
2026-11-06 19:57 ` Ihor Solodrai [this message]
2026-11-07 0:50 ` [PATCH bpf-next v1 1/3] Revert "libbpf: Fix use-after-free in btf__add_type" patchwork-bot+netdevbpf
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=20261106195730.2623973-3-ihor.solodrai@linux.dev \
--to=ihor.solodrai@linux.dev \
--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=memxor@gmail.com \
--cc=qmo@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.