[PATCH] perf dso: Stay in perf's mount namespace for cached debuginfo
From: Alireza Haghdoost via B4 Relay
Date: Sat Nov 21 2026 - 17:25:45 EST
From: Alireza Haghdoost <haghdoost@xxxxxxxx>
When perf reads the data of a DSO that belongs to a process in another
mount namespace, open_dso() enters that namespace to open the file. It
does not do this for files in perf's own build-id cache, but it only
checks for DSO_BINARY_TYPE__BUILD_ID_CACHE.
Cached debuginfo files (DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO) are
in the same build-id cache, yet open_dso() looks for them in the
target's namespace. The file is usually not there, so for example
perf script -F +insn prints no instruction bytes. If a file with the
same path does exist there, perf reads the wrong file.
This patch skips the namespace switch for both build-id cache types, as
dso__load() already does.
Fixes: 5363c306787c ("perf symbol: Set binary_type of dso when loading")
Signed-off-by: Alireza Haghdoost <haghdoost@xxxxxxxx>
---
Found while working on lazy symbol loading [1]. It does not depend on
that series.
[1] https://lore.kernel.org/all/20261121-perf-symbol-memory-send-v8-0-370561cbb5a7@xxxxxxxx/
---
tools/perf/util/dso.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index e46cd614eb21..6aad25e9d4f5 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -707,14 +707,17 @@ static int open_dso(struct dso *dso, struct machine *machine)
{
int fd;
struct nscookie nsc;
+ enum dso_binary_type bt = dso__binary_type(dso);
+ bool nsenter = bt != DSO_BINARY_TYPE__BUILD_ID_CACHE &&
+ bt != DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO;
- if (dso__binary_type(dso) != DSO_BINARY_TYPE__BUILD_ID_CACHE) {
+ if (nsenter) {
mutex_lock(dso__lock(dso));
nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
mutex_unlock(dso__lock(dso));
}
fd = __open_dso(dso, machine);
- if (dso__binary_type(dso) != DSO_BINARY_TYPE__BUILD_ID_CACHE)
+ if (nsenter)
nsinfo__mountns_exit(&nsc);
if (fd >= 0) {
---
base-commit: bb27ddbaee56536fb8df0a24f07b526766dfe131
change-id: 20261121-perf-dso-ns-fix-4a71bd206f04
Best regards,
--
Alireza Haghdoost <haghdoost@xxxxxxxx>