From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49A32155753; Wed, 19 Feb 2025 09:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956252; cv=none; b=ef2CGu29+P245lbJP7QJuvD6jeaUCLyd2NHS33N9z2mcl1l0btr4yrX8FiY6iIpfoWZD+B0T++dVROv0/QFB0/6W9Cv0IivAB0hCPODczvF3fNa/yl3Fpok1D4rYb+b0kbaljzmmSSi6JMChyCq38bTzwL0YXR84ENkmhB4m6mU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956252; c=relaxed/simple; bh=bKCzlWs1HAchJSxEPcvVKc1NvGDTfq3EQjEizmY4Cxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RxXGWT44gcTM0T/QolPa5Zb3ez1GGFCyu2xzGx9VBt9AhEIcg5LbzSikDewpeBrj9I+IuSm8lhkuG0nRaPXbzI+ODlNkt9UfkjEpp6NQD05YtyB2Xo9bqBXXAZxH7pmaQ7E84GMMZU+murMck8Qs/E+4DPhTCgASfQJCxpq9hi0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=T5ihBn1H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="T5ihBn1H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35E5CC4CEE7; Wed, 19 Feb 2025 09:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739956251; bh=bKCzlWs1HAchJSxEPcvVKc1NvGDTfq3EQjEizmY4Cxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T5ihBn1HiJSHJId/2GKnxSj7ITVPN47RG8j5lvtPSIKIZye39kOtHHjOCbZbkyHc+ RvakZUg5y36Fk4yTXtp5NDDKSnQ0iPvB+nulS2C8D/Be/5JiLPkrHlDCyzxkmDwzQO e7KGGswiLlWKCbJzhs4dCsccAK8vyDVTvANVjWGQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Francesco Nigro , Ilan Green , Adrian Hunter , Clark Williams , Ian Rogers , Ingo Molnar , James Clark , Jiri Olsa , Kan Liang , Namhyung Kim , Stephane Eranian , Thomas Gleixner , Yonatan Goldschmidt , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.1 117/578] perf namespaces: Introduce nsinfo__set_in_pidns() Date: Wed, 19 Feb 2025 09:22:01 +0100 Message-ID: <20250219082657.584297672@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo [ Upstream commit 9c6a585d257f6845731f4e36b45fe42b5c3162f5 ] When we're processing a perf.data file we will, for every thread in that file do a machine__findnew_thread(machine, pid, tid) that when that pid is seen for the first time will create a 'struct thread' representing it. That in turn will call nsinfo__new() -> nsinfo__init() and there it will assume we're running live, which is wrong and will need to be addressed in a followup patch. The nsinfo__new() assumes that if we can't access that thread it has already finished and will ignore the -1 return from nsinfo__init(), just taking notes to avoid trying to enter in that namespace, since it isn't there anymore, a race. When doing this from 'perf inject', tho, we can fill in parts of that nsinfo from what we get from the PERF_RECORD_MMAP2 (pid, tid) and in the jitdump file name, that has the form of jit-.dump. So if the pid in the jitdump file name is not the one in the PERF_RECORD_MMAP2, we can assume that its the pid of the process _inside_ the namespace, and that perf was runing outside that namespace. This will be done in the following patch. Reported-by: Francesco Nigro Reported-by: Ilan Green Cc: Adrian Hunter Cc: Clark Williams Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Yonatan Goldschmidt Link: https://lore.kernel.org/r/20241206204828.507527-4-acme@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Stable-dep-of: 64a7617efd5a ("perf namespaces: Fixup the nsinfo__in_pidns() return type, its bool") Signed-off-by: Sasha Levin --- tools/perf/util/namespaces.c | 5 +++++ tools/perf/util/namespaces.h | 1 + 2 files changed, 6 insertions(+) diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c index dd536220cdb9e..fe59c2b9cd624 100644 --- a/tools/perf/util/namespaces.c +++ b/tools/perf/util/namespaces.c @@ -242,6 +242,11 @@ pid_t nsinfo__in_pidns(const struct nsinfo *nsi) return nsi->in_pidns; } +void nsinfo__set_in_pidns(struct nsinfo *nsi) +{ + RC_CHK_ACCESS(nsi)->in_pidns = true; +} + void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc) { diff --git a/tools/perf/util/namespaces.h b/tools/perf/util/namespaces.h index 567829262c428..62a9145a6ffba 100644 --- a/tools/perf/util/namespaces.h +++ b/tools/perf/util/namespaces.h @@ -58,6 +58,7 @@ pid_t nsinfo__tgid(const struct nsinfo *nsi); pid_t nsinfo__nstgid(const struct nsinfo *nsi); pid_t nsinfo__pid(const struct nsinfo *nsi); pid_t nsinfo__in_pidns(const struct nsinfo *nsi); +void nsinfo__set_in_pidns(struct nsinfo *nsi); void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc); void nsinfo__mountns_exit(struct nscookie *nc); -- 2.39.5