From nobody Tue Dec 16 04:37:56 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA6EAC32771 for ; Mon, 26 Sep 2022 12:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237009AbiIZMYB (ORCPT ); Mon, 26 Sep 2022 08:24:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239556AbiIZMXi (ORCPT ); Mon, 26 Sep 2022 08:23:38 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05EB08A1DE; Mon, 26 Sep 2022 04:05:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id A2552CE1117; Mon, 26 Sep 2022 10:48:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84783C433D6; Mon, 26 Sep 2022 10:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189323; bh=iQBts69Xg4uRZG7l2hp4cSGamepujS260GBRhpeKnlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Usr4bFJUtRg+rESsU6WdhYe6dsAsE0Zf1x6vltQKpY1d7aHDFN/fXaZDkpK626BLW i/4rYy7F+dayaIGrKe/csmWUWmSdA9xjDF7ZEnygvCJ056Xn0JLqBCxeGWJfTiPjXh qoCWhyZRy4qLKHpcAaV6VbtoBbNI4UXFlz7/EhOA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Adrian Hunter , Ian Rogers , Jiri Olsa , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.19 149/207] perf tools: Honor namespace when synthesizing build-ids Date: Mon, 26 Sep 2022 12:12:18 +0200 Message-Id: <20220926100813.321988454@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Namhyung Kim [ Upstream commit 999e4eaa4b3691acf85d094836260ec4b66c74fd ] It needs to enter the namespace before reading a file. Fixes: 4183a8d70a288627 ("perf tools: Allow synthesizing the build id for k= ernel/modules/tasks in PERF_RECORD_MMAP2") Signed-off-by: Namhyung Kim Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20220920222822.2171056-1-namhyung@kernel.= org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/synthetic-events.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 84d17bd4efae..64e273b2b1b2 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -367,13 +367,24 @@ static void perf_record_mmap2__read_build_id(struct p= erf_record_mmap2 *event, bool is_kernel) { struct build_id bid; + struct nsinfo *nsi; + struct nscookie nc; int rc; =20 - if (is_kernel) + if (is_kernel) { rc =3D sysfs__read_build_id("/sys/kernel/notes", &bid); - else - rc =3D filename__read_build_id(event->filename, &bid) > 0 ? 0 : -1; + goto out; + } + + nsi =3D nsinfo__new(event->pid); + nsinfo__mountns_enter(nsi, &nc); =20 + rc =3D filename__read_build_id(event->filename, &bid) > 0 ? 0 : -1; + + nsinfo__mountns_exit(&nc); + nsinfo__put(nsi); + +out: if (rc =3D=3D 0) { memcpy(event->build_id, bid.data, sizeof(bid.data)); event->build_id_size =3D (u8) bid.size; --=20 2.35.1