From patchwork Wed Aug 7 10:54:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13756146 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 04A74C3DA7F for ; Wed, 7 Aug 2024 10:56:54 +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: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=g1CfpUgJXS7BrN7tAFA68qWsxl5eht2ofVsjd8s8rPw=; b=vT0OclHSvC9CxeRIdZstPTfiye gv8gX4Fq2jT96j7CCtbXva/4YnBs434GrbTdI++kUQOJYYhrk0Y50qIIw3/dsMbqi70WFPbvULgKx PswYf+NhuDMly91aIJ7c9GK5HT8eKMUPGX2S+eyAnjUpQb+Kn56EJeJMOefvT1pB1tO1p9XvqRVL5 5MGVHu9PcDKd5zs5HAWlvjCxbo2YaCIAYTFYJ+HknH+PopQc5yq/+tQ4rabvwoz7Goop8yXfIgF2w W/S1/K/YgMQ9RNpBnR3qr/NDpzORWCJqjjXKku7g9Vjdz/6z9sWA+0tK4mWWP3PaZWn5MhFwnqP5V e/gYBknQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbeLR-00000004n4P-0Klp; Wed, 07 Aug 2024 10:56:41 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbeKV-00000004mtz-0R32 for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 10:56:08 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-36887ca3da2so933251f8f.2 for ; Wed, 07 Aug 2024 03:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723028141; x=1723632941; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=g1CfpUgJXS7BrN7tAFA68qWsxl5eht2ofVsjd8s8rPw=; b=Thtzn+PBnAVbTAMw057uCsQeek3um7AS8Kb6TD/Cujinn0CPe3E9eyBK8kF+Y6d6kN 266C7KUQIO8py6SULtIjthjLfFhWGPIrm+KkufZUpuDccLxgSNfx8qfnWI8NbBuyXLiB BHhgiYI7ecUL6bRxohSps5hSZXEcK9XPazn6V7iAUPbk6qpUrXdKkbHM8Pj9d/E7VKgP jmdjOMAFlvyzqbq5/RUTnaeecA7b32bzMdOLdRTlI1ctQRLAvnHWWn2VZE0kz9+9fLmf U4LP/3DzirDULIuaY4+eSRYb21DuaWp+5qDv/LSqrU3WMmQ6ESskn1lnFsDUpQj6b6+s 4QPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723028141; x=1723632941; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g1CfpUgJXS7BrN7tAFA68qWsxl5eht2ofVsjd8s8rPw=; b=OEYLWrLYVqYQ2psMrr3Dh3rE3B497/jRD1hRztzYLOKwhj3QQZ5r/5IqmZerZqELGJ VPr52GiJBVBdEOoqP3IWw7wUvUXylivzVQfV1h84wxvb5DVR//AZ6OXTY1HJnIML6dDe IkVzctUFXqkVFTxd84slibq2H7JNHxMZ1IIdSazDDOaNsJO8X+pzkHr//5IXlArMfu55 i1UL01UH2Z6WlbKnus7B8ZH7J/XjZqKaiNY7vpoEMKonRX7q3NZPD5p33v+PEdKC33sq UwLiSM1AFh7WlLeqm+xpyVXBWHaHeNKThGRX7n6lDmMKGVNNx1uZggLKzSbe1iu5AAhS kRrA== X-Gm-Message-State: AOJu0YxRD+mjdkDGWEFo2avjz5na1jQjSHPN8rkZDZ9V8tPZeQZNBLzM jZQag9WDOJH9Ol3CWkadMjEjwI1KuWxOImNHw+y56h+OH5Li8UxxnmZNSroiwzFfRnV7npoFA0E hmxo= X-Google-Smtp-Source: AGHT+IGt+z3jjIQ5JZ71Sm7Hm7Y023gn/0oFOumyjerqnx97PjhdWlctYsTLYdnmPaqcAi0kbDv17g== X-Received: by 2002:a05:6000:8:b0:368:747c:5a04 with SMTP id ffacd0b85a97d-36bbc10f6c5mr9798605f8f.25.1723028141352; Wed, 07 Aug 2024 03:55:41 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbd059891sm15644743f8f.73.2024.08.07.03.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 03:55:41 -0700 (PDT) From: James Clark To: linux-arm-kernel@lists.infradead.org Cc: James Clark , Al Grant , Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Paul Moore , James Morris , "Serge E. Hallyn" , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH] drivers/perf: arm_spe: Use perf_allow_kernel() for permissions Date: Wed, 7 Aug 2024 11:54:41 +0100 Message-Id: <20240807105441.2156738-1-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_035543_168959_1CA9C298 X-CRM114-Status: GOOD ( 17.72 ) 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 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 --- drivers/perf/arm_spe_pmu.c | 9 ++++----- kernel/events/core.c | 1 + security/security.c | 1 + 3 files changed, 6 insertions(+), 5 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; } @@ -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)) + return perf_allow_kernel(&event->attr); return 0; } diff --git a/kernel/events/core.c b/kernel/events/core.c index aa3450bdc227..4a69583e329a 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -417,6 +417,7 @@ static struct kmem_cache *perf_event_cache; * 2 - disallow kernel profiling for unpriv */ int sysctl_perf_event_paranoid __read_mostly = 2; +EXPORT_SYMBOL_GPL(sysctl_perf_event_paranoid); /* Minimum for 512 kiB + 1 user control page */ int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */ diff --git a/security/security.c b/security/security.c index 8cee5b6c6e6d..70cc9206e902 100644 --- a/security/security.c +++ b/security/security.c @@ -5610,6 +5610,7 @@ int security_perf_event_open(struct perf_event_attr *attr, int type) { return call_int_hook(perf_event_open, attr, type); } +EXPORT_SYMBOL_GPL(security_perf_event_open); /** * security_perf_event_alloc() - Allocate a perf event LSM blob