All of lore.kernel.org
 help / color / mirror / Atom feed
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 v3 00/11] perf tools: Enhance namespace and chroot handling
Date: Mon, 23 Nov 2026 15:20:14 -0800	[thread overview]
Message-ID: <20261123232025.1406560-1-namhyung@kernel.org> (raw)

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.

v3 changes:

 * Guard evlist before calling evlist__session() in write_boot_id().
 * Repipe PERF_RECORD_HEADER_FEATURE events in perf-inject pipe mode
   and add a boot ID pipe-injection shell test and unit test.
 * Pin a reference-counted host /proc descriptor across
   nsinfo__mountns_enter()/exit(), access relative /proc paths via
   stack-buffered nsinfo__proc_{open,stat,readlink}() helpers instead of
   heap-allocating mntns_path, and handle ENOENT/ESRCH on ns/mnt stat.
 * Skip filename_with_chroot() chroot resolution when
   nsinfo__need_setns() is set.
 * Add compiler context-analysis lock annotations (__guarded_by,
   __must_hold, __returns_ctx_lock) for struct nsinfo, host_proc_lock,
   thread->nsinfo, and __thread__reset_nsinfo(), plus locked accessors.
 * Expand mount namespace tests to verify overmounted /proc during
   nsinfo__mountns_enter() and own a private mount namespace in
   enter_private_userns() for clean nsinfo__mountns_exit() restoration.

v2: https://lore.kernel.org/r/20261116055731.707164-1-namhyung@kernel.org

 * 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/20261023071141.134149-1-namhyung@kernel.org

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                   |   29 +-
 tools/perf/builtin-trace.c                    |    2 +-
 tools/perf/tests/Build                        |    1 +
 tools/perf/tests/builtin-test.c               |    1 +
 tools/perf/tests/namespaces.c                 | 1188 +++++++++++++++++
 tools/perf/tests/shell/header.sh              |    9 +
 tools/perf/tests/shell/pipe_test.sh           |   21 +
 tools/perf/tests/tests.h                      |    1 +
 tools/perf/util/build-id.c                    |   15 +-
 tools/perf/util/capstone.c                    |    8 +-
 tools/perf/util/debuginfo.c                   |   19 +-
 tools/perf/util/disasm.c                      |    8 +-
 tools/perf/util/dso.c                         |   58 +-
 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                  |  439 +++++-
 tools/perf/util/namespaces.h                  |   23 +-
 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                      |   97 +-
 tools/perf/util/thread.h                      |   15 +-
 tools/perf/util/util.c                        |    7 +-
 33 files changed, 1998 insertions(+), 175 deletions(-)
 create mode 100644 tools/perf/tests/namespaces.c

-- 
2.56.1.809.ga0b61035b5-goog


             reply	other threads:[~2026-11-23 23:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 23:20 Namhyung Kim [this message]
2026-11-23 23:20 ` [PATCH v3 01/11] perf tools: Add HEADER_BOOT_ID feature Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 02/11] perf tools: Add perf_env__is_same_boot() Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 03/11] perf tools: Add nsinfo__new_thread() to track tid Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 04/11] perf tools: Add lock to struct nsinfo Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 05/11] perf tools: Defer /proc lookup until nsinfo is used Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 06/11] perf tools: Verify thread status and mount namespace inode Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 07/11] perf tools: Check thread liveness when accessing /proc Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 08/11] perf tools: Export filename__read_build_id_ns() Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 09/11] perf tools: Only enter mount namespace if necessary Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 10/11] perf tools: Scope mount namespace entry in dso__load() Namhyung Kim
2026-11-23 23:20 ` [PATCH v3 11/11] perf tests: Add namespace, nsinfo, and boot ID tests Namhyung Kim
2026-11-23 23:33   ` sashiko-bot
2026-11-23 23:35 ` [PATCH v3 00/11] perf tools: Enhance namespace and chroot handling sashiko-bot

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=20261123232025.1406560-1-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.