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 D3B9FC433EF for ; Thu, 7 Jul 2022 11:39:34 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OVHIaI25EAy3H2lFELjq9zJ5SGExu+h9OxvVNfLTiNw=; b=PJ271y5HOYgeaW 6ZwPOipNKn1zGX0o+w3trFGQwkxrThq/oIawWI72Y/zuZLipZmraboJ0wYWwTuwoyP8c7wZUAx2/W CORiSjm+X8Qid1DqyL8l0rDX2k/q4Y3dUAYQCWT7WHSk7cGTFRkDG/aMnbiNBFRjDdI0QN5UsQkiw ImfdD2nUJWYs4ahnvvYy7l70TNRN3jMC9fC4BTB0w+2yQ6srTlCn79igufXGBZffPrCRYrcsTtFyT UUTI0Om84/8s5TaNn2YJ+HhwqR1y9BJDzndHAW3Cwc4FHd7lYGQd8XwxTLdKXZtqZcECYlYXeaFMA 6+dJubS2NyAfbrXOxc7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9Ppl-00FqAb-W5; Thu, 07 Jul 2022 11:38:14 +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 1o9Ppi-00Fq9n-JH for linux-arm-kernel@lists.infradead.org; Thu, 07 Jul 2022 11:38:12 +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 DE27AB82113; Thu, 7 Jul 2022 11:38:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 628FEC3411E; Thu, 7 Jul 2022 11:38:04 +0000 (UTC) Date: Thu, 7 Jul 2022 12:37:58 +0100 From: Catalin Marinas To: Mark Brown Cc: Will Deacon , Suzuki K Poulose , Szabolcs Nagy , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v5 2/3] arm64/cpufeature: Store elf_hwcaps as a bitmap rather than unsigned long Message-ID: References: <20220707103632.12745-1-broonie@kernel.org> <20220707103632.12745-3-broonie@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220707103632.12745-3-broonie@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220707_043811_004684_EDD27918 X-CRM114-Status: GOOD ( 26.09 ) 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 On Thu, Jul 07, 2022 at 11:36:31AM +0100, Mark Brown wrote: > 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 a > bitmap instead, with 64 bits allocated to each AT_HWCAP. > > 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 | 2 +- > arch/arm64/kernel/cpufeature.c | 12 +++++------- > 3 files changed, 7 insertions(+), 9 deletions(-) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index 14a8f3d93add..7abd6c0fa53d 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -11,7 +11,7 @@ > #include > #include > > -#define MAX_CPU_FEATURES 64 > +#define MAX_CPU_FEATURES 128 Should this be (32 + 64)? I guess it's easier as you did since we have 128 bits in total, only that we reserved the top 32 in ELF_HWCAP. > #define cpu_feature(x) KERNEL_HWCAP_ ## x > > #ifndef __ASSEMBLY__ > diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h > index aa443d8f8cfb..9b5fdc114f8c 100644 > --- a/arch/arm64/include/asm/hwcap.h > +++ b/arch/arm64/include/asm/hwcap.h > @@ -85,7 +85,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) + 64) > #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..5ba226f3721c 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 DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly; > > #ifdef CONFIG_COMPAT > #define COMPAT_ELF_HWCAP_DEFAULT \ > @@ -3098,14 +3098,12 @@ 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); > + set_bit(num, elf_hwcap); > } > > bool cpu_have_feature(unsigned int num) > { > - WARN_ON(num >= MAX_CPU_FEATURES); > - return elf_hwcap & BIT(num); > + return test_bit(num, elf_hwcap); > } > EXPORT_SYMBOL_GPL(cpu_have_feature); > > @@ -3116,12 +3114,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]; > } This is fine on the assumption that DECLARE_BITMAP is always an array of longs. I couldn't see any documentation on this but at least the set_bit() etc. API only works on 'long *' pointers. Reviewed-by: Catalin Marinas _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel