arm64: Add AT_HWCAP3
Subsystems (4)
v3 cover arm64: Add AT_HWCAP3
Currently for arm64 we expose hwcaps to userspace using the low 32 bits of AT_HWCAP and AT_HWCAP2. Due to the ever expanding capabilties of the architecture we have now allocated all the available bits in this scheme so we need to expand, either using the higher bits or adding a new AT_HWCAP3. Discussions with glibc developers suggested that AT_HWCAP3 would be cleaner for them so the series adopts that approach.
The final patch adds an initial value in AT_HWCAP3 reporting the presence of FEAT_EBF16, this will conflict with my series converting ID_AA64ISAR1_EL1 to be generated. I've got a version based on top of that which I can send if that's convenient.
v3:
- Expand comment on CPU_FEATURES_PER_HWCAP.
v2:
- Rebase onto v5.19-rc3.
Mark Brown (4):
arm64/cpufeature: Store elf_hwcaps as an array rather than unsigned
long
elf: Allow architectures to provide AT_HWCAP3 arm64/cpufeature: Support AT_HWCAP3
arm64/hwcap: Support FEAT_EBF16
Documentation/arm64/elf_hwcaps.rst | 10 +++++++--- arch/arm64/include/asm/cpufeature.h | 9 ++++++++- arch/arm64/include/asm/hwcap.h | 17 ++++++++++++----- arch/arm64/include/uapi/asm/hwcap.h | 5 +++++ arch/arm64/kernel/cpufeature.c | 28 +++++++++++++++++++++------- arch/arm64/kernel/cpuinfo.c | 1 + fs/binfmt_elf.c | 3 +++ include/uapi/linux/auxvec.h | 1 + 8 files changed, 58 insertions(+), 16 deletions(-)
base-commit: a111daf0c53ae91e71fd2bfe7497862d14132e3e
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 1/4 arm64/cpufeature: Store elf_hwcaps as an array 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 an array instead. There should be no functional change from this patch.
--- 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(-)
arch/arm64/include/asm/cpufeature.h +6 -0
@@ -11,6 +11,12 @@#include <asm/hwcap.h> #include <asm/sysreg.h> +/* +* 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
arch/arm64/include/asm/hwcap.h +3 -1
@@ -41,6 +41,8 @@#ifndef __ASSEMBLY__#include <linux/log2.h> +#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)
arch/arm64/kernel/cpufeature.c +15 -7
@@ -91,7 +91,7 @@#include <asm/virt.h> /* 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 )
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 2/4 elf: Allow architectures to provide AT_HWCAP3
In reply to Mark BrownIn order to provide for architectures which have filled both AT_HWCAP and AT_HWCAP2 add support for AT_HWCAP3.
--- fs/binfmt_elf.c | 3 +++ include/uapi/linux/auxvec.h | 1 + 2 files changed, 4 insertions(+)
fs/binfmt_elf.c +3 -0
@@ -275,6 +275,9 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec,NEW_AUX_ENT (AT_RANDOM , (elf_addr_t )(unsigned long )u_rand_bytes);#ifdef ELF_HWCAP2 NEW_AUX_ENT (AT_HWCAP2 ,ELF_HWCAP2 ); +#endif +#ifdef ELF_HWCAP3 +NEW_AUX_ENT (AT_HWCAP3 ,ELF_HWCAP3 );#endif NEW_AUX_ENT (AT_EXECFN , bprm->exec);if (k_platform) {
include/uapi/linux/auxvec.h +1 -0
@@ -30,6 +30,7 @@* differ from AT_PLATFORM. */ #define AT_RANDOM 25/* address of 16 random bytes */ #define AT_HWCAP2 26/* extension of AT_HWCAP */ +#define AT_HWCAP3 27/* further extension of AT_HWCAP */ #define AT_EXECFN 31/* filename of program */
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 3/4 arm64/cpufeature: Support AT_HWCAP3
In reply to Mark BrownWe have filled the low 32 bits of both AT_HWCAP and AT_HWCAP2 so in order to support further architecture features we must either start allocating from the upper 32 bits or add a new AT_HWCAP3. Feedback from the glibc developers was that AT_HWCAP3 would be cleaner so go with that.
This patch merely adds the glue required for AT_HWCAP3, meaning that we start providing AT_HWCAP3 for ELF executables but no bits will be set in it.
--- Documentation/arm64/elf_hwcaps.rst | 6 +++--- arch/arm64/include/asm/cpufeature.h | 3 ++- arch/arm64/include/asm/hwcap.h | 12 ++++++++---- arch/arm64/include/uapi/asm/hwcap.h | 4 ++++ arch/arm64/kernel/cpufeature.c | 5 +++++ 5 files changed, 22 insertions(+), 8 deletions(-)
Documentation/arm64/elf_hwcaps.rst +3 -3
@@ -16,9 +16,9 @@ architected discovery mechanism available to userspace code at EL0. The kernel exposes the presence of these features to userspace through a set of flags called hwcaps, exposed in the auxilliary vector. -Userspace software can test for features by acquiring the AT_HWCAP or -AT_HWCAP2 entry of the auxiliary vector, and testing whether the relevant -flags are set, e.g.:: +Userspace software can test for features by acquiring the AT_HWCAP, +AT_HWCAP2 or AT_HWCAP3 entry of the auxiliary vector, and testing +whether the relevant flags are set, e.g.:: bool floating_point_is_present(void) {
arch/arm64/include/asm/cpufeature.h +2 -1
@@ -17,7 +17,7 @@* AT_HWCAP are reserved for glibc. */ #define CPU_FEATURES_PER_HWCAP 32 -#define MAX_CPU_FEATURES 64 +#define MAX_CPU_FEATURES 96#define cpu_feature (x) KERNEL_HWCAP_ ## x#ifndef __ASSEMBLY__
@@ -440,6 +440,7 @@ void cpu_set_feature(unsigned int num);bool cpu_have_feature (unsigned int num);unsigned long cpu_get_elf_hwcap (void );unsigned long cpu_get_elf_hwcap2 (void ); +unsigned long cpu_get_elf_hwcap3 (void );#define cpu_set_named_feature (name) cpu_set_feature(cpu_feature(name))#define cpu_have_named_feature (name) cpu_have_feature(cpu_feature(name))
arch/arm64/include/asm/hwcap.h +8 -4
@@ -44,10 +44,11 @@#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 -* natural numbers (in a single range of size MAX_CPU_FEATURES) defined here -* with prefix KERNEL_HWCAP_ mapped to their HWCAP{,2}_x counterpart. +* For userspace we represent hwcaps as a collection of HWCAP{,[23]}_x +* bitfields as described in uapi/asm/hwcap.h. For the kernel we +* represent hwcaps as natural numbers (in a single range of size +* MAX_CPU_FEATURES) defined here with prefix KERNEL_HWCAP_ mapped to +* their HWCAP{,2}_x counterpart. * * Hwcaps should be set and tested within the kernel via the * cpu_{set,have}_named_feature(feature) where feature is the unique suffix
@@ -121,12 +122,15 @@#define KERNEL_HWCAP_SME_FA64 __khwcap2_feature(SME_FA64)#define KERNEL_HWCAP_WFXT __khwcap2_feature(WFXT) +#define __khwcap3_feature (x) (const_ilog2(HWCAP3_ ## x) + KHWCAP_OFFSET(3)) +/* * This yields a mask that user programs can use to figure out what * instruction set this cpu supports. */ #define ELF_HWCAP cpu_get_elf_hwcap()#define ELF_HWCAP2 cpu_get_elf_hwcap2() +#define ELF_HWCAP3 cpu_get_elf_hwcap3()#ifdef CONFIG_COMPAT #define COMPAT_ELF_HWCAP (compat_elf_hwcap)
arch/arm64/include/uapi/asm/hwcap.h +4 -0
@@ -89,4 +89,8 @@#define HWCAP2_SME_FA64 (1 << 30)#define HWCAP2_WFXT (1UL << 31) +/* +* HWCAP3 flags - for AT_HWCAP3 +*/ +#endif /* _UAPI__ASM_HWCAP_H */
arch/arm64/kernel/cpufeature.c +5 -0
@@ -3132,6 +3132,11 @@ unsigned long cpu_get_elf_hwcap2(void)return elf_hwcap[1 ]; } +unsigned long cpu_get_elf_hwcap3 (void ) +{ +return elf_hwcap[2 ]; +} +static void __init setup_system_capabilities (void ) {/*
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 4/4 arm64/hwcap: Support FEAT_EBF16
In reply to Mark BrownThe v9.2 feature FEAT_EBF16 provides support for an extended BFloat16 mode. Allow userspace to discover system support for this feature by adding a hwcap for it.
--- Documentation/arm64/elf_hwcaps.rst | 4 ++++ arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel/cpufeature.c | 1 + arch/arm64/kernel/cpuinfo.c | 1 + 5 files changed, 8 insertions(+)
Documentation/arm64/elf_hwcaps.rst +4 -0
@@ -301,6 +301,10 @@ HWCAP2_WFXT Functionality implied by ID_AA64ISAR2_EL1.WFXT == 0b0010. +HWCAP3_EBF16 + + Functionality implied by ID_AA64ISAR1_EL1.BF16 == 0b0010. + 4. Unused AT_HWCAP bits -----------------------
arch/arm64/include/asm/hwcap.h +1 -0
@@ -123,6 +123,7 @@#define KERNEL_HWCAP_WFXT __khwcap2_feature(WFXT)#define __khwcap3_feature (x) (const_ilog2(HWCAP3_ ## x) + KHWCAP_OFFSET(3)) +#define KERNEL_HWCAP_EBF16 __khwcap3_feature(EBF16)/* * This yields a mask that user programs can use to figure out what
arch/arm64/include/uapi/asm/hwcap.h +1 -0
@@ -92,5 +92,6 @@/* * HWCAP3 flags - for AT_HWCAP3 */ +#define HWCAP3_EBF16 (1 << 0)#endif /* _UAPI__ASM_HWCAP_H */
arch/arm64/kernel/cpufeature.c +1 -0
@@ -2623,6 +2623,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_FRINTTS_SHIFT ,4 ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_FRINT ),HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_SB_SHIFT ,4 ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_SB ),HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_BF16_SHIFT ,4 ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_BF16 ), +HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_BF16_SHIFT ,4 ,FTR_UNSIGNED ,2 ,CAP_HWCAP ,KERNEL_HWCAP_EBF16 ),HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_DGH_SHIFT ,4 ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_DGH ),HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_I8MM_SHIFT ,4 ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_I8MM ), HWCAP_CAP(SYS_ID_AA64MMFR2_EL1, ID_AA64MMFR2_AT_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_USCAT),
arch/arm64/kernel/cpuinfo.c +1 -0
@@ -107,6 +107,7 @@ static const char *const hwcap_str[] = { [KERNEL_HWCAP_SME_F32F32] = "smef32f32", [KERNEL_HWCAP_SME_FA64] = "smefa64", [KERNEL_HWCAP_WFXT] = "wfxt", + [KERNEL_HWCAP_EBF16] = "ebf16", };#ifdef CONFIG_COMPAT
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel