summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2026-07-01 11:17:43 -0700
committerAndrii Nakryiko <andrii@kernel.org>2026-07-01 11:17:43 -0700
commitf29997a6d920cdfa2c43995e17c596c599ff261b (patch)
treebfa65907811f4a6c2276a73f1b1eb4be525d7770
parenta954c9e3168cdf0c3cad07b43dfc8ca2945d773a (diff)
parentf7f540e19751face50c68bb9ce58460fcb46c293 (diff)
downloadlinux-f29997a6d920cdfa2c43995e17c596c599ff261b.tar.gz
linux-f29997a6d920cdfa2c43995e17c596c599ff261b.zip
Merge branch 'tools-bpf-bpftool-fix-vmlinux-btf-state-cleanup'
Yichong Chen says: ==================== tools/bpf/bpftool: Fix vmlinux BTF state cleanup This series fixes stale vmlinux BTF state in bpftool batch mode. Patch 1 resets the map command cached vmlinux BTF pointer when the command releases it, and avoids freeing the cached object from the map lookup path. Patch 2 resets the struct_ops command cached vmlinux BTF pointer and dependent cached map info state after each struct_ops command. Changes in v4: - Add Emil's Reviewed-by tag to patch 1. - Inline the struct_ops cleanup instead of adding a helper. Changes in v3: - Add Fixes tags to both patches. Changes in v2: - Fold the map lookup path fix into patch 1. - Update patch 1 subject and commit message to cover map commands rather than only map dump. ==================== Link: https://patch.msgid.link/12A35C14DA710D2E+20260624025055.1574875-1-chenyichong@uniontech.com Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
-rw-r--r--tools/bpf/bpftool/map.c12
-rw-r--r--tools/bpf/bpftool/struct_ops.c4
2 files changed, 13 insertions, 3 deletions
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 71a45d96617e..6b9649294ca1 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 @@ exit_close:
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)
diff --git a/tools/bpf/bpftool/struct_ops.c b/tools/bpf/bpftool/struct_ops.c
index aa43dead249c..835e5e561f7f 100644
--- a/tools/bpf/bpftool/struct_ops.c
+++ b/tools/bpf/bpftool/struct_ops.c
@@ -643,6 +643,10 @@ int do_struct_ops(int argc, char **argv)
err = cmd_select(cmds, argc, argv, do_help);
btf__free(btf_vmlinux);
+ btf_vmlinux = NULL;
+ map_info_type = NULL;
+ map_info_alloc_len = 0;
+ map_info_type_id = 0;
return err;
}