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 83186C43334 for ; Mon, 20 Jun 2022 13:19:48 +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=ijBmSAZ7oyEQ08JnkIBpsajdY4uNf0v401+OXQxXqq4=; b=izlLCsyl3XY8MO 7eqYvtOBHEbO0F72V1wtCmD+SvH03BrXbVaCY3AmLFcZmRToyomkL1/Gx0yG9vp6d3MSUbDabeST5 qhT26yLcQuimExnztyFB7jJfp01876zyg71KXKVdrJPmwN5+4RCVFXDDo3omyuCsVhR0UAUHOTWww uHaomjHZ+Q9Vk8qHkO4SyK8uvF21qmwPmNQt0rhS/+evtAQZDmeHGE7WOyCD5oflFZ4xgEb3R4sMz qiqphZ0jDPWhWzvmrtkm5ebKXQr8o8xw2NklVW9AvdMriXzwYyk8peWaDL3WZDUzpQzDNsWM0HMZR yDeMPYwHpCnP8X70Y8zA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3HIa-000lgc-C0; Mon, 20 Jun 2022 13:18:36 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3Gvk-000aVG-88 for linux-arm-kernel@lists.infradead.org; Mon, 20 Jun 2022 12:55:01 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BBB0E614D5; Mon, 20 Jun 2022 12:54:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 676EDC341CE; Mon, 20 Jun 2022 12:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655729699; bh=+4I71YYvIrjC3XnZ5kCSy5M4jGA+CIeBlqzuoP2WDZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YR7te2/9/o47WK2nsxWYExn8SmODCll4zjdYV015l38j6y5IIf2j7husrqz3Nkk83 E8c5Rg4Lm52LzetTrM0c/EtAmHEFI4V/AduNVsUnu07ajeuGsxs5Gw2tXAPj0hVumf RhewHmCRWbXXY6le17N6/mt8uE61aHcc7dzYiSgclbDM5W2xGntnsyIKByAACjvtfr QDBNeZRkx1sPFqgzJ2cG7nUN9w6ZmRD6Cq1sOSCnPcJfLi5Gml+4bhtTvBgnHX0uzr S6XCklbFn9TZ56JHXgSnGpO0V/hfVC54aIZbIuUUCiPiYbNfTc71mRLe+8ZMIvbC30 UblKRZjr1hwrw== From: Mark Brown To: Catalin Marinas , Will Deacon , Eric Biederman , Kees Cook Cc: Suzuki K Poulose , Szabolcs Nagy , linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v2 1/4] arm64/cpufeature: Store elf_hwcaps as an array rather than unsigned long Date: Mon, 20 Jun 2022 13:54:48 +0100 Message-Id: <20220620125451.653507-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220620125451.653507-1-broonie@kernel.org> References: <20220620125451.653507-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3727; h=from:subject; bh=+4I71YYvIrjC3XnZ5kCSy5M4jGA+CIeBlqzuoP2WDZo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBisG4XhWj7cp7DPZrv16jUYG5vB/s6irTibMOtM5iU MHlGG9WJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYrBuFwAKCRAk1otyXVSH0PS3B/ sHQKOSoBr72ViTM6V3exA8PUf7nom+sqga58379PBlV+H4f6y0sj63DdvHb+Sx+io70VcZ3ywmlF2x /iooIcLuGIjm+Kj8b/S3UqYmpGSyKHslmY5XkI06gKeeh+dVeNigSosuCcYdR+A3Cqn6TnKiE+pF3h EM8aJVtRPte1cVXNk3QrMdbxnxf7VMkplWzwFGLj4ShtZ4DpSMKEhcKwJ6cHR7VnJb3sxvEFjM4dVa HIYAk77IEU9SeARyr6Eql3FLq+fqZpZkXJvgEWhqR+oqg3Dz42wxEkidOnGgnWwJYhneYgTpJ6w1Yy Z2wWCKLtfjhGqRH6V8RFJ6Q+COBLhY X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220620_055500_475146_906EDDE8 X-CRM114-Status: GOOD ( 17.34 ) 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 When we added support for AT_HWCAP2 we took advantage of the fact that we have limited hwcaps to the low 32 bits and stored it along with AT_HWCAP in a single unsigned integer. Thanks to the ever expanding capabilities of the architecture we have now allocated all 64 of the bits in an unsigned long so in preparation for adding more hwcaps convert elf_hwcap to be an array instead. There should be no functional change from this patch. Signed-off-by: Mark Brown --- arch/arm64/include/asm/cpufeature.h | 2 ++ arch/arm64/include/asm/hwcap.h | 4 +++- arch/arm64/kernel/cpufeature.c | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 14a8f3d93add..84756c660b5e 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -11,6 +11,8 @@ #include #include +/* Note that bits 62 and 63 of each AT_HWCAP are reserved */ +#define CPU_FEATURES_PER_HWCAP 32 #define MAX_CPU_FEATURES 64 #define cpu_feature(x) KERNEL_HWCAP_ ## x diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h index aa443d8f8cfb..e0054c7b3a98 100644 --- a/arch/arm64/include/asm/hwcap.h +++ b/arch/arm64/include/asm/hwcap.h @@ -41,6 +41,8 @@ #ifndef __ASSEMBLY__ #include +#define KHWCAP_OFFSET(n) ((n - 1) * CPU_FEATURES_PER_HWCAP) + /* * For userspace we represent hwcaps as a collection of HWCAP{,2}_x bitfields * as described in uapi/asm/hwcap.h. For the kernel we represent hwcaps as @@ -85,7 +87,7 @@ #define KERNEL_HWCAP_PACA __khwcap_feature(PACA) #define KERNEL_HWCAP_PACG __khwcap_feature(PACG) -#define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + 32) +#define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + KHWCAP_OFFSET(2)) #define KERNEL_HWCAP_DCPODP __khwcap2_feature(DCPODP) #define KERNEL_HWCAP_SVE2 __khwcap2_feature(SVE2) #define KERNEL_HWCAP_SVEAES __khwcap2_feature(SVEAES) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 8d88433de81d..1a8f60a6661e 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -91,7 +91,7 @@ #include /* Kernel representation of AT_HWCAP and AT_HWCAP2 */ -static unsigned long elf_hwcap __read_mostly; +static unsigned long elf_hwcap[MAX_CPU_FEATURES / CPU_FEATURES_PER_HWCAP] __read_mostly; #ifdef CONFIG_COMPAT #define COMPAT_ELF_HWCAP_DEFAULT \ @@ -3098,14 +3098,22 @@ static bool __maybe_unused __system_matches_cap(unsigned int n) void cpu_set_feature(unsigned int num) { - WARN_ON(num >= MAX_CPU_FEATURES); - elf_hwcap |= BIT(num); + int i = num / CPU_FEATURES_PER_HWCAP; + int bit = num % CPU_FEATURES_PER_HWCAP; + + WARN_ON(i >= ARRAY_SIZE(elf_hwcap)); + + elf_hwcap[i] |= BIT(bit); } bool cpu_have_feature(unsigned int num) { - WARN_ON(num >= MAX_CPU_FEATURES); - return elf_hwcap & BIT(num); + int i = num / CPU_FEATURES_PER_HWCAP; + int bit = num % CPU_FEATURES_PER_HWCAP; + + WARN_ON(i >= ARRAY_SIZE(elf_hwcap)); + + return elf_hwcap[i] & BIT(bit); } EXPORT_SYMBOL_GPL(cpu_have_feature); @@ -3116,12 +3124,12 @@ unsigned long cpu_get_elf_hwcap(void) * note that for userspace compatibility we guarantee that bits 62 * and 63 will always be returned as 0. */ - return lower_32_bits(elf_hwcap); + return elf_hwcap[0]; } unsigned long cpu_get_elf_hwcap2(void) { - return upper_32_bits(elf_hwcap); + return elf_hwcap[1]; } static void __init setup_system_capabilities(void) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel