From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: [PATCH v1 11/11] perf tools: Scope mount namespace entry in dso__load()
Date: Fri, 23 Oct 2026 00:11:41 -0700 [thread overview]
Message-ID: <20261023071141.134149-12-namhyung@kernel.org> (raw)
In-Reply-To: <20261023071141.134149-1-namhyung@kernel.org>
Enter the target mount namespace only for the specific binary types
that need it.
Assisted-by: LLM
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 43 +++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 23 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 807e433c770812a4..063e9da0878e93bc 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1811,17 +1811,6 @@ int dso__load(struct dso *dso, struct map *map)
const char *map_path = dso__long_name(dso);
mutex_lock(dso__lock(dso));
- perfmap = is_perf_pid_map_name(map_path);
-
- if (perfmap) {
- if (dso__nsinfo(dso) &&
- (dso__find_perf_map(newmapname, sizeof(newmapname),
- dso__nsinfo_ptr(dso)) == 0)) {
- map_path = newmapname;
- }
- }
-
- nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
/* check again under the dso->lock */
if (dso__loaded(dso)) {
@@ -1845,8 +1834,16 @@ int dso__load(struct dso *dso, struct map *map)
dso__set_adjust_symbols(dso, false);
+ perfmap = is_perf_pid_map_name(map_path);
if (perfmap) {
+ if (dso__nsinfo(dso) &&
+ (dso__find_perf_map(newmapname, sizeof(newmapname),
+ dso__nsinfo_ptr(dso)) == 0)) {
+ map_path = newmapname;
+ }
+ nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
ret = dso__load_perf_map(map_path, dso);
+ nsinfo__mountns_exit(&nsc);
dso__set_binary_type(dso, DSO_BINARY_TYPE__JAVA_JIT);
dso__set_symtab_type(dso, ret > 0
? DSO_BINARY_TYPE__JAVA_JIT
@@ -1869,7 +1866,7 @@ int dso__load(struct dso *dso, struct map *map)
struct build_id bid = { .size = 0, };
__symbol__join_symfs(name, PATH_MAX, dso__long_name(dso));
- if (filename__read_build_id(name, &bid) > 0)
+ if (filename__read_build_id_ns(name, &bid, dso__nsinfo(dso)) > 0)
dso__set_build_id(dso, &bid);
}
@@ -1882,24 +1879,25 @@ int dso__load(struct dso *dso, struct map *map)
struct symsrc *ss = &ss_[ss_pos];
bool next_slot = false;
bool is_reg;
- bool nsexit;
+ bool nsenter;
int bfdrc = -1;
int sirc = -1;
enum dso_binary_type symtab_type = binary_type_symtab[i];
- nsexit = (symtab_type == DSO_BINARY_TYPE__BUILD_ID_CACHE ||
- symtab_type == DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO);
-
if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
continue;
+ nsenter = dso_binary_type__needs_ns(symtab_type);
+ if (nsenter)
+ nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
+
if (dso__read_binary_type_filename(dso, symtab_type,
- root_dir, name, PATH_MAX))
+ root_dir, name, PATH_MAX)) {
+ if (nsenter)
+ nsinfo__mountns_exit(&nsc);
continue;
-
- if (nsexit)
- nsinfo__mountns_exit(&nsc);
+ }
is_reg = is_regular_file(name);
@@ -1910,8 +1908,8 @@ int dso__load(struct dso *dso, struct map *map)
if (is_reg && bfdrc < 0)
sirc = symsrc__init(ss, dso, name, symtab_type);
- if (nsexit)
- nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
+ if (nsenter)
+ nsinfo__mountns_exit(&nsc);
if (bfdrc > 0) {
dso__set_symtab_type(dso, symtab_type);
@@ -1978,7 +1976,6 @@ int dso__load(struct dso *dso, struct map *map)
out:
dso__set_loaded(dso);
mutex_unlock(dso__lock(dso));
- nsinfo__mountns_exit(&nsc);
return ret;
}
--
2.56.0.257.gf7497c7d27-goog
prev parent reply other threads:[~2026-10-23 7:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 7:11 [PATCH v1 00/11] perf tools: Enhance namespace and chroot handling Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 01/11] perf tools: Add HEADER_BOOT_ID feature Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 02/11] perf tools: Add perf_env__is_same_boot() Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 03/11] perf tools: Add nsinfo__new_thread() to track tid Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 04/11] perf tools: Defer /proc lookup until nsinfo is used Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 05/11] perf tools: Verify thread status and mount namespace inode Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 06/11] perf tools: Check thread liveness when accessing /proc Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 07/11] perf tools: Handle chroot inside nsinfo__mountns_enter() Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 08/11] perf tools: Export filename__read_build_id_ns() Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 09/11] perf tools: Remove redundant chroot handling Namhyung Kim
2026-10-23 7:11 ` [PATCH v1 10/11] perf tools: Only enter mount namespace if necessary Namhyung Kim
2026-10-23 7:11 ` Namhyung Kim [this message]
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=20261023071141.134149-12-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.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=mingo@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®