Skip to content

Commit 60c868e

Browse files
brooniewilldeacon
authored andcommitted
arm64/cpufeature: Store elf_hwcaps as a bitmap rather than unsigned long
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 <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent d3e4a9d commit 60c868e

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

arch/arm64/include/asm/cpufeature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <asm/hwcap.h>
1212
#include <asm/sysreg.h>
1313

14-
#define MAX_CPU_FEATURES 64
14+
#define MAX_CPU_FEATURES 128
1515
#define cpu_feature(x) KERNEL_HWCAP_ ## x
1616

1717
#ifndef __ASSEMBLY__

arch/arm64/include/asm/hwcap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#define KERNEL_HWCAP_PACA __khwcap_feature(PACA)
8686
#define KERNEL_HWCAP_PACG __khwcap_feature(PACG)
8787

88-
#define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + 32)
88+
#define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + 64)
8989
#define KERNEL_HWCAP_DCPODP __khwcap2_feature(DCPODP)
9090
#define KERNEL_HWCAP_SVE2 __khwcap2_feature(SVE2)
9191
#define KERNEL_HWCAP_SVEAES __khwcap2_feature(SVEAES)

arch/arm64/kernel/cpufeature.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#include <asm/virt.h>
9292

9393
/* Kernel representation of AT_HWCAP and AT_HWCAP2 */
94-
static unsigned long elf_hwcap __read_mostly;
94+
static DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly;
9595

9696
#ifdef CONFIG_COMPAT
9797
#define COMPAT_ELF_HWCAP_DEFAULT \
@@ -3116,14 +3116,12 @@ static bool __maybe_unused __system_matches_cap(unsigned int n)
31163116

31173117
void cpu_set_feature(unsigned int num)
31183118
{
3119-
WARN_ON(num >= MAX_CPU_FEATURES);
3120-
elf_hwcap |= BIT(num);
3119+
set_bit(num, elf_hwcap);
31213120
}
31223121

31233122
bool cpu_have_feature(unsigned int num)
31243123
{
3125-
WARN_ON(num >= MAX_CPU_FEATURES);
3126-
return elf_hwcap & BIT(num);
3124+
return test_bit(num, elf_hwcap);
31273125
}
31283126
EXPORT_SYMBOL_GPL(cpu_have_feature);
31293127

@@ -3134,12 +3132,12 @@ unsigned long cpu_get_elf_hwcap(void)
31343132
* note that for userspace compatibility we guarantee that bits 62
31353133
* and 63 will always be returned as 0.
31363134
*/
3137-
return lower_32_bits(elf_hwcap);
3135+
return elf_hwcap[0];
31383136
}
31393137

31403138
unsigned long cpu_get_elf_hwcap2(void)
31413139
{
3142-
return upper_32_bits(elf_hwcap);
3140+
return elf_hwcap[1];
31433141
}
31443142

31453143
static void __init setup_system_capabilities(void)

0 commit comments

Comments
 (0)