[PATCH v1 3/8] perf symbol: Fall back to fetching the vmlinux by build ID

From: Arnaldo Carvalho de Melo

Date: Sat Sep 12 2026 - 22:35:56 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

A profile recorded on a kernel that is no longer installed, be it
because the machine was rebooted into a new kernel or because the
profile is being processed on another machine, can't have its kernel
symbols resolved: /proc/kallsyms matches the running kernel, not the
one in the profile, and is refused when restricted, e.g. with
kernel.perf_event_paranoid > 1, while the build-id cache may carry
just a kallsyms copy with zeroed addresses. With no kernel symbols
the kernel samples can't be annotated, so they all end up in the
'(unknown)' data type and the kernel is missing from the data type
profile JSON "dsos" entry.

As a last resort, when the kernel symbols can't be found locally and
the user didn't specify a kallsyms file, fetch the vmlinux keyed by
the kernel build ID recorded in the perf.data file using the
debuginfod client and use it for symbols, which also provides the
DWARF debuginfo needed for data type profiling.

Like the other vmlinux sources this honors --ignore-vmlinux and
--ignore-vmlinux_buildid: a fetched vmlinux is still a vmlinux, and
the fetch is keyed by the build ID, so both flags skip it, keeping
'perf record' and 'perf probe', that set ignore_vmlinux_buildid
internally, away from it. The fetch itself follows the opt-out
controls added in the previous patch, --no-debuginfod,
core.debuginfod=false and the build-id-cache-is-off case, and can be
skipped with the 's'/'d' keys while it runs. Build IDs that were a
miss are remembered, not queried again on every dso__load() retry.

With a profile recorded on a system running kernel 7.1.10, later
processed after it was upgraded to 7.1.13, 'perf report -s type
' went from having all 24.91% of the kernel samples as
'(unknown)' data types to resolving struct task_struct, struct rq,
struct tty_struct, struct qspinlock, etc, with the kernel DSO, keyed
by its build ID, appearing in the data type profile JSON.

Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/symbol.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b1a2684c813c5d8d..034e11e75bb94999 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -20,6 +20,7 @@
#include "cap.h"
#include "cpumap.h"
#include "debug.h"
+#include "debuginfo.h"
#include "demangle-cxx.h"
#include "demangle-java.h"
#include "demangle-ocaml.h"
@@ -2191,12 +2192,35 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
return strdup(path);
}

+/*
+ * Last resort when the symbols for the kernel the profile was recorded
+ * on can't be found locally: fetch the vmlinux keyed by the build ID
+ * recorded in the perf.data file using the debuginfod client, which
+ * checks its local cache first, e.g. when processing the profile on
+ * another machine or after the kernel and its debuginfo package got
+ * upgraded in between.
+ */
+static int dso__load_vmlinux_build_id(struct dso *dso, struct map *map)
+{
+ char *path = NULL;
+
+ if (!dso__has_build_id(dso))
+ return -1;
+
+ if (debuginfo__find_build_id(dso__bid(dso), &path))
+ return -1;
+
+ /* Takes ownership of 'path' even when it fails */
+ return dso__load_vmlinux(dso, map, path, true);
+}
+
static int dso__load_kernel_sym(struct dso *dso, struct map *map)
{
int err;
const char *kallsyms_filename = NULL;
char *kallsyms_allocated_filename = NULL;
char *filename = NULL;
+ bool user_kallsyms = false;

/*
* Step 1: if the user specified a kallsyms or vmlinux filename, use
@@ -2215,6 +2239,7 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map)
*/
if (symbol_conf.kallsyms_name != NULL) {
kallsyms_filename = symbol_conf.kallsyms_name;
+ user_kallsyms = true;
goto do_kallsyms;
}

@@ -2257,7 +2282,18 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map)
pr_debug("Using %s for symbols\n", kallsyms_filename);
free(kallsyms_allocated_filename);

- if (err > 0 && !dso__is_kcore(dso)) {
+ /*
+ * The kallsyms may be unavailable or restricted, e.g.
+ * /proc/kallsyms with kernel.perf_event_paranoid > 1, try to fetch
+ * the vmlinux keyed by the build ID using debuginfod as a last
+ * resort, honoring --ignore-vmlinux and --ignore-vmlinux_buildid
+ * like the other vmlinux sources above.
+ */
+ if (err <= 0 && !user_kallsyms &&
+ !symbol_conf.ignore_vmlinux &&
+ !symbol_conf.ignore_vmlinux_buildid) {
+ err = dso__load_vmlinux_build_id(dso, map);
+ } else if (err > 0 && !dso__is_kcore(dso)) {
struct maps *kmaps = map__kmaps(map);

dso__set_binary_type(dso, DSO_BINARY_TYPE__KALLSYMS);
--
2.55.0