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 366E4C43334 for ; Thu, 16 Jun 2022 11:29:28 +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=mRSJtfjFC40oHU4gq8xRoV/4twH1pByEcBQ20SOv1RY=; b=TFgC/JgxmzqXbZ GAmkastmJYlbPVao+Hiwjq6W5W+WSPifc59WcqqQxiZG6rJ0vXoUtwHRzd0W+yKdSMFWhOQiDbjNQ u3Er85GAtL6vY0eChkND0iYMDg1A73KC54qhCkDULq/PrMCOq+dA8JeOw/3SnV1xcv8beoF4PER+D 3ZJ+KO2k9X5dKCE+i4dnwLfXFQtdQ2tRSvjEZI+TLIuBoNXjOX0jvq0/wu+KEqIQpH6Pzq09KS2XP aVCjitS4zTugVrHC4OXGabEjKGPA8YwggVq36bZrkq7ry+pBGJD2o7XgsD32uVDn1k4EKtHPjeCb1 ly7uLSK4y11hH4YYR5yQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1nfr-0024lz-DW; Thu, 16 Jun 2022 11:28:31 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1nfW-0024hA-Nu for linux-arm-kernel@lists.infradead.org; Thu, 16 Jun 2022 11:28:19 +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 ams.source.kernel.org (Postfix) with ESMTPS id 36194B82368; Thu, 16 Jun 2022 11:28:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1657DC341C8; Thu, 16 Jun 2022 11:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655378887; bh=xFpk0cCpUtHjsbwKbcNfMsBd2gddb0U8B8WJ1BHqFCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FJ0euP+lcb3fWrWm6AenWF3sZgn/1t9xjFbG4slCtD6gtQF2sHZzH3E/EUmck8TU3 S/QlPWliJgMSV0hywrBNKM7wfwwCkzO9umj+AkwuU5NhUoi1Kal6WadhUXe9dVvRzI FOoZMj07k4+Nz3/pYie6ouahD95EMS3NkqJe9kDauo56gXWoNS2jOZC+Baok2/yQxd by8XXlIJTcISuYGQGsVMrOzre5yTHpJ9R11QiPNrEa1zQTPAQMIb7SalWXAmbcLqun 5Rcv6YdhWcmdG5TeQHpaD4jpCll3RwZvVio0Wc2hIoUiK3LicCje8f2GAVHxEUo5ID u9c9vjbA1BKZw== 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 v1 1/4] arm64/cpufeature: Store elf_hwcaps as an array rather than unsigned long Date: Thu, 16 Jun 2022 12:18:15 +0100 Message-Id: <20220616111818.724230-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220616111818.724230-1-broonie@kernel.org> References: <20220616111818.724230-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3765; h=from:subject; bh=xFpk0cCpUtHjsbwKbcNfMsBd2gddb0U8B8WJ1BHqFCQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiqxF0znZl4HuJpaPrrnfSJ09MHm1zDaWCtcnbaXEB HgmuoseJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYqsRdAAKCRAk1otyXVSH0K+IB/ sGHHSpdnBOfx9iX1Wc94DCdVuSEQu4Nl7zxnNvlgibzjPkK3RAP0TDzHFqdSWA1iz80KuTl9NEXZyK GPoK+QSiNQhWQpLgASQ+byvI+hmI8ewKmfQeEdpysiLI2LPo0xLBgsGlLDNqKctbHoK8DDu9kW9fRu uVLVYWbUWNkPA7VgFhl5ct0oye4V7PlMEcJNlcO25ZyIcMgQlGWgAj3VIqbF9veOkGZLonKu8UeVRu ie00l/I+WSjy3G1jUTd6g3PTYch3NNmTLttnAimeB1t6Sql8v8Vy23P90l8PgVwfIOQKeveoYBt7mK D+C+bt0eFBai4okNYD0Qlutq5dKntz 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-20220616_042811_155227_6B4B5339 X-CRM114-Status: GOOD ( 17.47 ) 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 42ea2bd856c6..3ae8eb4a9446 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 \ @@ -3106,15 +3106,23 @@ 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); } EXPORT_SYMBOL_GPL(cpu_set_feature); 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); @@ -3125,12 +3133,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