From: "Emil Tsalapatis" <emil@etsalapatis.com>
To: "Yichong Chen" <chenyichong@uniontech.com>, <qmo@kernel.org>,
<ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>,
<eddyz87@gmail.com>, <memxor@gmail.com>
Cc: <martin.lau@linux.dev>, <song@kernel.org>,
<yonghong.song@linux.dev>, <jolsa@kernel.org>,
<jiayuan.chen@linux.dev>, <bpf@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] tools/bpf/bpftool: Reset vmlinux BTF after map commands
Date: Tue, 23 Jun 2026 17:44:02 -0400 [thread overview]
Message-ID: <DJGR9M02WSP5.2SJ91UABVUWAQ@etsalapatis.com> (raw)
In-Reply-To: <E2D0E58A0333B7F3+20260623072220.1421837-2-chenyichong@uniontech.com>
On Tue Jun 23, 2026 at 3:22 AM EDT, Yichong Chen wrote:
> get_map_kv_btf() caches the vmlinux BTF object when a map uses
> btf_vmlinux_value_type_id. map dump released that object when the
> command completed, but left the global pointer stale.
>
> The same cached object can also be returned to print_key_value(), which
> freed it directly. That leaves btf_vmlinux dangling before the command
> cleanup path runs.
>
> Use free_map_kv_btf() for per-entry cleanup, and reset the cached
> btf_vmlinux pointer when the map command releases the object. This keeps
> batch mode from reusing a freed BTF object.
>
> Fixes: 4e1ea33292ff ("bpftool: Support dumping a map with btf_vmlinux_value_type_id")
> Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
> ---
> tools/bpf/bpftool/map.c | 12 +++++++++---
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 7ebf7dbcfba4..a265ad3afbb0 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -790,6 +790,12 @@ static int maps_have_btf(int *fds, int nb_fds)
>
> static struct btf *btf_vmlinux;
>
> +static void free_btf_vmlinux(void)
> +{
> + btf__free(btf_vmlinux);
> + btf_vmlinux = NULL;
> +}
> +
> static int get_map_kv_btf(const struct bpf_map_info *info, struct btf **btf)
> {
> int err = 0;
> @@ -958,7 +964,7 @@ static int do_dump(int argc, char **argv)
> close(fds[i]);
> exit_free:
> free(fds);
> - btf__free(btf_vmlinux);
> + free_btf_vmlinux();
> return err;
> }
>
> @@ -1049,7 +1055,7 @@ static void print_key_value(struct bpf_map_info *info, void *key,
> btf_wtr = get_btf_writer();
> if (!btf_wtr) {
> p_info("failed to create json writer for btf. falling back to plain output");
> - btf__free(btf);
> + free_map_kv_btf(btf);
> btf = NULL;
> print_entry_plain(info, key, value);
> } else {
> @@ -1065,7 +1071,7 @@ static void print_key_value(struct bpf_map_info *info, void *key,
> } else {
> print_entry_plain(info, key, value);
> }
> - btf__free(btf);
> + free_map_kv_btf(btf);
> }
>
> static int do_lookup(int argc, char **argv)
next prev parent reply other threads:[~2026-06-23 21:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260623072220.1421837-1-chenyichong@uniontech.com>
2026-06-23 7:22 ` Yichong Chen
2026-06-23 21:44 ` Emil Tsalapatis [this message]
2026-06-23 7:22 ` [PATCH v3 2/2] tools/bpf/bpftool: Reset vmlinux BTF after struct_ops commands Yichong Chen
2026-06-23 21:45 ` Emil Tsalapatis
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=DJGR9M02WSP5.2SJ91UABVUWAQ@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyichong@uniontech.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jiayuan.chen@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=qmo@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
all inboxes | Powered by JetHome®