From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65C8CCED270 for ; Tue, 8 Oct 2024 07:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pTehMuXZj5J3wpIAXETd1riY5YcVcqwSocK9HZT6Cyk=; b=Z8wpgSXU6JA6TbIhaeWayYsfkG Hb91uKbVL2g7ORRGOUst1iqkl2xA0yCEHtuoy6kJV5qDI4C1NBT1sQei+CtC5cYkGJXRJxr/98H1t 8Lhom7VfQuo7oyWzwOjQrwMo4eFP3co3cEqHnGp6Pvx0V8CcPMO0Q5bCO+4E/ejZmihPdUMu7guKX m6LaxdsuKqFF8ACPZD0NCinGMhonSJjFm0+uxDAhtp5R6wxBiCIqCZWuE42iv603U2k0W1VNcXsVL cHMxpveTeLVqcOCiJ5eDV1j2Uk7EQyjgDqOkQblczKu1VW5OcLJ72wpuEo2VNb38OtsFVpCuFEK8V 8YNi+rXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sy4EW-00000004jdS-11Cw; Tue, 08 Oct 2024 07:02:12 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sy451-00000004iFp-0wKg for linux-arm-kernel@lists.infradead.org; Tue, 08 Oct 2024 06:52:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68BB8DA7; Mon, 7 Oct 2024 23:52:50 -0700 (PDT) Received: from [10.57.21.241] (unknown [10.57.21.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0838A3F640; Mon, 7 Oct 2024 23:52:18 -0700 (PDT) Message-ID: <93e822b1-76d1-454b-a42f-adf9292d4da6@arm.com> Date: Tue, 8 Oct 2024 07:52:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] coresight: etm4x: Fix PID tracing when perf is run in an init PID namespace To: Leo Yan , Julien Meunier Cc: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , stable@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20240925131357.9468-1-julien.meunier@nokia.com> <20241007200528.GB30834@debian-dev> Content-Language: en-US From: Leo Yan In-Reply-To: <20241007200528.GB30834@debian-dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241007_235223_418486_FCD50580 X-CRM114-Status: GOOD ( 18.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/7/2024 9:05 PM, Leo Yan wrote: > > Hi Julien, > > On Wed, Sep 25, 2024 at 03:13:56PM +0200, Julien Meunier wrote: >> The previous implementation limited the tracing capabilities when perf >> was run in the init PID namespace, making it impossible to trace >> applications in non-init PID namespaces. >> >> This update improves the tracing process by verifying the event owner. >> This allows us to determine whether the user has the necessary >> permissions to trace the application. > > The original commit aab473867fed is not for constraint permission. It is > about PID namespace mismatching issue. > > E.g. Perf runs in non-root namespace, thus it records process info in the > non-root PID namespace. On the other hand, Arm CoreSight traces PID for > root namespace, as a result, it will lead mess when decoding. > > With this change, I am not convinced that Arm CoreSight can trace PID for > non-root PID namespace. Seems to me, the concerned issue is still existed > - it might cause PID mismatching issue between hardware trace data and > Perf's process info. I thought again and found I was wrong with above conclusion. This patch is a good fixing for the perf running in root namespace to profile programs in non-root namespace. Sorry for noise. Maybe it is good to improve a bit comments to avoid confusion. See below. [...] >> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c >> index bf01f01964cf..8365307b1aec 100644 >> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c >> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c >> @@ -695,7 +695,7 @@ static int etm4_parse_event_config(struct coresight_device *csdev, >> >> /* Only trace contextID when runs in root PID namespace */ We can claim the requirement for the *tool* running in root PID namespae. /* Only trace contextID when the tool runs in root PID namespace */ >> if ((attr->config & BIT(ETM_OPT_CTXTID)) && >> - task_is_in_init_pid_ns(current)) >> + task_is_in_init_pid_ns(event->owner)) >> /* bit[6], Context ID tracing bit */ >> config->cfg |= TRCCONFIGR_CID; >> >> @@ -710,7 +710,7 @@ static int etm4_parse_event_config(struct coresight_device *csdev, >> goto out; >> } >> /* Only trace virtual contextID when runs in root PID namespace */ Ditto. /* Only trace virtual contextID when the tool runs in root PID namespace */ With above change: Reviewed-by: Leo Yan >> - if (task_is_in_init_pid_ns(current)) >> + if (task_is_in_init_pid_ns(event->owner)) >> config->cfg |= TRCCONFIGR_VMID | TRCCONFIGR_VMIDOPT; >> } >> >> -- >> 2.34.1 >> >>