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 AA489C52D7C for ; Fri, 23 Aug 2024 15:03:49 +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=LKwXGA/gRysHl9fqV+0JbFIrwJa0GuQKgUXyf7Mb+bw=; b=H/Lu4CcGp7C27jq7fpl9Ptd6Hp 0DTpQUBFoWh4FzlXKfUHwAzH97d4L60JSRJkbKpRrSWqk+mpCP6Ibza8BjkTEufrH7K2g7X0NldtI jR+WbCAR9OEtlRZB2UqJW7rJZ2QP3Vb0vmCZdUvTzciHMJuEIFSlmrME4KO/9ATiDOJz3G9XdzBPN +Io4ovViOM5iV66aNGSz08h1VAw/r+1JsMQVNGU/4VkxD9gToxLV8bnWics5pB+NPr5IygrHIzq29 /4DqtpWUT16w9Nq1bDeMJciqOOa0PXckN8FkHm5Dq93c1NlMK/xI3eBUv8pU8mxcT8trmMBf+sL0r sM22t3sQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1shVp6-0000000HDFk-370o; Fri, 23 Aug 2024 15:03:32 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1shVoK-0000000HD6e-1Vmo for linux-arm-kernel@lists.infradead.org; Fri, 23 Aug 2024 15:02:46 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 9CE71A426CC; Fri, 23 Aug 2024 15:02:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6192CC32786; Fri, 23 Aug 2024 15:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724425363; bh=rEyyg+xn4o9Md6QUaT9B5lyqywHCgzfMkFreOWkBSaE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gtSTONTeITfK0dOc6MCAhM9vcByK8VWvN2cCbvfjVDscvcWxc802hhSDVC2b2GZ49 u79Jn/w6WBiAd8cphQmdjINCjkQMNq4mFV2IfJFM6+2W18G1O7jPp9WtDzX6AR93BA CTiVYWO0Qv0sJsRNxVSdOd9Jix/WSxiygG1nLALDu9yZCSNJikW1jIDJxX4B9wgKbF WtXv8KAaUbIQET1ru+UwkgcgHW1coc6cmxKpD+yXQOAxJFN4TVZK5K741bnESYLsy4 dayDnP4H+rJ0ALRo5JZcEGFIR7QftTpFnCafbz6FA8GvGyQojuDoWjIRUQZlWX7uI1 bwPedPz2GhB2A== Date: Fri, 23 Aug 2024 16:02:36 +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: <20240823150236.GA32691@willie-the-truck> References: <20240807155153.2714025-1-james.clark@linaro.org> <20240816124459.GA24323@willie-the-truck> <177108bc-2bdd-4914-97cc-ee09dfef75c3@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <177108bc-2bdd-4914-97cc-ee09dfef75c3@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-20240823_080245_009030_C75956CD X-CRM114-Status: GOOD ( 37.22 ) 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 Fri, Aug 16, 2024 at 02:27:19PM +0100, James Clark wrote: > > > On 16/08/2024 1:45 pm, Will Deacon wrote: > > 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... > > > > That is true, I suppose I was thinking of two reasons to do it this way that > I didn't really elaborate on: > > #1 because context IDs and physical timestamps didn't seem to be any more > sensitive than physical addresses, so it wouldn't make sense for them to > have a stricter permissions model than addresses. > > #2 (although this is indirect and not really related to the driver) but Perf > will still print the misleading warning when physical timestamps are > requested. So some other fix would eventually have to be made for that. > > I'm not sure if you are objecting to the permissions change for the other > two things, or it's just a lack of reasoning in the commit message? I'm just objecting to the rationale in the commit message not being applicable to some of the changes made in the code. A much better rationale to use perf_allow_kernel() is because of its integration with the LSM hooks. Will