mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alireza Haghdoost via B4 Relay <devnull+haghdoost.uber.com@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	 Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	 Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	 linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Alireza Haghdoost <haghdoost@uber.com>
Subject: [PATCH] perf dso: Stay in perf's mount namespace for cached debuginfo
Date: Sat, 21 Nov 2026 14:25:23 -0800	[thread overview]
Message-ID: <20261121-perf-dso-ns-fix-v1-1-897322ddadf8@uber.com> (raw)

From: Alireza Haghdoost <haghdoost@uber.com>

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@uber.com>
---
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@uber.com/
---
 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@uber.com>



                 reply	other threads:[~2026-11-21 22:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261121-perf-dso-ns-fix-v1-1-897322ddadf8@uber.com \
    --to=devnull+haghdoost.uber.com@kernel.org \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=haghdoost@uber.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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®