From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795998047; b=bogHdlCCT+CB4+kflUcLtv05RX/FL0XFZOPxXt2yNMxcx6Y0QulI0cWK474tNa9pPD0V +8MkRGkDAb4NUmBUdmMyclrRR3qCKoUOFS2lb0wTXOU+xPfJgo38xPYmW7kuQdGXkzU/M 1A4TJNX83ugL7QjInZ8lNQBngWPJDD+LRV5gbKDOBHfwtTofLnazlSczXGpfQOvkIBr6k kD7/Tp2ukca5WJT6xaKdjQudkiu1N4AF0+CrOONDlHFFNAZb5iXUZSJX+98hjxT4iNFyx Erm9hTzbCshdKWfle+9P8df6VhRxCMwAsM+bvFbc4Kq8Tflxxqplxfz3KUODRC7TVww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795998047; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=ypQ21VYhktPQW3Q3nJYOXOK1wP1CdXe+Sg4FCUUs+JM=; b=DNIwN+QMZ+zMcKbwMh48RdUJsTlWg9S/j/m0De6ty7+y419kPMPeoJdXEf4Io0A2ZhXb YGiEkzkHO+eVYe0Tf5Gv+MEIgRidsvMlmylG+YU2M4KmfCxTRm1e9oAmqxKwU2n284HzD gVZzLFtxvbokvcX1vmSZkDX5K5FFyGxQXz1fSve/9tmrq4a9Vogi+UMbzCFztSqdFzOoJ 9rKD+iWG3UQQMU3OIqxbdpe5k+ObgPZbjEQAtydmNTvpFPKlk9njClmR+ysODHN7qUICs niASSFyw6ltKW+4JtKnR+OLJ9e1hRn82b8TYxmX5RMA3oEM37lnuBctATCEW8/P64lg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CX8r3Btd; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B8FC606A33B; Mon, 30 Nov 2026 00:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CX8r3Btd Received: by smtp.kernel.org (Postfix) with ESMTPSA id 502921F00898; Mon, 30 Nov 2026 00:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795998046; bh=ypQ21VYhktPQW3Q3nJYOXOK1wP1CdXe+Sg4FCUUs+JM=; h=From:To:Cc:Subject:Date; b=CX8r3BtdaUfgFrEPAUMYG18U43ZVmnmxXDQVV5jH9MjdL63R0Fbm/W931RYlZMvpe KslY5gTsFT/K4JFlOVHpUSG2JeDGS5kFdFML9O524N5utXUd8N8OgFoC3Ne6Xysq5E ueS1KhUeKZWInxEo9Pb9ARJtFaAdszghxOVxfhpLtGUZgU66FWw7TPhn1k5cALp7fZ PryziTQNCHzXzUe4u9DnYf5+oNsUYVd47kIMxdnr8A8Qz0pYQQWXtzhMou2hoCSw+A yEUgOLQ/1/Li2lz9PFDs1YatgKKKnYQsasauCBiDn15DExrfIrQkELYi7AFkwRQwNQ 3CwWcKdYUfOZw== From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , James Clark , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 00/11] perf tools: Enhance namespace and chroot handling Date: Sun, 29 Nov 2026 16:20:34 -0800 Message-ID: <20261130002045.1964237-1-namhyung@kernel.org> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. v5 changes: * Match "Tgid:\t" and "NStgid:\t" at the start of /proc//status lines using strstarts() instead of strstr(), and add a regression test for spoofed Name: values. * Return an error from nsinfo__host_proc_get() without incrementing host_proc_refcnt when open("/proc") fails, and bail out early in nsinfo__mountns_enter(). * Pre-check dso__read_binary_type_filename() before entering the mount namespace for non-DEBUGLINK types in dso__find_binary_type_locked(), dso__find_dbginfo_type() (via __dso__get_filename()), and dso__load(), with comments explaining why DEBUGLINK differs. * Add Tested-by from Athira Rajeev. v4: https://lore.kernel.org/r/20261125212851.1792988-1-namhyung@kernel.org * Fix a potential struct thread reference leak on failure in test__nsinfo_thread_liveness(). * Rebase onto the latest tmp.perf-tools-next (preserving chroot tracking for --lazy-load-symbols in dso__load()). v3: https://lore.kernel.org/r/20261123232025.1406560-1-namhyung@kernel.org * 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 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 | 1193 +++++++++++++++++ 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 | 78 +- 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 | 457 +++++-- tools/perf/util/namespaces.h | 23 +- tools/perf/util/session.c | 1 + tools/perf/util/symbol-minimal.c | 4 +- tools/perf/util/symbol.c | 53 +- 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, 2046 insertions(+), 178 deletions(-) create mode 100644 tools/perf/tests/namespaces.c -- 2.56.1.839.g22a8290db9-goog