From: Quentin Monnet <qmo@kernel.org>
To: Tianyi Chen <hi@tychen.cc>, bpf@vger.kernel.org
Cc: andrii@kernel.org, eddyz87@gmail.com, ihor.solodrai@linux.dev,
linux-kselftest@vger.kernel.org, skokovmaksimevg@gmail.com
Subject: Re: [PATCH bpf-next v9 1/2] bpftool: Add recursive map dumping
Date: Mon, 28 Sep 2026 16:25:42 +0100 [thread overview]
Message-ID: <3acbe829-06f0-4df4-b57c-a8c7b802ec96@kernel.org> (raw)
In-Reply-To: <20260926014208.24773-2-hi@tychen.cc>
2026-09-26 10:42 UTC+0900 ~ Tianyi Chen <hi@tychen.cc>
> Dumping a map-of-maps currently shows inner map IDs without their
> contents. Add a recursive keyword to map dump to include referenced
> inner maps, leaving the default output unchanged. Show selected maps
> followed by distinct inner maps, preserving plain and BTF formatting
> and using an array of map objects for JSON output.
>
> Holding every discovered inner-map FD open would make descriptor use
> grow with the number of maps and could exhaust RLIMIT_NOFILE. Keep the
> selected map FDs open, queue distinct inner map IDs, and open, dump and
> close each queued map in turn. This needs only one additional map FD.
> The tradeoff is deferred ID resolution: concurrently removed inner
> maps can disappear before they are opened, so the dump is not atomic.
>
> Report failure when an inner map cannot be opened, retain per-entry
> lookup errors, and close JSON containers before returning.
>
> Link: https://github.com/libbpf/bpftool/issues/58
> Assisted-by: LLM
> Signed-off-by: Tianyi Chen <hi@tychen.cc>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 626882f2079e..015910a493db 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -971,30 +1066,61 @@ static int do_dump(int argc, char **argv)
> }
> }
>
> - if (wtr && nb_fds > 1)
> + if (wtr && (nb_fds > 1 || recursive_dump))
> jsonw_start_array(wtr); /* root array */
> for (i = 0; i < nb_fds; i++) {
> + memset(&info, 0, sizeof(info));
> + len = sizeof(info);
Good catch, reading bpf-ci's review the other day I didn't realise there
were other locations in the file where we omitted to reset "info", which
means we may print wrong BTF info when dumping the maps, that's a bug.
I can see three other locations (do_show(), do_show_subset(),
maps_have_btf()) where we call bpf_map_get_info_by_fd() in loops without
resetting "info". We'll need to fix these, but this should be a
different patch or series. You're welcome to go at it if you want, I'll
send a patch otherwise, just let me know. I would maybe move this
memset() (the hunk above) to that dedicated patch.
This patch looks good to me otherwise:
Acked-by: Quentin Monnet <qmo@kernel.org>
You still have a conflict with Maxim's series on patch 2 though, both of
you picked the same test file name. Maybe use
bpftool_map_dump_recursive.c instead?
Thanks,
Quentin
next prev parent reply other threads:[~2026-09-28 15:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 1:42 [PATCH bpf-next v9 0/2] bpftool: Add recursive map dumping Tianyi Chen
2026-09-26 1:42 ` [PATCH bpf-next v9 1/2] " Tianyi Chen
2026-09-28 15:25 ` Quentin Monnet [this message]
2026-09-28 17:19 ` Tianyi Chen
2026-09-26 1:42 ` [PATCH bpf-next v9 2/2] selftests/bpf: Cover recursive bpftool map dumps Tianyi Chen
[not found] ` <effbbc956dbdf4c78d27608f6ef8639908323d0aaabf80e1cd592cccac938c99@mail.kernel.org>
2026-09-26 6:08 ` [PATCH bpf-next v9 0/2] bpftool: Add recursive map dumping Tianyi Chen
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=3acbe829-06f0-4df4-b57c-a8c7b802ec96@kernel.org \
--to=qmo@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=hi@tychen.cc \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kselftest@vger.kernel.org \
--cc=skokovmaksimevg@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