From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E56E221A01; Mon, 15 Jan 2024 23:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uvaND2n0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 557ABC43399; Mon, 15 Jan 2024 23:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705361248; bh=/mtGC3dAeGirAxx76w0zBinixbRGMNd/NfUpbG8wlkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uvaND2n01NQXbjcusfoOfiUXhaeN/6tjaYSFbmQe7fZhAvWX74gCml0UlfU/4TjFT CXUExBJFyevFjmOTgby2p7jKv8b3mtAHiisjvNFYX/xgC8Iv/p5WVJQAMHeZ8g3bBd MS2uU7PSU5EvaNUYIkMNVywFs5HwWizybohISHaJkpBnbLwRGoShN+1KI3jQrZzPVa ssnuMDZO7UJy1eNvpeQWxAWv4PFASWN81bChz0b4Jnfao6WpLxjE7SNB+s5rvKduur jcK7TOZeq+NIlftJQ7hDGpMSG74Hb9K785+W5kYtfHnWRe6EsVB42JgURh/Hn2sKFk 7UlEz315KGACQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mark Rutland , Will Deacon , Sasha Levin , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 04/12] drivers/perf: pmuv3: don't expose SW_INCR event in sysfs Date: Mon, 15 Jan 2024 18:26:49 -0500 Message-ID: <20240115232718.209642-4-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115232718.209642-1-sashal@kernel.org> References: <20240115232718.209642-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.147 Content-Transfer-Encoding: 8bit From: Mark Rutland [ Upstream commit ca6f537e459e2da4b331fe8928d1a0b0f9301f42 ] The SW_INCR event is somewhat unusual, and depends on the specific HW counter that it is programmed into. When programmed into PMEVCNTR, SW_INCR will count any writes to PMSWINC_EL0 with bit n set, ignoring writes to SW_INCR with bit n clear. Event rotation means that there's no fixed relationship between perf_events and HW counters, so this isn't all that useful. Further, we program PMUSERENR.{SW,EN}=={0,0}, which causes EL0 writes to PMSWINC_EL0 to be trapped and handled as UNDEFINED, resulting in a SIGILL to userspace. Given that, it's not a good idea to expose SW_INCR in sysfs. Hide it as we did for CHAIN back in commit: 4ba2578fa7b55701 ("arm64: perf: don't expose CHAIN event in sysfs") Signed-off-by: Mark Rutland Cc: Will Deacon Link: https://lore.kernel.org/r/20231204115847.2993026-1-mark.rutland@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/perf_event.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index b4044469527e..c77b9460d63e 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -168,7 +168,11 @@ armv8pmu_events_sysfs_show(struct device *dev, PMU_EVENT_ATTR_ID(name, armv8pmu_events_sysfs_show, config) static struct attribute *armv8_pmuv3_event_attrs[] = { - ARMV8_EVENT_ATTR(sw_incr, ARMV8_PMUV3_PERFCTR_SW_INCR), + /* + * Don't expose the sw_incr event in /sys. It's not usable as writes to + * PMSWINC_EL0 will trap as PMUSERENR.{SW,EN}=={0,0} and event rotation + * means we don't have a fixed event<->counter relationship regardless. + */ ARMV8_EVENT_ATTR(l1i_cache_refill, ARMV8_PMUV3_PERFCTR_L1I_CACHE_REFILL), ARMV8_EVENT_ATTR(l1i_tlb_refill, ARMV8_PMUV3_PERFCTR_L1I_TLB_REFILL), ARMV8_EVENT_ATTR(l1d_cache_refill, ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL), -- 2.43.0 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 B510AC3DA79 for ; Mon, 15 Jan 2024 23:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YHFqLgyi93rBWnRF2LfL3hVvvFQnt2d5t33irisXytc=; b=szXVGiY1rEP85U OMta03/TTbmNmqRmUb+pz/XI82MxrfH5AIkNdIiGDr6OBMhQHblhmuyXyMp3VyqW+AOMChon12NC1 q+ztO0X4dQWRde4FUNHVK5pREAYdEiYSJqoj2c2Ra+8YX1/4KpylThhQLp4r40nu5f9u+SyutN+oY TMJi2ObGuA2un+P7n1v/S1qkX+JO7Ru3ZP0CKn9JGIEmqNqYBasvlcdLMjGKoSCQ3l2VLBWHGvFv+ p7JNnBsxL+MPZeDYPm6+kdU/3LtpfeLfr4qXBOqUo5jr4Dv5bMzoXKoijNExzdqRf4RuF3r/bWCAv IbpDBLMCM7+PwQH+GHzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPWMe-00AMaF-2k; Mon, 15 Jan 2024 23:27:32 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rPWMb-00AMYO-15 for linux-arm-kernel@lists.infradead.org; Mon, 15 Jan 2024 23:27:32 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C412F60FE0; Mon, 15 Jan 2024 23:27:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 557ABC43399; Mon, 15 Jan 2024 23:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705361248; bh=/mtGC3dAeGirAxx76w0zBinixbRGMNd/NfUpbG8wlkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uvaND2n01NQXbjcusfoOfiUXhaeN/6tjaYSFbmQe7fZhAvWX74gCml0UlfU/4TjFT CXUExBJFyevFjmOTgby2p7jKv8b3mtAHiisjvNFYX/xgC8Iv/p5WVJQAMHeZ8g3bBd MS2uU7PSU5EvaNUYIkMNVywFs5HwWizybohISHaJkpBnbLwRGoShN+1KI3jQrZzPVa ssnuMDZO7UJy1eNvpeQWxAWv4PFASWN81bChz0b4Jnfao6WpLxjE7SNB+s5rvKduur jcK7TOZeq+NIlftJQ7hDGpMSG74Hb9K785+W5kYtfHnWRe6EsVB42JgURh/Hn2sKFk 7UlEz315KGACQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mark Rutland , Will Deacon , Sasha Levin , peterz@infradead.org, mingo@redhat.com, acme@kernel.org, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 04/12] drivers/perf: pmuv3: don't expose SW_INCR event in sysfs Date: Mon, 15 Jan 2024 18:26:49 -0500 Message-ID: <20240115232718.209642-4-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115232718.209642-1-sashal@kernel.org> References: <20240115232718.209642-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.147 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240115_152729_419521_6F8E2024 X-CRM114-Status: GOOD ( 11.81 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mark Rutland [ Upstream commit ca6f537e459e2da4b331fe8928d1a0b0f9301f42 ] The SW_INCR event is somewhat unusual, and depends on the specific HW counter that it is programmed into. When programmed into PMEVCNTR, SW_INCR will count any writes to PMSWINC_EL0 with bit n set, ignoring writes to SW_INCR with bit n clear. Event rotation means that there's no fixed relationship between perf_events and HW counters, so this isn't all that useful. Further, we program PMUSERENR.{SW,EN}=={0,0}, which causes EL0 writes to PMSWINC_EL0 to be trapped and handled as UNDEFINED, resulting in a SIGILL to userspace. Given that, it's not a good idea to expose SW_INCR in sysfs. Hide it as we did for CHAIN back in commit: 4ba2578fa7b55701 ("arm64: perf: don't expose CHAIN event in sysfs") Signed-off-by: Mark Rutland Cc: Will Deacon Link: https://lore.kernel.org/r/20231204115847.2993026-1-mark.rutland@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/perf_event.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index b4044469527e..c77b9460d63e 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -168,7 +168,11 @@ armv8pmu_events_sysfs_show(struct device *dev, PMU_EVENT_ATTR_ID(name, armv8pmu_events_sysfs_show, config) static struct attribute *armv8_pmuv3_event_attrs[] = { - ARMV8_EVENT_ATTR(sw_incr, ARMV8_PMUV3_PERFCTR_SW_INCR), + /* + * Don't expose the sw_incr event in /sys. It's not usable as writes to + * PMSWINC_EL0 will trap as PMUSERENR.{SW,EN}=={0,0} and event rotation + * means we don't have a fixed event<->counter relationship regardless. + */ ARMV8_EVENT_ATTR(l1i_cache_refill, ARMV8_PMUV3_PERFCTR_L1I_CACHE_REFILL), ARMV8_EVENT_ATTR(l1i_tlb_refill, ARMV8_PMUV3_PERFCTR_L1I_TLB_REFILL), ARMV8_EVENT_ATTR(l1d_cache_refill, ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL), -- 2.43.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel