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>
Cc: bpf@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH bpf-next v2 1/5] libbpf: Walk types in btf_dump_resize(), not in mark_referenced()
Date: Tue, 29 Sep 2026 16:46:04 -0700 [thread overview]
Message-ID: <20260929234608.48503-2-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20260929234608.48503-1-ihor.solodrai@linux.dev>
btf_dump_mark_referenced() both walks every type added since the last
resize and decides what each one references. Move the walk out to
btf_dump_resize() and hand the function one type at a time, so a second
per-type job can share the same pass instead of adding another one.
No functional change.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
---
tools/lib/bpf/btf_dump.c | 122 +++++++++++++++++++--------------------
1 file changed, 60 insertions(+), 62 deletions(-)
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index fa995c02a170..e0293e6d3492 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -143,7 +143,7 @@ static void btf_dump_printf(const struct btf_dump *d, const char *fmt, ...)
va_end(args);
}
-static int btf_dump_mark_referenced(struct btf_dump *d);
+static int btf_dump_mark_referenced(struct btf_dump *d, const struct btf_type *t);
static int btf_dump_resize(struct btf_dump *d);
struct btf_dump *btf_dump__new(const struct btf *btf,
@@ -195,6 +195,8 @@ struct btf_dump *btf_dump__new(const struct btf *btf,
static int btf_dump_resize(struct btf_dump *d)
{
int err, last_id = btf__type_cnt(d->btf) - 1;
+ const struct btf_type *t;
+ __u32 i;
if (last_id <= d->last_id)
return 0;
@@ -212,10 +214,13 @@ static int btf_dump_resize(struct btf_dump *d)
d->type_states[0].emit_state = EMITTED;
}
- /* eagerly determine referenced types for anon enums */
- err = btf_dump_mark_referenced(d);
- if (err)
- return err;
+ for (i = d->last_id + 1; i <= last_id; i++) {
+ t = btf__type_by_id(d->btf, i);
+
+ err = btf_dump_mark_referenced(d, t);
+ if (err)
+ return err;
+ }
d->last_id = last_id;
return 0;
@@ -312,71 +317,64 @@ int btf_dump__dump_type(struct btf_dump *d, __u32 id)
* top-level anonymous enum won't be referenced by anything, while embedded
* one will.
*/
-static int btf_dump_mark_referenced(struct btf_dump *d)
+static int btf_dump_mark_referenced(struct btf_dump *d, const struct btf_type *t)
{
- int i, j, n = btf__type_cnt(d->btf);
- const struct btf_type *t;
- __u32 vlen;
+ __u32 j, vlen = btf_vlen(t);
- for (i = d->last_id + 1; i < n; i++) {
- t = btf__type_by_id(d->btf, i);
- vlen = btf_vlen(t);
-
- switch (btf_kind(t)) {
- case BTF_KIND_INT:
- case BTF_KIND_ENUM:
- case BTF_KIND_ENUM64:
- case BTF_KIND_FWD:
- case BTF_KIND_FLOAT:
- case BTF_KIND_LOC_PARAM:
- case BTF_KIND_LOC_PROTO:
- case BTF_KIND_LOCSEC:
- break;
+ switch (btf_kind(t)) {
+ case BTF_KIND_INT:
+ case BTF_KIND_ENUM:
+ case BTF_KIND_ENUM64:
+ case BTF_KIND_FWD:
+ case BTF_KIND_FLOAT:
+ case BTF_KIND_LOC_PARAM:
+ case BTF_KIND_LOC_PROTO:
+ case BTF_KIND_LOCSEC:
+ break;
- case BTF_KIND_VOLATILE:
- case BTF_KIND_CONST:
- case BTF_KIND_RESTRICT:
- case BTF_KIND_PTR:
- case BTF_KIND_TYPEDEF:
- case BTF_KIND_FUNC:
- case BTF_KIND_VAR:
- case BTF_KIND_DECL_TAG:
- case BTF_KIND_TYPE_TAG:
- d->type_states[t->type].referenced = 1;
- break;
+ case BTF_KIND_VOLATILE:
+ case BTF_KIND_CONST:
+ case BTF_KIND_RESTRICT:
+ case BTF_KIND_PTR:
+ case BTF_KIND_TYPEDEF:
+ case BTF_KIND_FUNC:
+ case BTF_KIND_VAR:
+ case BTF_KIND_DECL_TAG:
+ case BTF_KIND_TYPE_TAG:
+ d->type_states[t->type].referenced = 1;
+ break;
- case BTF_KIND_ARRAY: {
- const struct btf_array *a = btf_array(t);
+ case BTF_KIND_ARRAY: {
+ const struct btf_array *a = btf_array(t);
- d->type_states[a->index_type].referenced = 1;
- d->type_states[a->type].referenced = 1;
- break;
- }
- case BTF_KIND_STRUCT:
- case BTF_KIND_UNION: {
- const struct btf_member *m = btf_members(t);
+ d->type_states[a->index_type].referenced = 1;
+ d->type_states[a->type].referenced = 1;
+ break;
+ }
+ case BTF_KIND_STRUCT:
+ case BTF_KIND_UNION: {
+ const struct btf_member *m = btf_members(t);
- for (j = 0; j < vlen; j++, m++)
- d->type_states[m->type].referenced = 1;
- break;
- }
- case BTF_KIND_FUNC_PROTO: {
- const struct btf_param *p = btf_params(t);
+ for (j = 0; j < vlen; j++, m++)
+ d->type_states[m->type].referenced = 1;
+ break;
+ }
+ case BTF_KIND_FUNC_PROTO: {
+ const struct btf_param *p = btf_params(t);
- for (j = 0; j < vlen; j++, p++)
- d->type_states[p->type].referenced = 1;
- break;
- }
- case BTF_KIND_DATASEC: {
- const struct btf_var_secinfo *v = btf_var_secinfos(t);
+ for (j = 0; j < vlen; j++, p++)
+ d->type_states[p->type].referenced = 1;
+ break;
+ }
+ case BTF_KIND_DATASEC: {
+ const struct btf_var_secinfo *v = btf_var_secinfos(t);
- for (j = 0; j < vlen; j++, v++)
- d->type_states[v->type].referenced = 1;
- break;
- }
- default:
- return -EINVAL;
- }
+ for (j = 0; j < vlen; j++, v++)
+ d->type_states[v->type].referenced = 1;
+ break;
+ }
+ default:
+ return -EINVAL;
}
return 0;
}
--
2.50.1
next prev parent reply other threads:[~2026-09-29 23:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 23:46 [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump Ihor Solodrai
2026-09-29 23:46 ` Ihor Solodrai [this message]
2026-09-29 23:46 ` [PATCH bpf-next v2 2/5] " Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 3/5] selftests/bpf: Add ASSERT_TEXT_EQ() Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 4/5] selftests/bpf: Test btf_dump rendering of decl_tags Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 5/5] selftests/bpf: Show the tag kflag in the raw BTF dump helper Ihor Solodrai
2026-09-30 9:10 ` [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump 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=20260929234608.48503-2-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 \
/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