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 43591C433EF for ; Wed, 29 Jun 2022 12:24:26 +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=V3nmc4EnujDEZReSlFnKdwHFJb0tXGW6IcT9LxTCxMw=; b=47H09trcXeLnsL Rt+sqfMw3YyukZYLveN3X/9ZUm3IUc8ugYfYG4e4kdPMQwujFYG85bhBbll7yrGovi2wW6gquLX+D oV25vwkuLAG5pUc9RHiLrWJkdlGOCDj22vjztvORia7503PUI1HJgEcffo2dEQsgDkMKMecGIScuc mnvqzaQ+HdNx6avjFCSccybC7TAqjfvRynCyKL/PdYrpivQLY9qjC7Xgrv0iqgY6puUidkz4u0F++ 2pASviB3s85WrGI0yfTETivTwwaKOGvNGT7unzCsqiquEAK0ifRAMUrlavoMH15+tUuuv4MG+Wot9 7Uy3OeL82MeE0Cjg8qzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6Wiw-00BmNY-UW; Wed, 29 Jun 2022 12:23:15 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6Whk-00Blug-D4 for linux-arm-kernel@lists.infradead.org; Wed, 29 Jun 2022 12:22:05 +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 17B1361BFE; Wed, 29 Jun 2022 12:21:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2D9DC341CC; Wed, 29 Jun 2022 12:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656505318; bh=h8y1fgwgDdWDYt4pvtxuHIFSPLHGSZluW/hTNEoo/7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qd21Esnrmj4mqquKpHYxRiu2/IFJG76zSvmmUk3pgvgVq/f+VORb4EcwO4FLrzLCX k40GFUlxjT63eO+T0TPE3s8rtm3XdOfVGjgxho2ItXokW4q93sbbo23Iju6jNyUR4O sZzoljOF89qaIg0krgcmWbKQ84KCAFAXV7CQ6G7Jc6ZRitxo9t7DTC4EBgmBcKZCb6 ffTAQ+nhOt5JPRdwu6SzrhqA8Pcbpo2zIf6fR3ZRmBr8+SvLa0vcd9+iDpsJHWg2qV mn6gc23AWE9hazebF09Ih/vfl+/xLlk/jQkYVMR1OC1fRGqbXTB/Hm8NmWcSFbp7XX A00MN2lxn5+rg== 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 v3 1/4] arm64/cpufeature: Store elf_hwcaps as an array rather than unsigned long Date: Wed, 29 Jun 2022 13:20:44 +0100 Message-Id: <20220629122047.799324-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629122047.799324-1-broonie@kernel.org> References: <20220629122047.799324-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3856; h=from:subject; bh=h8y1fgwgDdWDYt4pvtxuHIFSPLHGSZluW/hTNEoo/7U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBivEObXDNbhmPTtOwSobEBV0BOlZxGw5IeomZ3d9OB Z3yRJBWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYrxDmwAKCRAk1otyXVSH0DQCB/ 98d+lqyAHsrd7rn8FWKGQpO0VQcGqUDH14psZzoQs0vdV6nE36qa5PRcvgEOJXvG/to0VU8cSk2j27 /EbtM3crFCqXqt9IP2o7C/5DBjqn1hYbP0/6cPNh4sRz5aLNzgHEicw4jRyFhV3IwCOE+s+IP0mmS7 LlKY6NiPCvxZ9fsI2K2Im5A6gI6Bnpz05PmMRN5gXg9X/43NKQWnoHcYe1FumjUCumCpbkOeSIlGwa De2xtiVAOPhOzj4bwYiSCygwh3UKMRq83ZffcDi18/rl5xpEZZQq0EVrIJMhO+WI/AuavTisOo2qEb acM8ZaJCZsX5vjVIwZSrNh/C6FvoGC 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-20220629_052200_580474_BA9E44E5 X-CRM114-Status: GOOD ( 18.79 ) 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 | 6 ++++++ arch/arm64/include/asm/hwcap.h | 4 +++- arch/arm64/kernel/cpufeature.c | 22 +++++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 14a8f3d93add..6c0284ca703e 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -11,6 +11,12 @@ #include #include +/* + * To support potential future 32 bit only ABIs and/or libc usage we + * currently only allocate the bottom 32 bits. Bits 62 and 63 of + * AT_HWCAP are reserved for glibc. + */ +#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