arm64: Initial support for CVADP
Subsystems (6)
v5 cover arm64: Initial support for CVADP
ARMv8.5 introduces a DC CVADP instruction which cleans the data cache to the point of deep persistence. This series makes the instruction available to userspace and advertises the presence of this CPU feature.
At present when CONFIG_ARM64_PMEM is enabled and the CVAP feature is present (ARMv8.2) the CVAP instruction is used (from memcpy_flushcache and arch_wb_cache_pmem). No changes have been made to use CVADP in these functions or similar.
As we have moved beyond 32 capabilities we now begin using AT_HWCAP2 for userspace.
Tested as follows:
$ dmesg | grep "Deep" [ 0.166496] CPU features: detected: Data cache clean to Point of Deep Persistence
$ LD_SHOW_AUXV=1 sleep 2>&1 | grep AT_HWCAP AT_HWCAP: ef91ff87 AT_HWCAP2: 0x1
Changes since v4:
- Rebased onto v5.1-rc4
- Add missing .sign field to cpufeature
- Include <linux/log2.h> where needed
Changes since v3:
- Rebased onto v5.1-rc3
- Add macros for mapping uapi HWCAPs to KERNEL_HWCAPs
- Squash AT_HWCAP2 documentation into AT_HWCAP2 patch
- Reorder series to allow HWCAP changes to be taken without CVADP (if needed)
- Additional comments, changes to comments and commit messages
Changes since v2:
- Rebased onto v5.1-rc2
- Renamed cpu_{have,set}_feature_name to cpu_{have,set}_named_feature
- Add additional comments and update kernel Documentation
Changes since v1:
- Rebased onto v5.0-rc7
- Introduced cpu_{have,set}_feature_name to eliminate use of KERNEL_HWCAP prefix
- Hard coded MAX_CPU_FEATURES and added a WARN_ON
- Minor comment and tab/spacing changes
- Use elf_hwcap for all 64 caps in the kernel instead of a new elf_hwcap2
Andrew Murray (6):
arm64: HWCAP: add support for AT_HWCAP2
arm64: HWCAP: encapsulate elf_hwcap
arm64: Handle trapped DC CVADP
arm64: Expose DC CVADP to userspace
arm64: add CVADP support to the cache maintenance helper
arm64: Advertise ARM64_HAS_DCPODP cpu feature
Documentation/arm64/elf_hwcaps.txt | 18 +++- arch/arm64/crypto/aes-ce-ccm-glue.c | 2 +- arch/arm64/crypto/aes-neonbs-glue.c | 2 +- arch/arm64/crypto/chacha-neon-glue.c | 2 +- arch/arm64/crypto/crct10dif-ce-glue.c | 4 +- arch/arm64/crypto/ghash-ce-glue.c | 8 +- arch/arm64/crypto/nhpoly1305-neon-glue.c | 2 +- arch/arm64/crypto/sha256-glue.c | 4 +- arch/arm64/include/asm/assembler.h | 4 + arch/arm64/include/asm/cpucaps.h | 3 +- arch/arm64/include/asm/cpufeature.h | 21 ++--- arch/arm64/include/asm/esr.h | 3 +- arch/arm64/include/asm/hwcap.h | 54 ++++++++++- arch/arm64/include/uapi/asm/hwcap.h | 7 +- arch/arm64/kernel/cpufeature.c | 110 +++++++++++++++-------- arch/arm64/kernel/cpuinfo.c | 3 +- arch/arm64/kernel/fpsimd.c | 4 +- arch/arm64/kernel/traps.c | 3 + drivers/clocksource/arm_arch_timer.c | 8 ++ 19 files changed, 191 insertions(+), 71 deletions(-)
Signature · 1 line
2.21.0
PATCH v5 1/6 arm64: HWCAP: add support for AT_HWCAP2
As we will exhaust the first 32 bits of AT_HWCAP let's start exposing AT_HWCAP2 to userspace to give us up to 64 caps.
Whilst it's possible to use the remaining 32 bits of AT_HWCAP, we prefer to expand into AT_HWCAP2 in order to provide a consistent view to userspace between ILP32 and LP64. However internal to the kernel we prefer to continue to use the full space of elf_hwcap.
To reduce complexity and allow for future expansion, we now represent hwcaps in the kernel as ordinals and use a KERNEL_HWCAP_ prefix. This allows us to support automatic feature based module loading for all our hwcaps.
We introduce cpu_set_feature to set hwcaps which complements the existing cpu_have_feature helper. These helpers allow us to clean up existing direct uses of elf_hwcap and reduce any future effort required to move beyond 64 caps.
For convenience we also introduce cpu_{have,set}_named_feature which makes use of the cpu_feature macro to allow providing a hwcap name without a {KERNEL_}HWCAP_ prefix.
--- Documentation/arm64/elf_hwcaps.txt | 14 +++-- arch/arm64/crypto/aes-ce-ccm-glue.c | 2 +- arch/arm64/crypto/aes-neonbs-glue.c | 2 +- arch/arm64/crypto/chacha-neon-glue.c | 2 +- arch/arm64/crypto/crct10dif-ce-glue.c | 4 +- arch/arm64/crypto/ghash-ce-glue.c | 8 +-- arch/arm64/crypto/nhpoly1305-neon-glue.c | 2 +- arch/arm64/crypto/sha256-glue.c | 4 +- arch/arm64/include/asm/cpufeature.h | 22 ++++---- arch/arm64/include/asm/hwcap.h | 52 ++++++++++++++++++- arch/arm64/include/uapi/asm/hwcap.h | 2 +- arch/arm64/kernel/cpufeature.c | 66 ++++++++++++------------ arch/arm64/kernel/cpuinfo.c | 2 +- arch/arm64/kernel/fpsimd.c | 4 +- drivers/clocksource/arm_arch_timer.c | 8 +++ 15 files changed, 131 insertions(+), 63 deletions(-)
Documentation/arm64/elf_hwcaps.txt +11 -3
@@ -13,9 +13,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 entry -of the auxilliary vector, and testing whether the relevant flags are -set, e.g. +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. bool floating_point_is_present(void) {
@@ -194,3 +194,11 @@ HWCAP_PACG Functionality implied by ID_AA64ISAR1_EL1.GPA == 0b0001 or ID_AA64ISAR1_EL1.GPI == 0b0001, as described by Documentation/arm64/pointer-authentication.txt. + + +4. Unused AT_HWCAP bits +----------------------- + +Each AT_HWCAP and AT_HWCAP2 entry provides for up to 32 hwcaps contained +in bits [31:0]. For interoperation with userspace we guarantee that bits +62 and 63 of AT_HWCAP will always be returned as 0.
arch/arm64/crypto/aes-ce-ccm-glue.c +1 -1
@@ -372,7 +372,7 @@ static struct aead_alg ccm_aes_alg = {static int __init aes_mod_init (void ) { -if (!(elf_hwcap &HWCAP_AES )) +if (!cpu_have_named_feature (AES ))return -ENODEV ;return crypto_register_aead (&ccm_aes_alg); }
arch/arm64/crypto/aes-neonbs-glue.c +1 -1
@@ -440,7 +440,7 @@ static int __init aes_init(void)int err;int i; -if (!(elf_hwcap &HWCAP_ASIMD )) +if (!cpu_have_named_feature (ASIMD ))return -ENODEV ; err =crypto_register_skciphers (aes_algs,ARRAY_SIZE (aes_algs));
arch/arm64/crypto/chacha-neon-glue.c +1 -1
@@ -173,7 +173,7 @@ static struct skcipher_alg algs[] = {static int __init chacha_simd_mod_init (void ) { -if (!(elf_hwcap &HWCAP_ASIMD )) +if (!cpu_have_named_feature (ASIMD ))return -ENODEV ;return crypto_register_skciphers (algs,ARRAY_SIZE (algs));
arch/arm64/crypto/crct10dif-ce-glue.c +2 -2
@@ -101,7 +101,7 @@ static struct shash_alg crc_t10dif_alg[] = {{static int __init crc_t10dif_mod_init (void ) { -if (elf_hwcap &HWCAP_PMULL ) +if (cpu_have_named_feature (PMULL ))return crypto_register_shashes (crc_t10dif_alg,ARRAY_SIZE (crc_t10dif_alg));else
@@ -111,7 +111,7 @@ static int __init crc_t10dif_mod_init(void) static void __exit crc_t10dif_mod_exit(void) { -if (elf_hwcap &HWCAP_PMULL ) +if (cpu_have_named_feature (PMULL ))crypto_unregister_shashes (crc_t10dif_alg,ARRAY_SIZE (crc_t10dif_alg));else
arch/arm64/crypto/ghash-ce-glue.c +4 -4
@@ -704,10 +704,10 @@ static int __init ghash_ce_mod_init(void) {int ret; -if (!(elf_hwcap &HWCAP_ASIMD )) +if (!cpu_have_named_feature (ASIMD ))return -ENODEV ; -if (elf_hwcap &HWCAP_PMULL ) +if (cpu_have_named_feature (PMULL )) ret =crypto_register_shashes (ghash_alg,ARRAY_SIZE (ghash_alg));else
@@ -717,7 +717,7 @@ static int __init ghash_ce_mod_init(void)if (ret)return ret; -if (elf_hwcap &HWCAP_PMULL ) { +if (cpu_have_named_feature (PMULL )) { ret =crypto_register_aead (&gcm_aes_alg);if (ret) crypto_unregister_shashes(ghash_alg,
@@ -728,7 +728,7 @@ static int __init ghash_ce_mod_init(void) static void __exit ghash_ce_mod_exit(void) { -if (elf_hwcap &HWCAP_PMULL ) +if (cpu_have_named_feature (PMULL ))crypto_unregister_shashes (ghash_alg,ARRAY_SIZE (ghash_alg));else crypto_unregister_shash (ghash_alg);
arch/arm64/crypto/nhpoly1305-neon-glue.c +1 -1
@@ -56,7 +56,7 @@ static struct shash_alg nhpoly1305_alg = {static int __init nhpoly1305_mod_init (void ) { -if (!(elf_hwcap &HWCAP_ASIMD )) +if (!cpu_have_named_feature (ASIMD ))return -ENODEV ;return crypto_register_shash (&nhpoly1305_alg);
arch/arm64/crypto/sha256-glue.c +2 -2
@@ -173,7 +173,7 @@ static int __init sha256_mod_init(void)if (ret)return ret; -if (elf_hwcap &HWCAP_ASIMD ) { +if (cpu_have_named_feature (ASIMD )) { ret =crypto_register_shashes (neon_algs,ARRAY_SIZE (neon_algs));if (ret)crypto_unregister_shashes (algs,ARRAY_SIZE (algs));
@@ -183,7 +183,7 @@ static int __init sha256_mod_init(void) static void __exit sha256_mod_fini(void) { -if (elf_hwcap &HWCAP_ASIMD ) +if (cpu_have_named_feature (ASIMD ))crypto_unregister_shashes (neon_algs,ARRAY_SIZE (neon_algs));crypto_unregister_shashes (algs,ARRAY_SIZE (algs)); }
arch/arm64/include/asm/cpufeature.h +12 -10
@@ -14,15 +14,8 @@#include <asm/hwcap.h> #include <asm/sysreg.h> -/* -* In the arm64 world (as in the ARM world), elf_hwcap is used both internally -* in the kernel and for user space to keep track of which optional features -* are supported by the current system. So let's map feature 'x' to HWCAP_x. -* Note that HWCAP_x constants are bit fields so we need to take the log. -*/ - -#define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap)) -#define cpu_feature (x) ilog2(HWCAP_ ## x) +#define MAX_CPU_FEATURES 64 +#define cpu_feature (x) KERNEL_HWCAP_ ## x#ifndef __ASSEMBLY__
@@ -400,10 +393,19 @@ extern DECLARE_BITMAP(boot_capabilities, ARM64_NPATCHABLE);bool this_cpu_has_cap (unsigned int cap); +static inline void cpu_set_feature (unsigned int num) +{ +WARN_ON (num >=MAX_CPU_FEATURES ); + elf_hwcap |=BIT (num); +} +#define cpu_set_named_feature (name) cpu_set_feature(cpu_feature(name)) +static inline bool cpu_have_feature (unsigned int num) { -return elf_hwcap & (1UL << num); +WARN_ON (num >=MAX_CPU_FEATURES ); +return elf_hwcap &BIT (num); } +#define cpu_have_named_feature (name) cpu_have_feature(cpu_feature(name))/* System capability check for constant caps */ static inline bool __cpus_have_const_cap (int num)
arch/arm64/include/asm/hwcap.h +51 -1
62 lines not on this page · raw message
arch/arm64/include/uapi/asm/hwcap.h +1 -1
@@ -18,7 +18,7 @@#define _UAPI__ASM_HWCAP_H/* -* HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP +* HWCAP flags - for AT_HWCAP */ #define HWCAP_FP (1 << 0)#define HWCAP_ASIMD (1 << 1)
arch/arm64/kernel/cpufeature.c +33 -33
93 lines not on this page · raw message
arch/arm64/kernel/cpuinfo.c +1 -1
@@ -167,7 +167,7 @@ static int c_show(struct seq_file *m, void *v)#endif /* CONFIG_COMPAT */ }else {for (j =0 ; hwcap_str[j]; j++) -if (elf_hwcap & (1 << j)) +if (cpu_have_feature (j))seq_printf (m," %s" , hwcap_str[j]); }seq_puts (m,"\n" );
arch/arm64/kernel/fpsimd.c +2 -2
@@ -1258,14 +1258,14 @@ static inline void fpsimd_hotplug_init(void) { }*/ static int __init fpsimd_init (void ) { -if (elf_hwcap &HWCAP_FP ) { +if (cpu_have_named_feature (FP )) {fpsimd_pm_init ();fpsimd_hotplug_init (); }else {pr_notice ("Floating-point is not implemented\n" ); } -if (!(elf_hwcap &HWCAP_ASIMD )) +if (!cpu_have_named_feature (ASIMD ))pr_notice ("Advanced SIMD is not implemented\n" );return sve_sysctl_init ();
drivers/clocksource/arm_arch_timer.c +8 -0
@@ -833,7 +833,11 @@ static void arch_timer_evtstrm_enable(int divider) cntkctl |= (divider <<ARCH_TIMER_EVT_TRIGGER_SHIFT ) |ARCH_TIMER_VIRT_EVT_EN ;arch_timer_set_cntkctl (cntkctl); +#ifdef CONFIG_ARM64 +cpu_set_named_feature (EVTSTRM ); +#else elf_hwcap |=HWCAP_EVTSTRM ; +#endif #ifdef CONFIG_COMPAT compat_elf_hwcap |=COMPAT_HWCAP_EVTSTRM ;#endif
@@ -1055,7 +1059,11 @@ static int arch_timer_cpu_pm_notify(struct notifier_block *self, }else if (action ==CPU_PM_ENTER_FAILED || action ==CPU_PM_EXIT ) {arch_timer_set_cntkctl (__this_cpu_read (saved_cntkctl)); +#ifdef CONFIG_ARM64 +if (cpu_have_named_feature (EVTSTRM )) +#else if (elf_hwcap & HWCAP_EVTSTRM) +#endif cpumask_set_cpu (smp_processor_id (), &evtstrm_available); }return NOTIFY_OK ;
Signature · 1 line
2.21.0
Re: [PATCH v5 1/6] arm64: HWCAP: add support for AT_HWCAP2
Quoted 60 lines · Andrew Murray
As we will exhaust the first 32 bits of
AT_HWCAPlet's start exposingAT_HWCAP2to userspace to give us up to 64 caps.Whilst it's possible to use the remaining 32 bits of
AT_HWCAP, we prefer to expand intoAT_HWCAP2in order to provide a consistent view to userspace between ILP32 and LP64. However internal to the kernel we prefer to continue to use the full space ofelf_hwcap.To reduce complexity and allow for future expansion, we now represent hwcaps in the kernel as ordinals and use a
KERNEL_HWCAP_prefix. This allows us to support automatic feature based module loading for all our hwcaps.We introduce
cpu_set_featureto set hwcaps which complements the existingcpu_have_featurehelper. These helpers allow us to clean up existing direct uses ofelf_hwcapand reduce any future effort required to move beyond 64 caps.For convenience we also introduce cpu_{have,set}_named_feature which makes use of the
cpu_featuremacro to allow providing a hwcap name without a {KERNEL_}HWCAP_ prefix.Signed-off-by Andrew Murray <[email protected]>--- Documentation/arm64/elf_hwcaps.txt | 14 +++-- arch/arm64/crypto/aes-ce-ccm-glue.c | 2 +- arch/arm64/crypto/aes-neonbs-glue.c | 2 +- arch/arm64/crypto/chacha-neon-glue.c | 2 +- arch/arm64/crypto/crct10dif-ce-glue.c | 4 +- arch/arm64/crypto/ghash-ce-glue.c | 8 +-- arch/arm64/crypto/nhpoly1305-neon-glue.c | 2 +- arch/arm64/crypto/sha256-glue.c | 4 +- arch/arm64/include/asm/cpufeature.h | 22 ++++---- arch/arm64/include/asm/hwcap.h | 52 ++++++++++++++++++- arch/arm64/include/uapi/asm/hwcap.h | 2 +- arch/arm64/kernel/cpufeature.c | 66 ++++++++++++------------ arch/arm64/kernel/cpuinfo.c | 2 +- arch/arm64/kernel/fpsimd.c | 4 +- drivers/clocksource/arm_arch_timer.c | 8 +++ 15 files changed, 131 insertions(+), 63 deletions(-)Documentation/arm64/elf_hwcaps.txt +3
-3@@ -13,9 +13,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 entry -of the auxilliary vector, and testing whether the relevant flags are -set, e.g. +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. bool floating_point_is_present(void) {@@ -194,3 +194,11 @@ HWCAP_PACG Functionality implied by ID_AA64ISAR1_EL1.GPA == 0b0001 or
Documentation/arm64/elf_hwcaps.txt HWCAP_PACG · line 204
Quoted 10 lines
Documentation/arm64/elf_hwcaps.txt +8
-0ID_AA64ISAR1_EL1.GPI == 0b0001, as described by Documentation/arm64/pointer-authentication.txt. + + +4. Unused AT_HWCAP bits +----------------------- + +Each AT_HWCAP and AT_HWCAP2 entry provides for up to 32 hwcaps contained +in bits [31:0]. For interoperation with userspace we guarantee that bits +62 and 63 of AT_HWCAP will always be returned as 0.
I'm a little nervous about the first sentence here, since it could be taken to mean that we will never allocate 61:32. Mind if I drop it?
Quoted 17 lines
drivers/clocksource/arm_arch_timer.c +4
-0@@ -833,7 +833,11 @@ static void arch_timer_evtstrm_enable(int divider) cntkctl |= (divider <<ARCH_TIMER_EVT_TRIGGER_SHIFT ) |ARCH_TIMER_VIRT_EVT_EN ;arch_timer_set_cntkctl (cntkctl); +#ifdef CONFIG_ARM64 +cpu_set_named_feature (EVTSTRM ); +#else elf_hwcap |=HWCAP_EVTSTRM ; +#endif #ifdef CONFIG_COMPAT compat_elf_hwcap |=COMPAT_HWCAP_EVTSTRM ;#endif
drivers/clocksource/arm_arch_timer.c static int arch_timer_cpu_pm_notify(struct notifier_block *self, · line 1066
Quoted 8 lines
drivers/clocksource/arm_arch_timer.c +4
-0@@ -1055,7 +1059,11 @@ static int arch_timer_cpu_pm_notify(struct notifier_block *self, }else if (action ==CPU_PM_ENTER_FAILED || action ==CPU_PM_EXIT ) {arch_timer_set_cntkctl (__this_cpu_read (saved_cntkctl)); +#ifdef CONFIG_ARM64 +if (cpu_have_named_feature (EVTSTRM )) +#else if (elf_hwcap & HWCAP_EVTSTRM) +#endif
I think this is an indication that the abstraction isn't quite right and should probably be done in an arch-helped via asm/arch_timer.h. However, that can be done as a separate patch later on.
Will
Re: [PATCH v5 1/6] arm64: HWCAP: add support for AT_HWCAP2
Quoted 66 lines · Will Deacon
Quoted 65 lines · Andrew Murray
As we will exhaust the first 32 bits of
AT_HWCAPlet's start exposingAT_HWCAP2to userspace to give us up to 64 caps.Whilst it's possible to use the remaining 32 bits of
AT_HWCAP, we prefer to expand intoAT_HWCAP2in order to provide a consistent view to userspace between ILP32 and LP64. However internal to the kernel we prefer to continue to use the full space ofelf_hwcap.To reduce complexity and allow for future expansion, we now represent hwcaps in the kernel as ordinals and use a
KERNEL_HWCAP_prefix. This allows us to support automatic feature based module loading for all our hwcaps.We introduce
cpu_set_featureto set hwcaps which complements the existingcpu_have_featurehelper. These helpers allow us to clean up existing direct uses ofelf_hwcapand reduce any future effort required to move beyond 64 caps.For convenience we also introduce cpu_{have,set}_named_feature which makes use of the
cpu_featuremacro to allow providing a hwcap name without a {KERNEL_}HWCAP_ prefix.Signed-off-by Andrew Murray <[email protected]>--- Documentation/arm64/elf_hwcaps.txt | 14 +++-- arch/arm64/crypto/aes-ce-ccm-glue.c | 2 +- arch/arm64/crypto/aes-neonbs-glue.c | 2 +- arch/arm64/crypto/chacha-neon-glue.c | 2 +- arch/arm64/crypto/crct10dif-ce-glue.c | 4 +- arch/arm64/crypto/ghash-ce-glue.c | 8 +-- arch/arm64/crypto/nhpoly1305-neon-glue.c | 2 +- arch/arm64/crypto/sha256-glue.c | 4 +- arch/arm64/include/asm/cpufeature.h | 22 ++++---- arch/arm64/include/asm/hwcap.h | 52 ++++++++++++++++++- arch/arm64/include/uapi/asm/hwcap.h | 2 +- arch/arm64/kernel/cpufeature.c | 66 ++++++++++++------------ arch/arm64/kernel/cpuinfo.c | 2 +- arch/arm64/kernel/fpsimd.c | 4 +- drivers/clocksource/arm_arch_timer.c | 8 +++ 15 files changed, 131 insertions(+), 63 deletions(-)Documentation/arm64/elf_hwcaps.txt +6
-3@@ -13,9 +13,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 entry -of the auxilliary vector, and testing whether the relevant flags are -set, e.g. +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. bool floating_point_is_present(void) {@@ -194,3 +194,11 @@ HWCAP_PACG Functionality implied by ID_AA64ISAR1_EL1.GPA == 0b0001 or ID_AA64ISAR1_EL1.GPI == 0b0001, as described by Documentation/arm64/pointer-authentication.txt. + + +4. Unused AT_HWCAP bits
Quoted 8 lines
Documentation/arm64/elf_hwcaps.txt HWCAP_PACG · line 204
Quoted 5 lines
Documentation/arm64/elf_hwcaps.txt +5
-0+----------------------- + +Each AT_HWCAP and AT_HWCAP2 entry provides for up to 32 hwcaps contained +in bits [31:0]. For interoperation with userspace we guarantee that bits +62 and 63 of AT_HWCAP will always be returned as 0.I'm a little nervous about the first sentence here, since it could be taken to mean that we will never allocate 61:32. Mind if I drop it?
Ack: I don't think we want to say explicitly that we will never use those bits, apart from AT_HWCAP[63:62] for which there are specific reasons.
(For now of course, we won't use them.)
Quoted 20 lines
Quoted 20 lines
drivers/clocksource/arm_arch_timer.c +4
-0@@ -833,7 +833,11 @@ static void arch_timer_evtstrm_enable(int divider) cntkctl |= (divider <<ARCH_TIMER_EVT_TRIGGER_SHIFT ) |ARCH_TIMER_VIRT_EVT_EN ;arch_timer_set_cntkctl (cntkctl); +#ifdef CONFIG_ARM64 +cpu_set_named_feature (EVTSTRM ); +#else elf_hwcap |=HWCAP_EVTSTRM ; +#endif #ifdef CONFIG_COMPAT compat_elf_hwcap |=COMPAT_HWCAP_EVTSTRM ;#endif @@ -1055,7 +1059,11 @@ static int arch_timer_cpu_pm_notify(struct notifier_block *self, }else if (action ==CPU_PM_ENTER_FAILED || action ==CPU_PM_EXIT ) {arch_timer_set_cntkctl (__this_cpu_read (saved_cntkctl));
Quoted 9 lines
drivers/clocksource/arm_arch_timer.c static int arch_timer_cpu_pm_notify(struct notifier_block *self, · line 1066
Quoted 5 lines
drivers/clocksource/arm_arch_timer.c +4
-0+#ifdef CONFIG_ARM64 +if (cpu_have_named_feature (EVTSTRM )) +#else if (elf_hwcap & HWCAP_EVTSTRM) +#endif I think this is an indication that the abstraction isn't quite right and should probably be done in an arch-helped via
asm/arch_timer.h. However, that can be done as a separate patch later on.
It probably does make sense to add an arch-specific helper for that.
Given that we don't want to encourage this kind of poking about in elf_hwcap. It might make sense to have a single-purpose helper just for checking this flag.
Cheers
---Dave
Re: [PATCH v5 1/6] arm64: HWCAP: add support for AT_HWCAP2
Quoted 76 lines · Dave Martin
Quoted 66 lines · Will Deacon
Quoted 65 lines · Andrew Murray
As we will exhaust the first 32 bits of
AT_HWCAPlet's start exposingAT_HWCAP2to userspace to give us up to 64 caps.Whilst it's possible to use the remaining 32 bits of
AT_HWCAP, we prefer to expand intoAT_HWCAP2in order to provide a consistent view to userspace between ILP32 and LP64. However internal to the kernel we prefer to continue to use the full space ofelf_hwcap.To reduce complexity and allow for future expansion, we now represent hwcaps in the kernel as ordinals and use a
KERNEL_HWCAP_prefix. This allows us to support automatic feature based module loading for all our hwcaps.We introduce
cpu_set_featureto set hwcaps which complements the existingcpu_have_featurehelper. These helpers allow us to clean up existing direct uses ofelf_hwcapand reduce any future effort required to move beyond 64 caps.For convenience we also introduce cpu_{have,set}_named_feature which makes use of the
cpu_featuremacro to allow providing a hwcap name without a {KERNEL_}HWCAP_ prefix.Signed-off-by Andrew Murray <[email protected]>--- Documentation/arm64/elf_hwcaps.txt | 14 +++-- arch/arm64/crypto/aes-ce-ccm-glue.c | 2 +- arch/arm64/crypto/aes-neonbs-glue.c | 2 +- arch/arm64/crypto/chacha-neon-glue.c | 2 +- arch/arm64/crypto/crct10dif-ce-glue.c | 4 +- arch/arm64/crypto/ghash-ce-glue.c | 8 +-- arch/arm64/crypto/nhpoly1305-neon-glue.c | 2 +- arch/arm64/crypto/sha256-glue.c | 4 +- arch/arm64/include/asm/cpufeature.h | 22 ++++---- arch/arm64/include/asm/hwcap.h | 52 ++++++++++++++++++- arch/arm64/include/uapi/asm/hwcap.h | 2 +- arch/arm64/kernel/cpufeature.c | 66 ++++++++++++------------ arch/arm64/kernel/cpuinfo.c | 2 +- arch/arm64/kernel/fpsimd.c | 4 +- drivers/clocksource/arm_arch_timer.c | 8 +++ 15 files changed, 131 insertions(+), 63 deletions(-)Documentation/arm64/elf_hwcaps.txt +6
-3@@ -13,9 +13,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 entry -of the auxilliary vector, and testing whether the relevant flags are -set, e.g. +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. bool floating_point_is_present(void) {@@ -194,3 +194,11 @@ HWCAP_PACG Functionality implied by ID_AA64ISAR1_EL1.GPA == 0b0001 or ID_AA64ISAR1_EL1.GPI == 0b0001, as described by Documentation/arm64/pointer-authentication.txt. + + +4. Unused AT_HWCAP bitsQuoted 8 lines
Documentation/arm64/elf_hwcaps.txt HWCAP_PACG · line 204
Quoted 5 lines
Documentation/arm64/elf_hwcaps.txt +5
-0+----------------------- + +Each AT_HWCAP and AT_HWCAP2 entry provides for up to 32 hwcaps contained +in bits [31:0]. For interoperation with userspace we guarantee that bits +62 and 63 of AT_HWCAP will always be returned as 0.I'm a little nervous about the first sentence here, since it could be taken to mean that we will never allocate 61:32. Mind if I drop it?
Quoted 3 lines
Ack: I don't think we want to say explicitly that we will never use those bits, apart from AT_HWCAP[63:62] for which there are specific reasons.
No problem with me. Thanks for making this change (and const_ilog2).
Quoted 33 lines
(For now of course, we won't use them.)
Quoted 20 lines
Quoted 20 lines
drivers/clocksource/arm_arch_timer.c +4
-0@@ -833,7 +833,11 @@ static void arch_timer_evtstrm_enable(int divider) cntkctl |= (divider <<ARCH_TIMER_EVT_TRIGGER_SHIFT ) |ARCH_TIMER_VIRT_EVT_EN ;arch_timer_set_cntkctl (cntkctl); +#ifdef CONFIG_ARM64 +cpu_set_named_feature (EVTSTRM ); +#else elf_hwcap |=HWCAP_EVTSTRM ; +#endif #ifdef CONFIG_COMPAT compat_elf_hwcap |=COMPAT_HWCAP_EVTSTRM ;#endif @@ -1055,7 +1059,11 @@ static int arch_timer_cpu_pm_notify(struct notifier_block *self, }else if (action ==CPU_PM_ENTER_FAILED || action ==CPU_PM_EXIT ) {arch_timer_set_cntkctl (__this_cpu_read (saved_cntkctl));Quoted 9 lines
drivers/clocksource/arm_arch_timer.c static int arch_timer_cpu_pm_notify(struct notifier_block *self, · line 1066
Quoted 5 lines
drivers/clocksource/arm_arch_timer.c +4
-0+#ifdef CONFIG_ARM64 +if (cpu_have_named_feature (EVTSTRM )) +#else if (elf_hwcap & HWCAP_EVTSTRM) +#endif I think this is an indication that the abstraction isn't quite right and should probably be done in an arch-helped via
asm/arch_timer.h. However, that can be done as a separate patch later on.
Quoted 5 lines
It probably does make sense to add an arch-specific helper for that.
Given that we don't want to encourage this kind of poking about in
elf_hwcap. It might make sense to have a single-purpose helper just for checking this flag.
I'll propose something in a separate patch.
Thanks,
Andrew Murray
Quoted 3 lines
Cheers
---Dave
PATCH v5 2/6 arm64: HWCAP: encapsulate elf_hwcap
In reply to Andrew MurrayThe introduction of AT_HWCAP2 introduced accessors which ensure that hwcap features are set and tested appropriately.
Let's now mandate access to elf_hwcap via these accessors by making elf_hwcap static within cpufeature.c.
--- arch/arm64/include/asm/cpufeature.h | 15 ++++--------- arch/arm64/include/asm/hwcap.h | 7 +++--- arch/arm64/kernel/cpufeature.c | 33 +++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 17 deletions(-)
arch/arm64/include/asm/cpufeature.h +4 -11
@@ -392,19 +392,12 @@ extern DECLARE_BITMAP(boot_capabilities, ARM64_NPATCHABLE);for_each_set_bit (cap, cpu_hwcaps,ARM64_NCAPS ) bool this_cpu_has_cap(unsigned int cap); +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 ); -static inline void cpu_set_feature (unsigned int num) -{ -WARN_ON (num >=MAX_CPU_FEATURES ); - elf_hwcap |=BIT (num); -}#define cpu_set_named_feature (name) cpu_set_feature(cpu_feature(name)) - -static inline bool cpu_have_feature (unsigned int num) -{ -WARN_ON (num >=MAX_CPU_FEATURES ); -return elf_hwcap &BIT (num); -}#define cpu_have_named_feature (name) cpu_have_feature(cpu_feature(name))/* System capability check for constant caps */
arch/arm64/include/asm/hwcap.h +3 -4
@@ -17,6 +17,7 @@#define __ASM_HWCAP_H#include <uapi/asm/hwcap.h> +#include <asm/cpufeature.h> #define COMPAT_HWCAP_HALF (1 << 1)#define COMPAT_HWCAP_THUMB (1 << 2)
@@ -40,7 +41,6 @@#define COMPAT_HWCAP2_CRC32 (1 << 4)#ifndef __ASSEMBLY__ -#include <linux/kernel.h> #include <linux/log2.h> /*
@@ -93,8 +93,8 @@* This yields a mask that user programs can use to figure out what * instruction set this cpu supports. */ -#define ELF_HWCAP lower_32_bits(elf_hwcap) -#define ELF_HWCAP2 upper_32_bits(elf_hwcap) +#define ELF_HWCAP cpu_get_elf_hwcap() +#define ELF_HWCAP2 cpu_get_elf_hwcap2()#ifdef CONFIG_COMPAT #define COMPAT_ELF_HWCAP (compat_elf_hwcap)
@@ -110,6 +110,5 @@ enum {#endif }; -extern unsigned long elf_hwcap;#endif #endif
arch/arm64/kernel/cpufeature.c +31 -2
@@ -35,8 +35,8 @@#include <asm/traps.h> #include <asm/virt.h> -unsigned long elf_hwcap__read_mostly ; -EXPORT_SYMBOL_GPL (elf_hwcap); +/* Kernel representation of AT_HWCAP and AT_HWCAP2 */ +static unsigned long elf_hwcap__read_mostly ;#ifdef CONFIG_COMPAT #define COMPAT_ELF_HWCAP_DEFAULT \
@@ -1947,6 +1947,35 @@ bool this_cpu_has_cap(unsigned int n)return false; } +void cpu_set_feature (unsigned int num) +{ +WARN_ON (num >=MAX_CPU_FEATURES ); + elf_hwcap |=BIT (num); +} +EXPORT_SYMBOL_GPL (cpu_set_feature); + +bool cpu_have_feature (unsigned int num) +{ +WARN_ON (num >=MAX_CPU_FEATURES ); +return elf_hwcap &BIT (num); +} +EXPORT_SYMBOL_GPL (cpu_have_feature); + +unsigned long cpu_get_elf_hwcap (void ) +{ +/* +* We currently only populate the first 32 bits of AT_HWCAP. Please +* note that for userspace compatibility we guarantee that bits 62 +* and 63 will always be returned as 0. +*/ +return lower_32_bits (elf_hwcap); +} + +unsigned long cpu_get_elf_hwcap2 (void ) +{ +return upper_32_bits (elf_hwcap); +} +static void __init setup_system_capabilities (void ) {/*
Signature · 1 line
2.21.0
PATCH v5 3/6 arm64: Handle trapped DC CVADP
In reply to Andrew MurrayThe ARMv8.5 DC CVADP instruction may be trapped to EL1 via SCTLR_EL1.UCI therefore let's provide a handler for it.
Just like the CVAP instruction we use a 'sys' instruction instead of the 'dc' alias to avoid build issues with older toolchains.
--- arch/arm64/include/asm/esr.h | 3 ++- arch/arm64/kernel/traps.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
arch/arm64/include/asm/esr.h +2 -1
@@ -198,9 +198,10 @@/* * User space cache operations have the following sysreg encoding * in System instructions. -* op0=1, op1=3, op2=1, crn=7, crm={ 5, 10, 11, 12, 14 }, WRITE (L=0) +* op0=1, op1=3, op2=1, crn=7, crm={ 5, 10, 11, 12, 13, 14 }, WRITE (L=0) */ #define ESR_ELx_SYS64_ISS_CRM_DC_CIVAC 14 +#define ESR_ELx_SYS64_ISS_CRM_DC_CVADP 13#define ESR_ELx_SYS64_ISS_CRM_DC_CVAP 12#define ESR_ELx_SYS64_ISS_CRM_DC_CVAU 11#define ESR_ELx_SYS64_ISS_CRM_DC_CVAC 10
arch/arm64/kernel/traps.c +3 -0
@@ -459,6 +459,9 @@ static void user_cache_maint_handler(unsigned int esr, struct pt_regs *regs)case ESR_ELx_SYS64_ISS_CRM_DC_CVAC:/* DC CVAC, gets promoted */ __user_cache_maint ("dc civac" , address, ret);break ; +case ESR_ELx_SYS64_ISS_CRM_DC_CVADP:/* DC CVADP */ +__user_cache_maint ("sys 3, c7, c13, 1" , address, ret); +break ;case ESR_ELx_SYS64_ISS_CRM_DC_CVAP:/* DC CVAP */ __user_cache_maint ("sys 3, c7, c12, 1" , address, ret);break ;
Signature · 1 line
2.21.0
PATCH v5 4/6 arm64: Expose DC CVADP to userspace
In reply to Andrew MurrayARMv8.5 builds upon the ARMv8.2 DC CVAP instruction by introducing a DC CVADP instruction which cleans the data cache to the point of deep persistence. Let's expose this support via the arm64 ELF hwcaps.
--- Documentation/arm64/elf_hwcaps.txt | 4 ++++ arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 5 +++++ arch/arm64/kernel/cpufeature.c | 1 + arch/arm64/kernel/cpuinfo.c | 1 + 5 files changed, 12 insertions(+)
Documentation/arm64/elf_hwcaps.txt +4 -0
@@ -135,6 +135,10 @@ HWCAP_DCPOP Functionality implied by ID_AA64ISAR1_EL1.DPB == 0b0001. +HWCAP2_DCPODP + + Functionality implied by ID_AA64ISAR1_EL1.DPB == 0b0010. + HWCAP_SHA3 Functionality implied by ID_AA64ISAR0_EL1.SHA3 == 0b0001.
arch/arm64/include/asm/hwcap.h +1 -0
@@ -88,6 +88,7 @@#define KERNEL_HWCAP_PACG __khwcap_feature(PACG)#define __khwcap2_feature (x) (ilog2(HWCAP2_ ## x) + 32) +#define KERNEL_HWCAP_DCPODP __khwcap2_feature(DCPODP)/* * This yields a mask that user programs can use to figure out what
arch/arm64/include/uapi/asm/hwcap.h +5 -0
@@ -53,4 +53,9 @@#define HWCAP_PACA (1 << 30)#define HWCAP_PACG (1UL << 31) +/* +* HWCAP2 flags - for AT_HWCAP2 +*/ +#define HWCAP2_DCPODP (1 << 0) +#endif /* _UAPI__ASM_HWCAP_H */
arch/arm64/kernel/cpufeature.c +1 -0
@@ -1591,6 +1591,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {HWCAP_CAP (SYS_ID_AA64PFR0_EL1 ,ID_AA64PFR0_ASIMD_SHIFT ,FTR_SIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_ASIMDHP ),HWCAP_CAP (SYS_ID_AA64PFR0_EL1 ,ID_AA64PFR0_DIT_SHIFT ,FTR_SIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_DIT ),HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_DPB_SHIFT ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_DCPOP ), +HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_DPB_SHIFT ,FTR_UNSIGNED ,2 ,CAP_HWCAP ,KERNEL_HWCAP_DCPODP ),HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_JSCVT_SHIFT ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_JSCVT ),HWCAP_CAP (SYS_ID_AA64ISAR1_EL1 ,ID_AA64ISAR1_FCMA_SHIFT ,FTR_UNSIGNED ,1 ,CAP_HWCAP ,KERNEL_HWCAP_FCMA ), HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_LRCPC),
arch/arm64/kernel/cpuinfo.c +1 -0
@@ -85,6 +85,7 @@ static const char *const hwcap_str[] = {"sb" ,"paca" ,"pacg" , +"dcpodp" , NULL };
Signature · 1 line
2.21.0
PATCH v5 5/6 arm64: add CVADP support to the cache maintenance helper
In reply to Andrew MurrayAllow users of dcache_by_line_op to specify cvadp as an op.
--- arch/arm64/include/asm/assembler.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/include/asm/assembler.h +4 -0
@@ -407,10 +407,14 @@ alternative_endif .ifc \op, cvap sys 3, c7, c12, 1, \kaddr // dc cvap .else + .ifc \op, cvadp + sys 3, c7, c13, 1, \kaddr // dc cvadp + .else dc \op, \kaddr .endif .endif .endif + .endif add \kaddr, \kaddr, \tmp1 cmp \kaddr, \size b.lo 9998b
Signature · 1 line
2.21.0
PATCH v5 6/6 arm64: Advertise ARM64_HAS_DCPODP cpu feature
In reply to Andrew MurrayAdvertise ARM64_HAS_DCPODP when both DC CVAP and DC CVADP are supported.
Even though we don't use this feature now, we provide it for consistency with DCPOP and anticipate it being used in the future.
--- arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/kernel/cpufeature.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -61,7 +61,8 @@#define ARM64_HAS_GENERIC_AUTH_ARCH 40#define ARM64_HAS_GENERIC_AUTH_IMP_DEF 41#define ARM64_HAS_IRQ_PRIO_MASKING 42 +#define ARM64_HAS_DCPODP 43 -#define ARM64_NCAPS 43 +#define ARM64_NCAPS 44#endif /* __ASM_CPUCAPS_H */
arch/arm64/kernel/cpufeature.c +10 -0
@@ -1340,6 +1340,16 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .field_pos = ID_AA64ISAR1_DPB_SHIFT, .min_field_value = 1, }, + { + .desc = "Data cache clean to Point of Deep Persistence", + .capability = ARM64_HAS_DCPODP, + .type = ARM64_CPUCAP_SYSTEM_FEATURE, + .matches = has_cpuid_feature, + .sys_reg = SYS_ID_AA64ISAR1_EL1, + .sign = FTR_UNSIGNED, + .field_pos = ID_AA64ISAR1_DPB_SHIFT, + .min_field_value = 2, + },#endif #ifdef CONFIG_ARM64_SVE {
Signature · 1 line
2.21.0