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 B468CC3DA4A for ; Fri, 16 Aug 2024 12:46:00 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WLqLNKM/Y5z8jaCPrn4st9PbWfpd2fWa0rxEu+dBVp8=; b=suu9SR30QHoGW5dle1B9nvf4wF fUVFYcDdun2nuPrcR/zonEN6mDxZ8qXOtTTpfI0XcUFm+Wub3UZ16gLiZxcn0caexk21SRD4nVTcF wnye5XftdtjNoFSZMDImsHLW/jmCyCLjUzapCA5yzhR9NbZTdC6BYFmzQNJ1LateCYv71JulQREuR W96DSa9ZifUUrjfIEyUVcHHuDnUnFjA7iJ+sIbma6pIPxwB89pXyi1zNmsynq9R0sPxMigIp2H/Nn JqN1efAJRLkYqYdvk40jle9jfwYm+Y6AKSCj+KAKDQoE3t4UTRwdm9eHzXcvePTGcheMfodzq9GUQ KN1rHwzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewL0-0000000CvaE-3z2h; Fri, 16 Aug 2024 12:45:50 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewKK-0000000CvOw-43Fg for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:45:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E76E5CE1FAB; Fri, 16 Aug 2024 12:45:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1393C32782; Fri, 16 Aug 2024 12:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723812306; bh=rtMrfjK8iEsHvD8MfwhuMO8zqNzjX/ypZgoq9vbE3yY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QW+gvw8aVVE6tW+fpjlsu7WK9H70UkisDnKbyNdj2xshVVYgVRQcg01mb2ah29xeM DhRaJ7QgM6liVWP/9WYa6IKF6666qIqJa7/F1ChIhod1AcuImUJowETo4WVqzvg+wG xD6cnOhQ/jdtZge2Vq61ZhSKxstoMWojwzd8EelQ8oJmamuel/DJxpWQtTzqjeS67b gPoBy98TZMP+9I8H0UesSCxWROF2Imdr+lLrwuOKKTwAtsYyY9z/AbywaNrgwYUQ6A CWBqjDeSSpJw9G3yGwgabNjmgXZnJ0KVrAWe3CZYXsQiSgmerwx2gLq29fP7ygLzLo 5+L2XfP+F3Ptg== Date: Fri, 16 Aug 2024 13:45:00 +0100 From: Will Deacon To: James Clark Cc: linux-arm-kernel@lists.infradead.org, peterz@infradead.org, Al Grant , Mark Rutland , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v2] drivers/perf: arm_spe: Use perf_allow_kernel() for permissions Message-ID: <20240816124459.GA24323@willie-the-truck> References: <20240807155153.2714025-1-james.clark@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240807155153.2714025-1-james.clark@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240816_054509_375766_6CD7D29A X-CRM114-Status: GOOD ( 25.28 ) 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 Wed, Aug 07, 2024 at 04:51:53PM +0100, James Clark wrote: > For other PMUs, PERF_SAMPLE_PHYS_ADDR requires perf_allow_kernel() > rather than just perfmon_capable(). Because PMSCR_EL1_PA is another form > of physical address, make it consistent and use perf_allow_kernel() for > SPE as well. PMSCR_EL1_PCT and PMSCR_EL1_CX also get the same change. > > This improves consistency and indirectly fixes the following error > message which is misleading because perf_event_paranoid is not taken > into account by perfmon_capable(): > > $ perf record -e arm_spe/pa_enable/ > > Error: > Access to performance monitoring and observability operations is > limited. Consider adjusting /proc/sys/kernel/perf_event_paranoid > setting ... > > Suggested-by: Al Grant > Signed-off-by: James Clark > --- > Changes since v1: > > * Export perf_allow_kernel() instead of sysctl_perf_event_paranoid > > drivers/perf/arm_spe_pmu.c | 9 ++++----- > include/linux/perf_event.h | 8 +------- > kernel/events/core.c | 9 +++++++++ > 3 files changed, 14 insertions(+), 12 deletions(-) > > diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c > index 9100d82bfabc..3569050f9cf3 100644 > --- a/drivers/perf/arm_spe_pmu.c > +++ b/drivers/perf/arm_spe_pmu.c > @@ -41,7 +41,7 @@ > > /* > * Cache if the event is allowed to trace Context information. > - * This allows us to perform the check, i.e, perfmon_capable(), > + * This allows us to perform the check, i.e, perf_allow_kernel(), > * in the context of the event owner, once, during the event_init(). > */ > #define SPE_PMU_HW_FLAGS_CX 0x00001 > @@ -50,7 +50,7 @@ static_assert((PERF_EVENT_FLAG_ARCH & SPE_PMU_HW_FLAGS_CX) == SPE_PMU_HW_FLAGS_C > > static void set_spe_event_has_cx(struct perf_event *event) > { > - if (IS_ENABLED(CONFIG_PID_IN_CONTEXTIDR) && perfmon_capable()) > + if (IS_ENABLED(CONFIG_PID_IN_CONTEXTIDR) && !perf_allow_kernel(&event->attr)) > event->hw.flags |= SPE_PMU_HW_FLAGS_CX; The rationale for this change in the commit message is because other drivers gate PERF_SAMPLE_PHYS_ADDR on perf_allow_kernel(). However, putting the PID in contextidr doesn't seem to have anything to do with that... > } > > @@ -745,9 +745,8 @@ static int arm_spe_pmu_event_init(struct perf_event *event) > > set_spe_event_has_cx(event); > reg = arm_spe_event_to_pmscr(event); > - if (!perfmon_capable() && > - (reg & (PMSCR_EL1_PA | PMSCR_EL1_PCT))) > - return -EACCES; > + if (reg & (PMSCR_EL1_PA | PMSCR_EL1_PCT)) Similarly here. What does the physical counter have to do with physical address sampling other than sharing the word "physical"? Will