Skip to content

perf tools: Enhance namespace and chroot handling

Namhyung Kim linux-perf-users lkml 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest11 patches 0 repliesNew
  2. v111 patches 0 repliesSuperseded

Changes in v2 from the cover letter

* Keep dso__filename_with_chroot() (guarded by nsinfo__check_proc()) instead of calling chroot() inside nsinfo__mountns_enter().
* Add a mutex lock to struct nsinfo and replace thread->nsinfo safely on exec/namespace events rather than mutating shared instances in place.
* Mark offline sessions explicitly, propagate exit on fork replacement and perf_event__exit_del_thread(), and guard sub-thread fallback in thread__e_machine_endian().
* Gate mount namespace entry for debuginfo/binary probing callers, include distro debuginfo types, and handle build-id lookups in symbol-minimal's dso__load_sym().
* Add unit and shell tests for namespace, nsinfo, chroot, and boot ID handling.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11perf tools: Add HEADER_BOOT_ID featuretools/perf/Documentation/perf.data-file-format.txt tools/perf/builtin-inject.c tools/perf/util/env.c +4 more+83 -00 replies
2/11perf tools: Add perf_env__is_same_boot()tools/perf/util/env.c tools/perf/util/env.h+26 -00 replies
3/11perf tools: Add nsinfo__new_thread() to track tidtools/perf/util/machine.c tools/perf/util/namespaces.c tools/perf/util/namespaces.h +1 more+25 -50 replies
4/11perf tools: Add lock to struct nsinfotools/perf/util/namespaces.c tools/perf/util/namespaces.h+86 -220 replies
5/11perf tools: Defer /proc lookup until nsinfo is usedtools/perf/builtin-inject.c tools/perf/util/jitdump.c tools/perf/util/map.c +4 more+53 -160 replies
6/11perf tools: Verify thread status and mount namespace inodetools/perf/util/namespaces.c tools/perf/util/namespaces.h+114 -290 replies
7/11perf tools: Check thread liveness when accessing /proctools/perf/builtin-trace.c tools/perf/util/dso.c tools/perf/util/event.c +3 more+86 -130 replies
8/11perf tools: Export filename__read_build_id_ns()tools/perf/builtin-inject.c tools/perf/util/build-id.c tools/perf/util/dsos.c +1 more+18 -280 replies
9/11perf tools: Only enter mount namespace if necessarytools/perf/util/capstone.c tools/perf/util/debuginfo.c tools/perf/util/disasm.c +2 more+102 -190 replies
10/11perf tools: Scope mount namespace entry in dso__load()tools/perf/util/symbol-minimal.c tools/perf/util/symbol.c+24 -250 replies
11/11perf tests: Add namespace, nsinfo, and boot ID teststools/perf/tests/Build tools/perf/tests/builtin-test.c tools/perf/tests/namespaces.c +2 more+1047 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 00/11] perf tools: Enhance namespace and chroot handling

Hello,

This series improves namespace and chroot handling when perf accesses files from /proc. It defers reading /proc until namespace info is actually needed, verifies thread liveness, matching boot IDs, and mount namespace inodes against PID/TID recycling, and avoids entering target mount namespaces for host-side files such as the build-id cache.

It's assisted by LLM.

v2 changes:

* Keep dso__filename_with_chroot() (guarded by nsinfo__check_proc()) instead of calling chroot() inside nsinfo__mountns_enter().
* Add a mutex lock to struct nsinfo and replace thread->nsinfo safely on exec/namespace events rather than mutating shared instances in place.
* Mark offline sessions explicitly, propagate exit on fork replacement and perf_event__exit_del_thread(), and guard sub-thread fallback in thread__e_machine_endian().
* Gate mount namespace entry for debuginfo/binary probing callers, include distro debuginfo types, and handle build-id lookups in symbol-minimal's dso__load_sym().
* Add unit and shell tests for namespace, nsinfo, chroot, and boot ID handling.

v1: https://lore.kernel.org/r/[email protected]

Thanks,
Namhyung

Namhyung Kim (11):
perf tools: Add HEADER_BOOT_ID feature
perf tools: Add perf_env__is_same_boot()
perf tools: Add nsinfo__new_thread() to track tid perf tools: Add lock to struct nsinfo
perf tools: Defer /proc lookup until nsinfo is used perf tools: Verify thread status and mount namespace inode perf tools: Check thread liveness when accessing /proc perf tools: Export filename__read_build_id_ns() perf tools: Only enter mount namespace if necessary perf tools: Scope mount namespace entry in dso__load() perf tests: Add namespace, nsinfo, and boot ID tests

 .../Documentation/perf.data-file-format.txt   |    5 +
 tools/perf/builtin-inject.c                   |   15 +-
 tools/perf/builtin-trace.c                    |    2 +-
 tools/perf/tests/Build                        |    1 +
 tools/perf/tests/builtin-test.c               |    1 +
 tools/perf/tests/namespaces.c                 | 1035 +++++++++++++++++
 tools/perf/tests/shell/header.sh              |    9 +
 tools/perf/tests/tests.h                      |    1 +
 tools/perf/util/build-id.c                    |   14 +-
 tools/perf/util/capstone.c                    |    8 +-
 tools/perf/util/debuginfo.c                   |   19 +-
 tools/perf/util/disasm.c                      |    8 +-
 tools/perf/util/dso.c                         |   59 +-
 tools/perf/util/dso.h                         |   34 +
 tools/perf/util/dsos.c                        |   17 +-
 tools/perf/util/env.c                         |   69 ++
 tools/perf/util/env.h                         |    4 +
 tools/perf/util/event.c                       |    1 +
 tools/perf/util/header.c                      |   28 +
 tools/perf/util/header.h                      |    1 +
 tools/perf/util/jitdump.c                     |    2 +-
 tools/perf/util/machine.c                     |   16 +-
 tools/perf/util/map.c                         |    2 +-
 tools/perf/util/namespaces.c                  |  273 ++++-
 tools/perf/util/namespaces.h                  |   10 +
 tools/perf/util/session.c                     |    1 +
 tools/perf/util/symbol-minimal.c              |    4 +-
 tools/perf/util/symbol.c                      |   45 +-
 tools/perf/util/symbol.h                      |    3 +
 tools/perf/util/thread.c                      |   95 +-
 tools/perf/util/thread.h                      |   13 +-
 31 files changed, 1651 insertions(+), 144 deletions(-)
 create mode 100644 tools/perf/tests/namespaces.c
Signature · 1 line
2.56.0.611.g1030f0b940-goog