From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796047069; b=LqRrCnZKanzlF4iDBeZaIjIlA2mNmUQmO3Aq30LxQuQp6LpPg8Z8Q6oW8niHmlD1ZuPE XpGTJ8wsi0ApC+u1A0Ws4CiczU6uigBFulFd0IUa4wuiK8AIoWwHaDChILzbWOAGANwiR xIvQw+O8FtMuYnAHBOKwaC5qZ+xg6aMX+sDadAH579Dc6giVsr765kf5d7l/3FXDcom+B eciIqk3l2vEnEZ1aojiL9am8g5oohnJmEaCdyCSEq6hnW++NhlO9Jh8S+T0s3TX+BPsxY byplq+qYGWwdQFOhy5OY4GYHxzI0PNiWu5WOJKJ35yg9rYXSAQY1WFQI4r3PsAJMq9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047069; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Content-Type:Mime-Version:Subject: From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id: References:To:X-Mailer:X-TM-AS-GCONF:X-Proofpoint-Reinject: X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=IYYnsYBQSO4Pj2KXzBMStE0pZYcynEpjHjp3r2vfkag=; b=iRViwuevmifwELXTEEgMzuENhdzOpgYBg2/pfuZxFNCLsDXpqcbyXUzCOaCwbMZFX9PJ RsvhQJydlmCpJgDe3zebS6lN30HQZjDiGmejb1/+ttpRZ3/W/d41u3WhwcD5FJW5gRSpE 4PnAjhLAAOe6UDiRP3YrLp5tgbT55P9uMxhDDu4i+qkx6Dq8OgVV4N8RNnG0Q3SqyGfvg PK0nulukySpZRcTdtF2QbARAm9+BFbNybD/mk1Bfi5JcI9v9IDmLKdKpdCFLSMKFn2VmB TI8fN+0IfSH+GCxA3Q8mNYvESCXkj7tnYaHqoBYIX/8SiB9QGbrSOJHHaWEcdq2wtEQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b="M/kRDV73"; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0AFE606A33E; Mon, 30 Nov 2026 13:57:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E0AFE606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=M/kRDV73 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUDZ2ni3413530; Mon, 30 Nov 2026 13:57:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=IYYnsY BQSO4Pj2KXzBMStE0pZYcynEpjHjp3r2vfkag=; b=M/kRDV730SCOoyvnSN0I1f tGt+cNLBTkM/SAa9LCVho0jlmNUGARm0viNpeR0AQFX5vAmBDICddz04OHdBfQZm Y1oQ8KEpVg/fMbxW6/no/3j9MsIoFgPpEHfkNoaYq1r/tKhkgkH3pteGshJF+UX+ 0n2j72T7LJzUpJAMaI6gWHOmF/JuNBGEvy2haBo8/GlkKTB+VNiuuEPhAoUiGUTX 0KmMUb2SlyK5WX0Z+grAjB3uEh7Lj99BBlbBn1YSAiK8/WxtaxWg84eHzymzrIjO El4zQbTU7LVRS5ZTrAIq8Cpuata9DorwdoZyDwXJjvMnc3SeLGG1hlk7xPKbz1oA == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pf3r37y-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 30 Nov 2026 13:57:22 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUDJPEw090160; Mon, 30 Nov 2026 13:57:21 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j8byxvuhp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Nov 2026 13:57:21 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6AUDvKRS48431602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Nov 2026 13:57:20 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7E0A2004B; Mon, 30 Nov 2026 13:57:19 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A252820040; Mon, 30 Nov 2026 13:57:17 +0000 (GMT) Received: from smtpclient.apple (unknown [9.124.208.233]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTPS; Mon, 30 Nov 2026 13:57:17 +0000 (GMT) Content-Type: text/plain; charset=utf-8 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.300.41.1.7\)) Subject: Re: [PATCH v4 00/11] perf tools: Enhance namespace and chroot handling From: Athira Rajeev In-Reply-To: Date: Mon, 30 Nov 2026 19:27:05 +0530 Cc: Arnaldo Carvalho de Melo , Ian Rogers , Jiri Olsa , Adrian Hunter , James Clark , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20261125212851.1792988-1-namhyung@kernel.org> <0E48728A-861B-4045-9B43-79B61579328E@linux.ibm.com> To: Namhyung Kim X-Mailer: Apple Mail (2.3864.300.41.1.7) X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA1NCBTYWx0ZWRfX7TTjMacTmMm/ NdDwlGFIp2EcmY2wWwgdl6BgKhVoa/fV2hIfS41v4FiNAGnTAHfyFF5PEustIuEzwx+KQNmJjEp ICX5Uj/kwmgXDHxMim7y+OXyfib6LjQ= X-Proofpoint-ORIG-GUID: tUGm-FuIDDwyAhvQAuDDVnu0Rx57DgTr X-Proofpoint-GUID: mwFULBxFiBMUyyj5ehVhk0IUzgKoGRU5 X-Authority-Analysis: v=2.4 cv=R6eWitRX c=1 sm=1 tr=0 ts=6b0d80c3 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=D1iN-VbA9rhTeTrjH1IA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA1NCBTYWx0ZWRfX9yGApencIQen bpg9COHiGlUHFsa65dSIRCUoqh9XkFdSPTYjnjMOvqfiq0oOkkAEAp4b5xOdYtHaoqicH/D3cyy GrluMul+OVJkizl23T6dv19Cu++4dcW0UX9eZwCuUoF+QAS3et37OQ8j/ZxkvsWOHYjN9L5Mgs2 M3nJdFvnjj85XJ9GZGgOjCzkoEsWze2pseLJKrwlEObH7/nrpF4WuDkZXZNcoya4lCFvQvhySoF YTCIpbsUH5Fm94SWwKfjMad+9quaRQMdI8acRA3BLiR/ar8fUTC4odJcaOAMVWaVBU+S7Ql8fIy al1vl4mYDNmqzn4rgm2KgbTIDetKn+NavchwJPJz1KAlcxn+MH3Z5bxVrrz2ByHeb3asksrFCsR U5uc4iblMwcPX+WS9Am90U01V5A8sCY3TvyrTuDI7qnXSCaqu/DyGfdmeD8jf1d1bueUXG4E2Aa C2rS8TPPkElCK+Cjlgg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-30_04,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 spamscore=0 bulkscore=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300054 > On 30 Nov 2026, at 5:08=E2=80=AFAM, Namhyung Kim = wrote: >=20 > Hello, >=20 > On Sat, Nov 28, 2026 at 03:22:33PM +0530, Athira Rajeev wrote: >>=20 >>=20 >>> On 26 Nov 2026, at 2:58=E2=80=AFAM, Namhyung Kim = wrote: >>>=20 >>> Hello, >>>=20 >>> 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. >>>=20 >>=20 >> Hi Namhyung, >>=20 >> Tested on powerpc (ppc64le, 7.4.0-rc4-next-20261124+), with the = series >> applied on = git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git >> and an unpatched perf as baseline. >>=20 >> Boot ID (patches 1, 2): >> - perf record writes the boot ID and it matches >> /proc/sys/kernel/random/boot_id. >> - perf inject keeps it, and perf inject on a file recorded by an = older >> perf does not add one. >>=20 >> Test suite: >> 75: Namespace and nsinfo tests >> 75.1: boot_id : Ok >> 75.2: init_and_copy : Ok >> 75.3: proc_and_recycled_tid : Ok >> 75.4: thread_liveness : Ok >> 75.5: dso_needs_ns : Ok >> 75.6: mountns_and_chroot : Ok >> (6 subtests passed, 0 failed) >>=20 >> Lazy nsinfo init (patch 5): >> For perf report on a 2-second system-wide recording >> (perf record -a -- sleep 2), the number of = /proc//{ns/mnt,status} >> accesses (counted with strace) dropped from 520 to 0, and the report >> output is identical. >>=20 >> Two boots (patches 2, 6, 7): >> I recorded system-wide while a busy process ran in its own mount >> namespace, rebooted, and ran perf report on the old file. >> - The report output on the new boot is identical to the one from = before >> the reboot, for both patched and unpatched perf. >> - I then started a different process with the recorded pid in a = private >> mount namespace (via ns_last_pid) and ran perf report again, = counting >> with strace: >> setns() calls = touches of that pid >> patched, different boot 0 0 >> unpatched, different boot 6 4 >> - Control on the same boot with the process still alive: >> patched 68 17 >> unpatched 30 4 >> so the patched perf still enters the namespace of a live process, = and >> stops using /proc when the boot ID differs. >>=20 >>=20 >> Tested-by: Athira Rajeev >=20 > Thanks a lot! >=20 >>=20 >> Namhyung, >>=20 >> FWIW, on the same boot with live processes in other mount namespaces = the >> patched perf enters the namespace about 2.5x as often as the = unpatched >> one (70 vs 28 enters, 140 vs 56 setns() calls on a 7844-sample >> system-wide recording). It does the same 134 traced openat/stat calls >> inside the namespaces, split across more enters, and the trace also >> shows extra opens of /proc and reads of /proc//task//status >> (patch 6). No setns() failed and the report output is identical. Is = the >> increase expected? >=20 > Huge thanks for your detailed test and analysis. It's expected to be > increased as it now tracks the proc and namespace more accurately. = But > I think there are places to optimized it a bit. Will update in v5. >=20 > Thanks, > Namhyung Sure Namhyung Thanks for the reply. I have tested V5 as well and will post the results and my Tested-by in the V5 thread Thanks Athira >=20 >=20 >>=20 >> How I measured it (./perf is patched, ./save_1/perf is unpatched): >>=20 >> # a busy process in its own mount namespace, then record system-wide >> unshare -m sh -c 'mount -t tmpfs none /mnt && cp /usr/bin/yes = /mnt/myyes && >> exec /mnt/myyes > /dev/null' & >> pid=3D$!; sleep 1 >> ./perf record -a -e cycles:u -o ctl.data -- sleep 3 >> kill $pid >>=20 >> # trace the same file with each binary >> strace -f -e trace=3Dsetns,openat,stat,newfstatat -o /tmp/c.new = ./perf report -i ctl.data --stdio --sort comm,dso,sym >> strace -f -e trace=3Dsetns,openat,stat,newfstatat -o /tmp/c.old = ./save_1/perf report -i ctl.data --stdio --sort comm,dso,sym >>=20 >>=20 >> grep -c 'setns(' /tmp/c.new >> grep 'setns(' /tmp/c.new >> awk '/setns\(/{ if (inside) { if (cnt=3D=3D0) empty++; inside=3D0 } >> else { inside=3D1; cnt=3D0; enters++ } next } >> inside { cnt++; total++ } >> END { printf "enters=3D%d empty_enters=3D%d = lines_inside=3D%d\n", >> enters, empty, total }' /tmp/c.new >>=20 >> grep -c 'setns(' /tmp/c.old >> grep 'setns(' /tmp/c.old >> awk '/setns\(/{ if (inside) { if (cnt=3D=3D0) empty++; inside=3D0 } >> else { inside=3D1; cnt=3D0; enters++ } next } >> inside { cnt++; total++ } >> END { printf "enters=3D%d empty_enters=3D%d = lines_inside=3D%d\n", >> enters, empty, total }' /tmp/c.old >>=20 >> Result: >> setns failed enters empty lines inside >> patched 140 0 70 6 134 >> unpatched 56 0 28 0 134 >>=20 >> The report output is identical for both. >> The report output is identical for both: >> ./perf report -i ctl.data --stdio --sort comm,dso,sym 2>&1 | grep = -v '^#' > /tmp/r.new >> ./save_1/perf report -i ctl.data --stdio --sort comm,dso,sym 2>&1 = | grep -v '^#' > /tmp/r.old >> diff /tmp/r.new /tmp/r.old # no output >>=20 >> Thanks >> Athira >>=20 >>> It's assisted by LLM. >>>=20 >>> v4 changes: >>>=20 >>> * 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()). >>>=20 >>> v3: = https://lore.kernel.org/r/20261123232025.1406560-1-namhyung@kernel.org >>>=20 >>> * 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. >>>=20 >>> v2: = https://lore.kernel.org/r/20261116055731.707164-1-namhyung@kernel.org >>>=20 >>> * 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. >>>=20 >>> v1: = https://lore.kernel.org/r/20261023071141.134149-1-namhyung@kernel.org >>>=20 >>> Thanks, >>> Namhyung >>>=20 >>>=20 >>> 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 >>>=20 >>> .../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 | 1189 = +++++++++++++++++ >>> 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, 1999 insertions(+), 175 deletions(-) >>> create mode 100644 tools/perf/tests/namespaces.c >>>=20 >>> --=20 >>> 2.56.1.831.g720f3f5937-goog