Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Contains CPU feature definitions |
| 4 | * |
| 5 | * Copyright (C) 2015 ARM Ltd. |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 8 | #define pr_fmt(fmt) "CPU features: " fmt |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 9 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 10 | #include <linux/bsearch.h> |
James Morse | 2a6dcb2 | 2016-10-18 11:27:46 +0100 | [diff] [blame] | 11 | #include <linux/cpumask.h> |
Vladimir Murzin | 5ffdfae | 2018-07-31 14:08:56 +0100 | [diff] [blame] | 12 | #include <linux/crash_dump.h> |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 13 | #include <linux/sort.h> |
James Morse | 2a6dcb2 | 2016-10-18 11:27:46 +0100 | [diff] [blame] | 14 | #include <linux/stop_machine.h> |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 15 | #include <linux/types.h> |
Laura Abbott | 2077be6 | 2017-01-10 13:35:49 -0800 | [diff] [blame] | 16 | #include <linux/mm.h> |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 17 | #include <linux/cpu.h> |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 18 | #include <asm/cpu.h> |
| 19 | #include <asm/cpufeature.h> |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 20 | #include <asm/cpu_ops.h> |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 21 | #include <asm/fpsimd.h> |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 22 | #include <asm/mmu_context.h> |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 23 | #include <asm/processor.h> |
Suzuki K. Poulose | cdcf817 | 2015-10-19 14:24:42 +0100 | [diff] [blame] | 24 | #include <asm/sysreg.h> |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 25 | #include <asm/traps.h> |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 26 | #include <asm/virt.h> |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 27 | |
Andrew Murray | aec0bff | 2019-04-09 10:52:41 +0100 | [diff] [blame] | 28 | /* Kernel representation of AT_HWCAP and AT_HWCAP2 */ |
| 29 | static unsigned long elf_hwcap __read_mostly; |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 30 | |
| 31 | #ifdef CONFIG_COMPAT |
| 32 | #define COMPAT_ELF_HWCAP_DEFAULT \ |
| 33 | (COMPAT_HWCAP_HALF|COMPAT_HWCAP_THUMB|\ |
| 34 | COMPAT_HWCAP_FAST_MULT|COMPAT_HWCAP_EDSP|\ |
Suzuki K Poulose | 7559950a | 2020-01-13 23:30:20 +0000 | [diff] [blame] | 35 | COMPAT_HWCAP_TLS|COMPAT_HWCAP_IDIV|\ |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 36 | COMPAT_HWCAP_LPAE) |
| 37 | unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT; |
| 38 | unsigned int compat_elf_hwcap2 __read_mostly; |
| 39 | #endif |
| 40 | |
| 41 | DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS); |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 42 | EXPORT_SYMBOL(cpu_hwcaps); |
Suzuki K Poulose | 82a3a21 | 2018-11-30 17:18:03 +0000 | [diff] [blame] | 43 | static struct arm64_cpu_capabilities const __ro_after_init *cpu_hwcaps_ptrs[ARM64_NCAPS]; |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 44 | |
Daniel Thompson | 0ceb0d5 | 2019-01-31 14:58:53 +0000 | [diff] [blame] | 45 | /* Need also bit for ARM64_CB_PATCH */ |
| 46 | DECLARE_BITMAP(boot_capabilities, ARM64_NPATCHABLE); |
| 47 | |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 48 | bool arm64_use_ng_mappings = false; |
| 49 | EXPORT_SYMBOL(arm64_use_ng_mappings); |
| 50 | |
Dave Martin | 8f1eec5 | 2017-10-31 15:51:09 +0000 | [diff] [blame] | 51 | /* |
| 52 | * Flag to indicate if we have computed the system wide |
| 53 | * capabilities based on the boot time active CPUs. This |
| 54 | * will be used to determine if a new booting CPU should |
| 55 | * go through the verification process to make sure that it |
| 56 | * supports the system capabilities, without using a hotplug |
Suzuki K Poulose | b51c6ac | 2020-01-13 23:30:17 +0000 | [diff] [blame] | 57 | * notifier. This is also used to decide if we could use |
| 58 | * the fast path for checking constant CPU caps. |
Dave Martin | 8f1eec5 | 2017-10-31 15:51:09 +0000 | [diff] [blame] | 59 | */ |
Suzuki K Poulose | b51c6ac | 2020-01-13 23:30:17 +0000 | [diff] [blame] | 60 | DEFINE_STATIC_KEY_FALSE(arm64_const_caps_ready); |
| 61 | EXPORT_SYMBOL(arm64_const_caps_ready); |
| 62 | static inline void finalize_system_capabilities(void) |
Dave Martin | 8f1eec5 | 2017-10-31 15:51:09 +0000 | [diff] [blame] | 63 | { |
Suzuki K Poulose | b51c6ac | 2020-01-13 23:30:17 +0000 | [diff] [blame] | 64 | static_branch_enable(&arm64_const_caps_ready); |
Dave Martin | 8f1eec5 | 2017-10-31 15:51:09 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Mark Rutland | 8effeaa | 2017-06-21 18:11:23 +0100 | [diff] [blame] | 67 | static int dump_cpu_hwcaps(struct notifier_block *self, unsigned long v, void *p) |
| 68 | { |
| 69 | /* file-wide pr_fmt adds "CPU features: " prefix */ |
| 70 | pr_emerg("0x%*pb\n", ARM64_NCAPS, &cpu_hwcaps); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static struct notifier_block cpu_hwcaps_notifier = { |
| 75 | .notifier_call = dump_cpu_hwcaps |
| 76 | }; |
| 77 | |
| 78 | static int __init register_cpu_hwcaps_dumper(void) |
| 79 | { |
| 80 | atomic_notifier_chain_register(&panic_notifier_list, |
| 81 | &cpu_hwcaps_notifier); |
| 82 | return 0; |
| 83 | } |
| 84 | __initcall(register_cpu_hwcaps_dumper); |
| 85 | |
Catalin Marinas | efd9e03 | 2016-09-05 18:25:48 +0100 | [diff] [blame] | 86 | DEFINE_STATIC_KEY_ARRAY_FALSE(cpu_hwcap_keys, ARM64_NCAPS); |
| 87 | EXPORT_SYMBOL(cpu_hwcap_keys); |
| 88 | |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 89 | #define __ARM64_FTR_BITS(SIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 90 | { \ |
Suzuki K. Poulose | 4f0a606 | 2015-11-18 17:08:57 +0000 | [diff] [blame] | 91 | .sign = SIGNED, \ |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 92 | .visible = VISIBLE, \ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 93 | .strict = STRICT, \ |
| 94 | .type = TYPE, \ |
| 95 | .shift = SHIFT, \ |
| 96 | .width = WIDTH, \ |
| 97 | .safe_val = SAFE_VAL, \ |
| 98 | } |
| 99 | |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 100 | /* Define a feature with unsigned values */ |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 101 | #define ARM64_FTR_BITS(VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \ |
| 102 | __ARM64_FTR_BITS(FTR_UNSIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) |
Suzuki K. Poulose | 4f0a606 | 2015-11-18 17:08:57 +0000 | [diff] [blame] | 103 | |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 104 | /* Define a feature with a signed value */ |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 105 | #define S_ARM64_FTR_BITS(VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \ |
| 106 | __ARM64_FTR_BITS(FTR_SIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 107 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 108 | #define ARM64_FTR_END \ |
| 109 | { \ |
| 110 | .width = 0, \ |
| 111 | } |
| 112 | |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 113 | /* meta feature for alternatives */ |
| 114 | static bool __maybe_unused |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 115 | cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused); |
| 116 | |
Vladimir Murzin | 5ffdfae | 2018-07-31 14:08:56 +0100 | [diff] [blame] | 117 | static void cpu_enable_cnp(struct arm64_cpu_capabilities const *cap); |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 118 | |
Amit Daniel Kachhap | 3ff047f | 2020-03-13 14:34:48 +0530 | [diff] [blame] | 119 | static bool __system_matches_cap(unsigned int n); |
| 120 | |
Suzuki K Poulose | 4aa8a47 | 2017-01-09 17:28:32 +0000 | [diff] [blame] | 121 | /* |
| 122 | * NOTE: Any changes to the visibility of features should be kept in |
| 123 | * sync with the documentation of the CPU feature register ABI. |
| 124 | */ |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 125 | static const struct arm64_ftr_bits ftr_id_aa64isar0[] = { |
Richard Henderson | 1a50ec0 | 2020-01-21 12:58:52 +0000 | [diff] [blame] | 126 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_RNDR_SHIFT, 4, 0), |
Suzuki K Poulose | 7206dc9 | 2018-03-12 10:04:14 +0000 | [diff] [blame] | 127 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_TS_SHIFT, 4, 0), |
Dongjiu Geng | 3b3b681 | 2017-12-13 18:13:56 +0800 | [diff] [blame] | 128 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_FHM_SHIFT, 4, 0), |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 129 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_DP_SHIFT, 4, 0), |
| 130 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SM4_SHIFT, 4, 0), |
| 131 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SM3_SHIFT, 4, 0), |
| 132 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA3_SHIFT, 4, 0), |
| 133 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_RDM_SHIFT, 4, 0), |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 134 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_ATOMICS_SHIFT, 4, 0), |
| 135 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_CRC32_SHIFT, 4, 0), |
| 136 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA2_SHIFT, 4, 0), |
| 137 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA1_SHIFT, 4, 0), |
| 138 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_AES_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 139 | ARM64_FTR_END, |
| 140 | }; |
| 141 | |
Suzuki K Poulose | c8c3798 | 2017-03-14 18:13:25 +0000 | [diff] [blame] | 142 | static const struct arm64_ftr_bits ftr_id_aa64isar1[] = { |
Steven Price | d4209d8 | 2019-12-16 11:33:37 +0000 | [diff] [blame] | 143 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_I8MM_SHIFT, 4, 0), |
| 144 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_DGH_SHIFT, 4, 0), |
| 145 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_BF16_SHIFT, 4, 0), |
| 146 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_SPECRES_SHIFT, 4, 0), |
Will Deacon | bd4fb6d | 2018-06-14 11:21:34 +0100 | [diff] [blame] | 147 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_SB_SHIFT, 4, 0), |
Julien Grall | 7230f7e | 2019-10-03 12:12:08 +0100 | [diff] [blame] | 148 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_FRINTTS_SHIFT, 4, 0), |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 149 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH), |
| 150 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_GPI_SHIFT, 4, 0), |
| 151 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH), |
| 152 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_GPA_SHIFT, 4, 0), |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 153 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_LRCPC_SHIFT, 4, 0), |
| 154 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_FCMA_SHIFT, 4, 0), |
| 155 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_JSCVT_SHIFT, 4, 0), |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 156 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH), |
| 157 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_API_SHIFT, 4, 0), |
| 158 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH), |
| 159 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_APA_SHIFT, 4, 0), |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 160 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR1_DPB_SHIFT, 4, 0), |
Suzuki K Poulose | c8c3798 | 2017-03-14 18:13:25 +0000 | [diff] [blame] | 161 | ARM64_FTR_END, |
| 162 | }; |
| 163 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 164 | static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { |
Will Deacon | 179a56f | 2017-11-27 18:29:30 +0000 | [diff] [blame] | 165 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV3_SHIFT, 4, 0), |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 166 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV2_SHIFT, 4, 0), |
Suzuki K Poulose | 7206dc9 | 2018-03-12 10:04:14 +0000 | [diff] [blame] | 167 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_DIT_SHIFT, 4, 0), |
Ionela Voinescu | 2c9d45b | 2020-03-05 09:06:21 +0000 | [diff] [blame] | 168 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_AMU_SHIFT, 4, 0), |
Dave Martin | 3fab399 | 2017-12-14 14:03:44 +0000 | [diff] [blame] | 169 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
| 170 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_SVE_SHIFT, 4, 0), |
Xie XiuQi | 64c0272 | 2018-01-15 19:38:56 +0000 | [diff] [blame] | 171 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_RAS_SHIFT, 4, 0), |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 172 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_GIC_SHIFT, 4, 0), |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 173 | S_ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI), |
| 174 | S_ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_FP_SHIFT, 4, ID_AA64PFR0_FP_NI), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 175 | /* Linux doesn't care about the EL3 */ |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 176 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_EL3_SHIFT, 4, 0), |
| 177 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_EL2_SHIFT, 4, 0), |
| 178 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_EL1_SHIFT, 4, ID_AA64PFR0_EL1_64BIT_ONLY), |
| 179 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_EL0_SHIFT, 4, ID_AA64PFR0_EL0_64BIT_ONLY), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 180 | ARM64_FTR_END, |
| 181 | }; |
| 182 | |
Will Deacon | d71be2b | 2018-06-15 11:37:34 +0100 | [diff] [blame] | 183 | static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = { |
| 184 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SSBS_SHIFT, 4, ID_AA64PFR1_SSBS_PSTATE_NI), |
| 185 | ARM64_FTR_END, |
| 186 | }; |
| 187 | |
Dave Martin | 06a916f | 2019-04-18 18:41:38 +0100 | [diff] [blame] | 188 | static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = { |
Julien Grall | ec52c71 | 2019-10-14 11:21:13 +0100 | [diff] [blame] | 189 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
Steven Price | d4209d8 | 2019-12-16 11:33:37 +0000 | [diff] [blame] | 190 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_F64MM_SHIFT, 4, 0), |
| 191 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
| 192 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_F32MM_SHIFT, 4, 0), |
| 193 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
| 194 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_I8MM_SHIFT, 4, 0), |
| 195 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
Julien Grall | ec52c71 | 2019-10-14 11:21:13 +0100 | [diff] [blame] | 196 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0), |
| 197 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
| 198 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0), |
| 199 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
Steven Price | d4209d8 | 2019-12-16 11:33:37 +0000 | [diff] [blame] | 200 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BF16_SHIFT, 4, 0), |
| 201 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
Julien Grall | ec52c71 | 2019-10-14 11:21:13 +0100 | [diff] [blame] | 202 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0), |
| 203 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
| 204 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0), |
| 205 | ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE), |
| 206 | FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0), |
Dave Martin | 06a916f | 2019-04-18 18:41:38 +0100 | [diff] [blame] | 207 | ARM64_FTR_END, |
| 208 | }; |
| 209 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 210 | static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = { |
Will Deacon | 5717fe5 | 2019-08-12 16:02:25 +0100 | [diff] [blame] | 211 | /* |
| 212 | * We already refuse to boot CPUs that don't support our configured |
| 213 | * page size, so we can only detect mismatches for a page size other |
| 214 | * than the one we're currently using. Unfortunately, SoCs like this |
| 215 | * exist in the wild so, even though we don't like it, we'll have to go |
| 216 | * along with it and treat them as non-strict. |
| 217 | */ |
| 218 | S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_TGRAN4_SHIFT, 4, ID_AA64MMFR0_TGRAN4_NI), |
| 219 | S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_TGRAN64_SHIFT, 4, ID_AA64MMFR0_TGRAN64_NI), |
| 220 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_TGRAN16_SHIFT, 4, ID_AA64MMFR0_TGRAN16_NI), |
| 221 | |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 222 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_BIGENDEL0_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 223 | /* Linux shouldn't care about secure memory */ |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 224 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_SNSMEM_SHIFT, 4, 0), |
| 225 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_BIGENDEL_SHIFT, 4, 0), |
| 226 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_ASID_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 227 | /* |
| 228 | * Differing PARange is fine as long as all peripherals and memory are mapped |
| 229 | * within the minimum PARange of all CPUs |
| 230 | */ |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 231 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_PARANGE_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 232 | ARM64_FTR_END, |
| 233 | }; |
| 234 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 235 | static const struct arm64_ftr_bits ftr_id_aa64mmfr1[] = { |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 236 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_PAN_SHIFT, 4, 0), |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 237 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_LOR_SHIFT, 4, 0), |
| 238 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_HPD_SHIFT, 4, 0), |
| 239 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_VHE_SHIFT, 4, 0), |
| 240 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_VMIDBITS_SHIFT, 4, 0), |
| 241 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_HADBS_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 242 | ARM64_FTR_END, |
| 243 | }; |
| 244 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 245 | static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = { |
Mark Brown | 3e6c69a | 2019-12-09 18:12:14 +0000 | [diff] [blame] | 246 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_E0PD_SHIFT, 4, 0), |
Marc Zyngier | e48d53a | 2018-04-06 12:27:28 +0100 | [diff] [blame] | 247 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_FWB_SHIFT, 4, 0), |
Suzuki K Poulose | 7206dc9 | 2018-03-12 10:04:14 +0000 | [diff] [blame] | 248 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_AT_SHIFT, 4, 0), |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 249 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_LVA_SHIFT, 4, 0), |
Sai Prakash Ranjan | 9d3f888 | 2020-04-21 15:29:15 +0100 | [diff] [blame] | 250 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_IESB_SHIFT, 4, 0), |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 251 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_LSM_SHIFT, 4, 0), |
| 252 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_UAO_SHIFT, 4, 0), |
| 253 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_CNP_SHIFT, 4, 0), |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 254 | ARM64_FTR_END, |
| 255 | }; |
| 256 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 257 | static const struct arm64_ftr_bits ftr_ctr[] = { |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 258 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, 31, 1, 1), /* RES1 */ |
| 259 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_DIC_SHIFT, 1, 1), |
| 260 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_IDC_SHIFT, 1, 1), |
Will Deacon | 147b963 | 2019-07-30 15:40:20 +0100 | [diff] [blame] | 261 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_OR_ZERO_SAFE, CTR_CWG_SHIFT, 4, 0), |
| 262 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_OR_ZERO_SAFE, CTR_ERG_SHIFT, 4, 0), |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 263 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_DMINLINE_SHIFT, 4, 1), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 264 | /* |
| 265 | * Linux can handle differing I-cache policies. Userspace JITs will |
Suzuki K Poulose | ee7bc63 | 2016-09-09 14:07:08 +0100 | [diff] [blame] | 266 | * make use of *minLine. |
Will Deacon | 155433c | 2017-03-10 20:32:22 +0000 | [diff] [blame] | 267 | * If we have differing I-cache policies, report it as the weakest - VIPT. |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 268 | */ |
Will Deacon | 155433c | 2017-03-10 20:32:22 +0000 | [diff] [blame] | 269 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_NONSTRICT, FTR_EXACT, 14, 2, ICACHE_POLICY_VIPT), /* L1Ip */ |
Suzuki K Poulose | 4c4a39d | 2018-07-04 23:07:45 +0100 | [diff] [blame] | 270 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_IMINLINE_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 271 | ARM64_FTR_END, |
| 272 | }; |
| 273 | |
Ard Biesheuvel | 675b056 | 2016-08-31 11:31:10 +0100 | [diff] [blame] | 274 | struct arm64_ftr_reg arm64_ftr_reg_ctrel0 = { |
| 275 | .name = "SYS_CTR_EL0", |
| 276 | .ftr_bits = ftr_ctr |
| 277 | }; |
| 278 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 279 | static const struct arm64_ftr_bits ftr_id_mmfr0[] = { |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 280 | S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 28, 4, 0xf), /* InnerShr */ |
| 281 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 24, 4, 0), /* FCSE */ |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 282 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, 20, 4, 0), /* AuxReg */ |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 283 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 0), /* TCM */ |
| 284 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 12, 4, 0), /* ShareLvl */ |
| 285 | S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 8, 4, 0xf), /* OuterShr */ |
| 286 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), /* PMSA */ |
| 287 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* VMSA */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 288 | ARM64_FTR_END, |
| 289 | }; |
| 290 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 291 | static const struct arm64_ftr_bits ftr_id_aa64dfr0[] = { |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 292 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_EXACT, 36, 28, 0), |
| 293 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64DFR0_PMSVER_SHIFT, 4, 0), |
| 294 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64DFR0_CTX_CMPS_SHIFT, 4, 0), |
| 295 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64DFR0_WRPS_SHIFT, 4, 0), |
| 296 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64DFR0_BRPS_SHIFT, 4, 0), |
Will Deacon | b20d1ba | 2016-07-25 16:17:52 +0100 | [diff] [blame] | 297 | /* |
| 298 | * We can instantiate multiple PMU instances with different levels |
| 299 | * of support. |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 300 | */ |
| 301 | S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_EXACT, ID_AA64DFR0_PMUVER_SHIFT, 4, 0), |
| 302 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_EXACT, ID_AA64DFR0_TRACEVER_SHIFT, 4, 0), |
| 303 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_EXACT, ID_AA64DFR0_DEBUGVER_SHIFT, 4, 0x6), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 304 | ARM64_FTR_END, |
| 305 | }; |
| 306 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 307 | static const struct arm64_ftr_bits ftr_mvfr2[] = { |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 308 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), /* FPMisc */ |
| 309 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* SIMDMisc */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 310 | ARM64_FTR_END, |
| 311 | }; |
| 312 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 313 | static const struct arm64_ftr_bits ftr_dczid[] = { |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 314 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, 4, 1, 1), /* DZP */ |
| 315 | ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* BS */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 316 | ARM64_FTR_END, |
| 317 | }; |
| 318 | |
| 319 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 320 | static const struct arm64_ftr_bits ftr_id_isar5[] = { |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 321 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR5_RDM_SHIFT, 4, 0), |
| 322 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR5_CRC32_SHIFT, 4, 0), |
| 323 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR5_SHA2_SHIFT, 4, 0), |
| 324 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR5_SHA1_SHIFT, 4, 0), |
| 325 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR5_AES_SHIFT, 4, 0), |
| 326 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR5_SEVL_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 327 | ARM64_FTR_END, |
| 328 | }; |
| 329 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 330 | static const struct arm64_ftr_bits ftr_id_mmfr4[] = { |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 331 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), /* ac2 */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 332 | ARM64_FTR_END, |
| 333 | }; |
| 334 | |
Will Deacon | 0113340 | 2020-04-21 15:29:16 +0100 | [diff] [blame] | 335 | static const struct arm64_ftr_bits ftr_id_isar4[] = { |
| 336 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_SWP_FRAC_SHIFT, 4, 0), |
| 337 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_PSR_M_SHIFT, 4, 0), |
| 338 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_SYNCH_PRIM_FRAC_SHIFT, 4, 0), |
| 339 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_BARRIER_SHIFT, 4, 0), |
| 340 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_SMC_SHIFT, 4, 0), |
| 341 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_WRITEBACK_SHIFT, 4, 0), |
| 342 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_WITHSHIFTS_SHIFT, 4, 0), |
| 343 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR4_UNPRIV_SHIFT, 4, 0), |
| 344 | ARM64_FTR_END, |
| 345 | }; |
| 346 | |
Anshuman Khandual | 8e3747b | 2019-12-17 20:17:32 +0530 | [diff] [blame] | 347 | static const struct arm64_ftr_bits ftr_id_isar6[] = { |
| 348 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR6_I8MM_SHIFT, 4, 0), |
| 349 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR6_BF16_SHIFT, 4, 0), |
| 350 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR6_SPECRES_SHIFT, 4, 0), |
| 351 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR6_SB_SHIFT, 4, 0), |
| 352 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR6_FHM_SHIFT, 4, 0), |
| 353 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR6_DP_SHIFT, 4, 0), |
| 354 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_ISAR6_JSCVT_SHIFT, 4, 0), |
| 355 | ARM64_FTR_END, |
| 356 | }; |
| 357 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 358 | static const struct arm64_ftr_bits ftr_id_pfr0[] = { |
Suzuki K Poulose | 5bdecb7 | 2017-10-19 16:39:02 +0100 | [diff] [blame] | 359 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 12, 4, 0), /* State3 */ |
| 360 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 8, 4, 0), /* State2 */ |
| 361 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), /* State1 */ |
| 362 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* State0 */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 363 | ARM64_FTR_END, |
| 364 | }; |
| 365 | |
Will Deacon | 0113340 | 2020-04-21 15:29:16 +0100 | [diff] [blame] | 366 | static const struct arm64_ftr_bits ftr_id_pfr1[] = { |
| 367 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_GIC_SHIFT, 4, 0), |
| 368 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_VIRT_FRAC_SHIFT, 4, 0), |
| 369 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_SEC_FRAC_SHIFT, 4, 0), |
| 370 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_GENTIMER_SHIFT, 4, 0), |
| 371 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_VIRTUALIZATION_SHIFT, 4, 0), |
| 372 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_MPROGMOD_SHIFT, 4, 0), |
| 373 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_SECURITY_SHIFT, 4, 0), |
| 374 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_PFR1_PROGMOD_SHIFT, 4, 0), |
| 375 | ARM64_FTR_END, |
| 376 | }; |
| 377 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 378 | static const struct arm64_ftr_bits ftr_id_dfr0[] = { |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 379 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 28, 4, 0), |
| 380 | S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 24, 4, 0xf), /* PerfMon */ |
| 381 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 20, 4, 0), |
| 382 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 0), |
| 383 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 12, 4, 0), |
| 384 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 8, 4, 0), |
| 385 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), |
| 386 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), |
Suzuki K Poulose | e534350 | 2016-01-26 10:58:13 +0000 | [diff] [blame] | 387 | ARM64_FTR_END, |
| 388 | }; |
| 389 | |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 390 | static const struct arm64_ftr_bits ftr_zcr[] = { |
| 391 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, |
| 392 | ZCR_ELx_LEN_SHIFT, ZCR_ELx_LEN_SIZE, 0), /* LEN */ |
| 393 | ARM64_FTR_END, |
| 394 | }; |
| 395 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 396 | /* |
| 397 | * Common ftr bits for a 32bit register with all hidden, strict |
| 398 | * attributes, with 4bit feature fields and a default safe value of |
| 399 | * 0. Covers the following 32bit registers: |
| 400 | * id_isar[0-4], id_mmfr[1-3], id_pfr1, mvfr[0-1] |
| 401 | */ |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 402 | static const struct arm64_ftr_bits ftr_generic_32bits[] = { |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 403 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 28, 4, 0), |
| 404 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 24, 4, 0), |
| 405 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 20, 4, 0), |
| 406 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 0), |
| 407 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 12, 4, 0), |
| 408 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 8, 4, 0), |
| 409 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), |
| 410 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 411 | ARM64_FTR_END, |
| 412 | }; |
| 413 | |
Suzuki K Poulose | eab43e8 | 2017-01-09 17:28:26 +0000 | [diff] [blame] | 414 | /* Table for a single 32bit feature value */ |
| 415 | static const struct arm64_ftr_bits ftr_single32[] = { |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 416 | ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_EXACT, 0, 32, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 417 | ARM64_FTR_END, |
| 418 | }; |
| 419 | |
Suzuki K Poulose | eab43e8 | 2017-01-09 17:28:26 +0000 | [diff] [blame] | 420 | static const struct arm64_ftr_bits ftr_raz[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 421 | ARM64_FTR_END, |
| 422 | }; |
| 423 | |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 424 | #define ARM64_FTR_REG(id, table) { \ |
| 425 | .sys_id = id, \ |
| 426 | .reg = &(struct arm64_ftr_reg){ \ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 427 | .name = #id, \ |
| 428 | .ftr_bits = &((table)[0]), \ |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 429 | }} |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 430 | |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 431 | static const struct __ftr_reg_entry { |
| 432 | u32 sys_id; |
| 433 | struct arm64_ftr_reg *reg; |
| 434 | } arm64_ftr_regs[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 435 | |
| 436 | /* Op1 = 0, CRn = 0, CRm = 1 */ |
| 437 | ARM64_FTR_REG(SYS_ID_PFR0_EL1, ftr_id_pfr0), |
Will Deacon | 0113340 | 2020-04-21 15:29:16 +0100 | [diff] [blame] | 438 | ARM64_FTR_REG(SYS_ID_PFR1_EL1, ftr_id_pfr1), |
Suzuki K Poulose | e534350 | 2016-01-26 10:58:13 +0000 | [diff] [blame] | 439 | ARM64_FTR_REG(SYS_ID_DFR0_EL1, ftr_id_dfr0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 440 | ARM64_FTR_REG(SYS_ID_MMFR0_EL1, ftr_id_mmfr0), |
| 441 | ARM64_FTR_REG(SYS_ID_MMFR1_EL1, ftr_generic_32bits), |
| 442 | ARM64_FTR_REG(SYS_ID_MMFR2_EL1, ftr_generic_32bits), |
| 443 | ARM64_FTR_REG(SYS_ID_MMFR3_EL1, ftr_generic_32bits), |
| 444 | |
| 445 | /* Op1 = 0, CRn = 0, CRm = 2 */ |
| 446 | ARM64_FTR_REG(SYS_ID_ISAR0_EL1, ftr_generic_32bits), |
| 447 | ARM64_FTR_REG(SYS_ID_ISAR1_EL1, ftr_generic_32bits), |
| 448 | ARM64_FTR_REG(SYS_ID_ISAR2_EL1, ftr_generic_32bits), |
| 449 | ARM64_FTR_REG(SYS_ID_ISAR3_EL1, ftr_generic_32bits), |
Will Deacon | 0113340 | 2020-04-21 15:29:16 +0100 | [diff] [blame] | 450 | ARM64_FTR_REG(SYS_ID_ISAR4_EL1, ftr_id_isar4), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 451 | ARM64_FTR_REG(SYS_ID_ISAR5_EL1, ftr_id_isar5), |
| 452 | ARM64_FTR_REG(SYS_ID_MMFR4_EL1, ftr_id_mmfr4), |
Anshuman Khandual | 8e3747b | 2019-12-17 20:17:32 +0530 | [diff] [blame] | 453 | ARM64_FTR_REG(SYS_ID_ISAR6_EL1, ftr_id_isar6), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 454 | |
| 455 | /* Op1 = 0, CRn = 0, CRm = 3 */ |
| 456 | ARM64_FTR_REG(SYS_MVFR0_EL1, ftr_generic_32bits), |
| 457 | ARM64_FTR_REG(SYS_MVFR1_EL1, ftr_generic_32bits), |
| 458 | ARM64_FTR_REG(SYS_MVFR2_EL1, ftr_mvfr2), |
| 459 | |
| 460 | /* Op1 = 0, CRn = 0, CRm = 4 */ |
| 461 | ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1, ftr_id_aa64pfr0), |
Will Deacon | d71be2b | 2018-06-15 11:37:34 +0100 | [diff] [blame] | 462 | ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1), |
Dave Martin | 06a916f | 2019-04-18 18:41:38 +0100 | [diff] [blame] | 463 | ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_id_aa64zfr0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 464 | |
| 465 | /* Op1 = 0, CRn = 0, CRm = 5 */ |
| 466 | ARM64_FTR_REG(SYS_ID_AA64DFR0_EL1, ftr_id_aa64dfr0), |
Suzuki K Poulose | eab43e8 | 2017-01-09 17:28:26 +0000 | [diff] [blame] | 467 | ARM64_FTR_REG(SYS_ID_AA64DFR1_EL1, ftr_raz), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 468 | |
| 469 | /* Op1 = 0, CRn = 0, CRm = 6 */ |
| 470 | ARM64_FTR_REG(SYS_ID_AA64ISAR0_EL1, ftr_id_aa64isar0), |
Suzuki K Poulose | c8c3798 | 2017-03-14 18:13:25 +0000 | [diff] [blame] | 471 | ARM64_FTR_REG(SYS_ID_AA64ISAR1_EL1, ftr_id_aa64isar1), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 472 | |
| 473 | /* Op1 = 0, CRn = 0, CRm = 7 */ |
| 474 | ARM64_FTR_REG(SYS_ID_AA64MMFR0_EL1, ftr_id_aa64mmfr0), |
| 475 | ARM64_FTR_REG(SYS_ID_AA64MMFR1_EL1, ftr_id_aa64mmfr1), |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 476 | ARM64_FTR_REG(SYS_ID_AA64MMFR2_EL1, ftr_id_aa64mmfr2), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 477 | |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 478 | /* Op1 = 0, CRn = 1, CRm = 2 */ |
| 479 | ARM64_FTR_REG(SYS_ZCR_EL1, ftr_zcr), |
| 480 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 481 | /* Op1 = 3, CRn = 0, CRm = 0 */ |
Ard Biesheuvel | 675b056 | 2016-08-31 11:31:10 +0100 | [diff] [blame] | 482 | { SYS_CTR_EL0, &arm64_ftr_reg_ctrel0 }, |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 483 | ARM64_FTR_REG(SYS_DCZID_EL0, ftr_dczid), |
| 484 | |
| 485 | /* Op1 = 3, CRn = 14, CRm = 0 */ |
Suzuki K Poulose | eab43e8 | 2017-01-09 17:28:26 +0000 | [diff] [blame] | 486 | ARM64_FTR_REG(SYS_CNTFRQ_EL0, ftr_single32), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | static int search_cmp_ftr_reg(const void *id, const void *regp) |
| 490 | { |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 491 | return (int)(unsigned long)id - (int)((const struct __ftr_reg_entry *)regp)->sys_id; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* |
| 495 | * get_arm64_ftr_reg - Lookup a feature register entry using its |
| 496 | * sys_reg() encoding. With the array arm64_ftr_regs sorted in the |
| 497 | * ascending order of sys_id , we use binary search to find a matching |
| 498 | * entry. |
| 499 | * |
| 500 | * returns - Upon success, matching ftr_reg entry for id. |
| 501 | * - NULL on failure. It is upto the caller to decide |
| 502 | * the impact of a failure. |
| 503 | */ |
| 504 | static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id) |
| 505 | { |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 506 | const struct __ftr_reg_entry *ret; |
| 507 | |
| 508 | ret = bsearch((const void *)(unsigned long)sys_id, |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 509 | arm64_ftr_regs, |
| 510 | ARRAY_SIZE(arm64_ftr_regs), |
| 511 | sizeof(arm64_ftr_regs[0]), |
| 512 | search_cmp_ftr_reg); |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 513 | if (ret) |
| 514 | return ret->reg; |
| 515 | return NULL; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 518 | static u64 arm64_ftr_set_value(const struct arm64_ftr_bits *ftrp, s64 reg, |
| 519 | s64 ftr_val) |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 520 | { |
| 521 | u64 mask = arm64_ftr_mask(ftrp); |
| 522 | |
| 523 | reg &= ~mask; |
| 524 | reg |= (ftr_val << ftrp->shift) & mask; |
| 525 | return reg; |
| 526 | } |
| 527 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 528 | static s64 arm64_ftr_safe_value(const struct arm64_ftr_bits *ftrp, s64 new, |
| 529 | s64 cur) |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 530 | { |
| 531 | s64 ret = 0; |
| 532 | |
| 533 | switch (ftrp->type) { |
| 534 | case FTR_EXACT: |
| 535 | ret = ftrp->safe_val; |
| 536 | break; |
| 537 | case FTR_LOWER_SAFE: |
| 538 | ret = new < cur ? new : cur; |
| 539 | break; |
Will Deacon | 147b963 | 2019-07-30 15:40:20 +0100 | [diff] [blame] | 540 | case FTR_HIGHER_OR_ZERO_SAFE: |
| 541 | if (!cur || !new) |
| 542 | break; |
| 543 | /* Fallthrough */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 544 | case FTR_HIGHER_SAFE: |
| 545 | ret = new > cur ? new : cur; |
| 546 | break; |
| 547 | default: |
| 548 | BUG(); |
| 549 | } |
| 550 | |
| 551 | return ret; |
| 552 | } |
| 553 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 554 | static void __init sort_ftr_regs(void) |
| 555 | { |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 556 | int i; |
| 557 | |
| 558 | /* Check that the array is sorted so that we can do the binary search */ |
| 559 | for (i = 1; i < ARRAY_SIZE(arm64_ftr_regs); i++) |
| 560 | BUG_ON(arm64_ftr_regs[i].sys_id < arm64_ftr_regs[i - 1].sys_id); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /* |
| 564 | * Initialise the CPU feature register from Boot CPU values. |
| 565 | * Also initiliases the strict_mask for the register. |
Mark Rutland | b389d79 | 2017-01-09 17:28:24 +0000 | [diff] [blame] | 566 | * Any bits that are not covered by an arm64_ftr_bits entry are considered |
| 567 | * RES0 for the system-wide value, and must strictly match. |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 568 | */ |
| 569 | static void __init init_cpu_ftr_reg(u32 sys_reg, u64 new) |
| 570 | { |
| 571 | u64 val = 0; |
| 572 | u64 strict_mask = ~0x0ULL; |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 573 | u64 user_mask = 0; |
Mark Rutland | b389d79 | 2017-01-09 17:28:24 +0000 | [diff] [blame] | 574 | u64 valid_mask = 0; |
| 575 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 576 | const struct arm64_ftr_bits *ftrp; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 577 | struct arm64_ftr_reg *reg = get_arm64_ftr_reg(sys_reg); |
| 578 | |
| 579 | BUG_ON(!reg); |
| 580 | |
韩科才 | 24b2cce | 2020-03-11 14:52:49 +0800 | [diff] [blame] | 581 | for (ftrp = reg->ftr_bits; ftrp->width; ftrp++) { |
Mark Rutland | b389d79 | 2017-01-09 17:28:24 +0000 | [diff] [blame] | 582 | u64 ftr_mask = arm64_ftr_mask(ftrp); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 583 | s64 ftr_new = arm64_ftr_value(ftrp, new); |
| 584 | |
| 585 | val = arm64_ftr_set_value(ftrp, val, ftr_new); |
Mark Rutland | b389d79 | 2017-01-09 17:28:24 +0000 | [diff] [blame] | 586 | |
| 587 | valid_mask |= ftr_mask; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 588 | if (!ftrp->strict) |
Mark Rutland | b389d79 | 2017-01-09 17:28:24 +0000 | [diff] [blame] | 589 | strict_mask &= ~ftr_mask; |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 590 | if (ftrp->visible) |
| 591 | user_mask |= ftr_mask; |
| 592 | else |
| 593 | reg->user_val = arm64_ftr_set_value(ftrp, |
| 594 | reg->user_val, |
| 595 | ftrp->safe_val); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 596 | } |
Mark Rutland | b389d79 | 2017-01-09 17:28:24 +0000 | [diff] [blame] | 597 | |
| 598 | val &= valid_mask; |
| 599 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 600 | reg->sys_val = val; |
| 601 | reg->strict_mask = strict_mask; |
Suzuki K Poulose | fe4fbdb | 2017-01-09 17:28:30 +0000 | [diff] [blame] | 602 | reg->user_mask = user_mask; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Suzuki K Poulose | 1e89bae | 2018-03-26 15:12:30 +0100 | [diff] [blame] | 605 | extern const struct arm64_cpu_capabilities arm64_errata[]; |
Suzuki K Poulose | 82a3a21 | 2018-11-30 17:18:03 +0000 | [diff] [blame] | 606 | static const struct arm64_cpu_capabilities arm64_features[]; |
| 607 | |
| 608 | static void __init |
| 609 | init_cpu_hwcaps_indirect_list_from_array(const struct arm64_cpu_capabilities *caps) |
| 610 | { |
| 611 | for (; caps->matches; caps++) { |
| 612 | if (WARN(caps->capability >= ARM64_NCAPS, |
| 613 | "Invalid capability %d\n", caps->capability)) |
| 614 | continue; |
| 615 | if (WARN(cpu_hwcaps_ptrs[caps->capability], |
| 616 | "Duplicate entry for capability %d\n", |
| 617 | caps->capability)) |
| 618 | continue; |
| 619 | cpu_hwcaps_ptrs[caps->capability] = caps; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | static void __init init_cpu_hwcaps_indirect_list(void) |
| 624 | { |
| 625 | init_cpu_hwcaps_indirect_list_from_array(arm64_features); |
| 626 | init_cpu_hwcaps_indirect_list_from_array(arm64_errata); |
| 627 | } |
| 628 | |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 629 | static void __init setup_boot_cpu_capabilities(void); |
Suzuki K Poulose | 1e89bae | 2018-03-26 15:12:30 +0100 | [diff] [blame] | 630 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 631 | void __init init_cpu_features(struct cpuinfo_arm64 *info) |
| 632 | { |
| 633 | /* Before we start using the tables, make sure it is sorted */ |
| 634 | sort_ftr_regs(); |
| 635 | |
| 636 | init_cpu_ftr_reg(SYS_CTR_EL0, info->reg_ctr); |
| 637 | init_cpu_ftr_reg(SYS_DCZID_EL0, info->reg_dczid); |
| 638 | init_cpu_ftr_reg(SYS_CNTFRQ_EL0, info->reg_cntfrq); |
| 639 | init_cpu_ftr_reg(SYS_ID_AA64DFR0_EL1, info->reg_id_aa64dfr0); |
| 640 | init_cpu_ftr_reg(SYS_ID_AA64DFR1_EL1, info->reg_id_aa64dfr1); |
| 641 | init_cpu_ftr_reg(SYS_ID_AA64ISAR0_EL1, info->reg_id_aa64isar0); |
| 642 | init_cpu_ftr_reg(SYS_ID_AA64ISAR1_EL1, info->reg_id_aa64isar1); |
| 643 | init_cpu_ftr_reg(SYS_ID_AA64MMFR0_EL1, info->reg_id_aa64mmfr0); |
| 644 | init_cpu_ftr_reg(SYS_ID_AA64MMFR1_EL1, info->reg_id_aa64mmfr1); |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 645 | init_cpu_ftr_reg(SYS_ID_AA64MMFR2_EL1, info->reg_id_aa64mmfr2); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 646 | init_cpu_ftr_reg(SYS_ID_AA64PFR0_EL1, info->reg_id_aa64pfr0); |
| 647 | init_cpu_ftr_reg(SYS_ID_AA64PFR1_EL1, info->reg_id_aa64pfr1); |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 648 | init_cpu_ftr_reg(SYS_ID_AA64ZFR0_EL1, info->reg_id_aa64zfr0); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 649 | |
| 650 | if (id_aa64pfr0_32bit_el0(info->reg_id_aa64pfr0)) { |
| 651 | init_cpu_ftr_reg(SYS_ID_DFR0_EL1, info->reg_id_dfr0); |
| 652 | init_cpu_ftr_reg(SYS_ID_ISAR0_EL1, info->reg_id_isar0); |
| 653 | init_cpu_ftr_reg(SYS_ID_ISAR1_EL1, info->reg_id_isar1); |
| 654 | init_cpu_ftr_reg(SYS_ID_ISAR2_EL1, info->reg_id_isar2); |
| 655 | init_cpu_ftr_reg(SYS_ID_ISAR3_EL1, info->reg_id_isar3); |
| 656 | init_cpu_ftr_reg(SYS_ID_ISAR4_EL1, info->reg_id_isar4); |
| 657 | init_cpu_ftr_reg(SYS_ID_ISAR5_EL1, info->reg_id_isar5); |
Anshuman Khandual | 8e3747b | 2019-12-17 20:17:32 +0530 | [diff] [blame] | 658 | init_cpu_ftr_reg(SYS_ID_ISAR6_EL1, info->reg_id_isar6); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 659 | init_cpu_ftr_reg(SYS_ID_MMFR0_EL1, info->reg_id_mmfr0); |
| 660 | init_cpu_ftr_reg(SYS_ID_MMFR1_EL1, info->reg_id_mmfr1); |
| 661 | init_cpu_ftr_reg(SYS_ID_MMFR2_EL1, info->reg_id_mmfr2); |
| 662 | init_cpu_ftr_reg(SYS_ID_MMFR3_EL1, info->reg_id_mmfr3); |
| 663 | init_cpu_ftr_reg(SYS_ID_PFR0_EL1, info->reg_id_pfr0); |
| 664 | init_cpu_ftr_reg(SYS_ID_PFR1_EL1, info->reg_id_pfr1); |
| 665 | init_cpu_ftr_reg(SYS_MVFR0_EL1, info->reg_mvfr0); |
| 666 | init_cpu_ftr_reg(SYS_MVFR1_EL1, info->reg_mvfr1); |
| 667 | init_cpu_ftr_reg(SYS_MVFR2_EL1, info->reg_mvfr2); |
| 668 | } |
| 669 | |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 670 | if (id_aa64pfr0_sve(info->reg_id_aa64pfr0)) { |
| 671 | init_cpu_ftr_reg(SYS_ZCR_EL1, info->reg_zcr); |
| 672 | sve_init_vq_map(); |
| 673 | } |
Suzuki K Poulose | 5e91107 | 2018-03-26 15:12:29 +0100 | [diff] [blame] | 674 | |
| 675 | /* |
Suzuki K Poulose | 82a3a21 | 2018-11-30 17:18:03 +0000 | [diff] [blame] | 676 | * Initialize the indirect array of CPU hwcaps capabilities pointers |
| 677 | * before we handle the boot CPU below. |
| 678 | */ |
| 679 | init_cpu_hwcaps_indirect_list(); |
| 680 | |
| 681 | /* |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 682 | * Detect and enable early CPU capabilities based on the boot CPU, |
| 683 | * after we have initialised the CPU feature infrastructure. |
Suzuki K Poulose | 5e91107 | 2018-03-26 15:12:29 +0100 | [diff] [blame] | 684 | */ |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 685 | setup_boot_cpu_capabilities(); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 686 | } |
| 687 | |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 688 | static void update_cpu_ftr_reg(struct arm64_ftr_reg *reg, u64 new) |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 689 | { |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 690 | const struct arm64_ftr_bits *ftrp; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 691 | |
| 692 | for (ftrp = reg->ftr_bits; ftrp->width; ftrp++) { |
| 693 | s64 ftr_cur = arm64_ftr_value(ftrp, reg->sys_val); |
| 694 | s64 ftr_new = arm64_ftr_value(ftrp, new); |
| 695 | |
| 696 | if (ftr_cur == ftr_new) |
| 697 | continue; |
| 698 | /* Find a safe value */ |
| 699 | ftr_new = arm64_ftr_safe_value(ftrp, ftr_new, ftr_cur); |
| 700 | reg->sys_val = arm64_ftr_set_value(ftrp, reg->sys_val, ftr_new); |
| 701 | } |
| 702 | |
| 703 | } |
| 704 | |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 705 | static int check_update_ftr_reg(u32 sys_id, int cpu, u64 val, u64 boot) |
Suzuki K. Poulose | cdcf817 | 2015-10-19 14:24:42 +0100 | [diff] [blame] | 706 | { |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 707 | struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id); |
| 708 | |
| 709 | BUG_ON(!regp); |
| 710 | update_cpu_ftr_reg(regp, val); |
| 711 | if ((boot & regp->strict_mask) == (val & regp->strict_mask)) |
| 712 | return 0; |
| 713 | pr_warn("SANITY CHECK: Unexpected variation in %s. Boot CPU: %#016llx, CPU%d: %#016llx\n", |
| 714 | regp->name, boot, cpu, val); |
| 715 | return 1; |
| 716 | } |
| 717 | |
Will Deacon | eab2f92 | 2020-04-21 15:29:20 +0100 | [diff] [blame^] | 718 | static void relax_cpu_ftr_reg(u32 sys_id, int field) |
| 719 | { |
| 720 | const struct arm64_ftr_bits *ftrp; |
| 721 | struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id); |
| 722 | |
| 723 | if (WARN_ON(!regp)) |
| 724 | return; |
| 725 | |
| 726 | for (ftrp = regp->ftr_bits; ftrp->width; ftrp++) { |
| 727 | if (ftrp->shift == field) { |
| 728 | regp->strict_mask &= ~arm64_ftr_mask(ftrp); |
| 729 | break; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /* Bogus field? */ |
| 734 | WARN_ON(!ftrp->width); |
| 735 | } |
| 736 | |
Will Deacon | 1efcfe7 | 2020-04-21 15:29:19 +0100 | [diff] [blame] | 737 | static int update_32bit_cpu_features(int cpu, struct cpuinfo_arm64 *info, |
| 738 | struct cpuinfo_arm64 *boot) |
| 739 | { |
| 740 | int taint = 0; |
| 741 | u64 pfr0 = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); |
| 742 | |
| 743 | /* |
| 744 | * If we don't have AArch32 at all then skip the checks entirely |
| 745 | * as the register values may be UNKNOWN and we're not going to be |
| 746 | * using them for anything. |
| 747 | */ |
| 748 | if (!id_aa64pfr0_32bit_el0(pfr0)) |
| 749 | return taint; |
| 750 | |
Will Deacon | eab2f92 | 2020-04-21 15:29:20 +0100 | [diff] [blame^] | 751 | /* |
| 752 | * If we don't have AArch32 at EL1, then relax the strictness of |
| 753 | * EL1-dependent register fields to avoid spurious sanity check fails. |
| 754 | */ |
| 755 | if (!id_aa64pfr0_32bit_el1(pfr0)) { |
| 756 | relax_cpu_ftr_reg(SYS_ID_ISAR4_EL1, ID_ISAR4_SMC_SHIFT); |
| 757 | relax_cpu_ftr_reg(SYS_ID_PFR1_EL1, ID_PFR1_VIRT_FRAC_SHIFT); |
| 758 | relax_cpu_ftr_reg(SYS_ID_PFR1_EL1, ID_PFR1_SEC_FRAC_SHIFT); |
| 759 | relax_cpu_ftr_reg(SYS_ID_PFR1_EL1, ID_PFR1_VIRTUALIZATION_SHIFT); |
| 760 | relax_cpu_ftr_reg(SYS_ID_PFR1_EL1, ID_PFR1_SECURITY_SHIFT); |
| 761 | relax_cpu_ftr_reg(SYS_ID_PFR1_EL1, ID_PFR1_PROGMOD_SHIFT); |
| 762 | } |
| 763 | |
Will Deacon | 1efcfe7 | 2020-04-21 15:29:19 +0100 | [diff] [blame] | 764 | taint |= check_update_ftr_reg(SYS_ID_DFR0_EL1, cpu, |
| 765 | info->reg_id_dfr0, boot->reg_id_dfr0); |
| 766 | taint |= check_update_ftr_reg(SYS_ID_ISAR0_EL1, cpu, |
| 767 | info->reg_id_isar0, boot->reg_id_isar0); |
| 768 | taint |= check_update_ftr_reg(SYS_ID_ISAR1_EL1, cpu, |
| 769 | info->reg_id_isar1, boot->reg_id_isar1); |
| 770 | taint |= check_update_ftr_reg(SYS_ID_ISAR2_EL1, cpu, |
| 771 | info->reg_id_isar2, boot->reg_id_isar2); |
| 772 | taint |= check_update_ftr_reg(SYS_ID_ISAR3_EL1, cpu, |
| 773 | info->reg_id_isar3, boot->reg_id_isar3); |
| 774 | taint |= check_update_ftr_reg(SYS_ID_ISAR4_EL1, cpu, |
| 775 | info->reg_id_isar4, boot->reg_id_isar4); |
| 776 | taint |= check_update_ftr_reg(SYS_ID_ISAR5_EL1, cpu, |
| 777 | info->reg_id_isar5, boot->reg_id_isar5); |
| 778 | taint |= check_update_ftr_reg(SYS_ID_ISAR6_EL1, cpu, |
| 779 | info->reg_id_isar6, boot->reg_id_isar6); |
| 780 | |
| 781 | /* |
| 782 | * Regardless of the value of the AuxReg field, the AIFSR, ADFSR, and |
| 783 | * ACTLR formats could differ across CPUs and therefore would have to |
| 784 | * be trapped for virtualization anyway. |
| 785 | */ |
| 786 | taint |= check_update_ftr_reg(SYS_ID_MMFR0_EL1, cpu, |
| 787 | info->reg_id_mmfr0, boot->reg_id_mmfr0); |
| 788 | taint |= check_update_ftr_reg(SYS_ID_MMFR1_EL1, cpu, |
| 789 | info->reg_id_mmfr1, boot->reg_id_mmfr1); |
| 790 | taint |= check_update_ftr_reg(SYS_ID_MMFR2_EL1, cpu, |
| 791 | info->reg_id_mmfr2, boot->reg_id_mmfr2); |
| 792 | taint |= check_update_ftr_reg(SYS_ID_MMFR3_EL1, cpu, |
| 793 | info->reg_id_mmfr3, boot->reg_id_mmfr3); |
| 794 | taint |= check_update_ftr_reg(SYS_ID_PFR0_EL1, cpu, |
| 795 | info->reg_id_pfr0, boot->reg_id_pfr0); |
| 796 | taint |= check_update_ftr_reg(SYS_ID_PFR1_EL1, cpu, |
| 797 | info->reg_id_pfr1, boot->reg_id_pfr1); |
| 798 | taint |= check_update_ftr_reg(SYS_MVFR0_EL1, cpu, |
| 799 | info->reg_mvfr0, boot->reg_mvfr0); |
| 800 | taint |= check_update_ftr_reg(SYS_MVFR1_EL1, cpu, |
| 801 | info->reg_mvfr1, boot->reg_mvfr1); |
| 802 | taint |= check_update_ftr_reg(SYS_MVFR2_EL1, cpu, |
| 803 | info->reg_mvfr2, boot->reg_mvfr2); |
| 804 | |
| 805 | return taint; |
| 806 | } |
| 807 | |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 808 | /* |
| 809 | * Update system wide CPU feature registers with the values from a |
| 810 | * non-boot CPU. Also performs SANITY checks to make sure that there |
| 811 | * aren't any insane variations from that of the boot CPU. |
| 812 | */ |
| 813 | void update_cpu_features(int cpu, |
| 814 | struct cpuinfo_arm64 *info, |
| 815 | struct cpuinfo_arm64 *boot) |
| 816 | { |
| 817 | int taint = 0; |
| 818 | |
| 819 | /* |
| 820 | * The kernel can handle differing I-cache policies, but otherwise |
| 821 | * caches should look identical. Userspace JITs will make use of |
| 822 | * *minLine. |
| 823 | */ |
| 824 | taint |= check_update_ftr_reg(SYS_CTR_EL0, cpu, |
| 825 | info->reg_ctr, boot->reg_ctr); |
| 826 | |
| 827 | /* |
| 828 | * Userspace may perform DC ZVA instructions. Mismatched block sizes |
| 829 | * could result in too much or too little memory being zeroed if a |
| 830 | * process is preempted and migrated between CPUs. |
| 831 | */ |
| 832 | taint |= check_update_ftr_reg(SYS_DCZID_EL0, cpu, |
| 833 | info->reg_dczid, boot->reg_dczid); |
| 834 | |
| 835 | /* If different, timekeeping will be broken (especially with KVM) */ |
| 836 | taint |= check_update_ftr_reg(SYS_CNTFRQ_EL0, cpu, |
| 837 | info->reg_cntfrq, boot->reg_cntfrq); |
| 838 | |
| 839 | /* |
| 840 | * The kernel uses self-hosted debug features and expects CPUs to |
| 841 | * support identical debug features. We presently need CTX_CMPs, WRPs, |
| 842 | * and BRPs to be identical. |
| 843 | * ID_AA64DFR1 is currently RES0. |
| 844 | */ |
| 845 | taint |= check_update_ftr_reg(SYS_ID_AA64DFR0_EL1, cpu, |
| 846 | info->reg_id_aa64dfr0, boot->reg_id_aa64dfr0); |
| 847 | taint |= check_update_ftr_reg(SYS_ID_AA64DFR1_EL1, cpu, |
| 848 | info->reg_id_aa64dfr1, boot->reg_id_aa64dfr1); |
| 849 | /* |
| 850 | * Even in big.LITTLE, processors should be identical instruction-set |
| 851 | * wise. |
| 852 | */ |
| 853 | taint |= check_update_ftr_reg(SYS_ID_AA64ISAR0_EL1, cpu, |
| 854 | info->reg_id_aa64isar0, boot->reg_id_aa64isar0); |
| 855 | taint |= check_update_ftr_reg(SYS_ID_AA64ISAR1_EL1, cpu, |
| 856 | info->reg_id_aa64isar1, boot->reg_id_aa64isar1); |
| 857 | |
| 858 | /* |
| 859 | * Differing PARange support is fine as long as all peripherals and |
| 860 | * memory are mapped within the minimum PARange of all CPUs. |
| 861 | * Linux should not care about secure memory. |
| 862 | */ |
| 863 | taint |= check_update_ftr_reg(SYS_ID_AA64MMFR0_EL1, cpu, |
| 864 | info->reg_id_aa64mmfr0, boot->reg_id_aa64mmfr0); |
| 865 | taint |= check_update_ftr_reg(SYS_ID_AA64MMFR1_EL1, cpu, |
| 866 | info->reg_id_aa64mmfr1, boot->reg_id_aa64mmfr1); |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 867 | taint |= check_update_ftr_reg(SYS_ID_AA64MMFR2_EL1, cpu, |
| 868 | info->reg_id_aa64mmfr2, boot->reg_id_aa64mmfr2); |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 869 | |
| 870 | /* |
| 871 | * EL3 is not our concern. |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 872 | */ |
| 873 | taint |= check_update_ftr_reg(SYS_ID_AA64PFR0_EL1, cpu, |
| 874 | info->reg_id_aa64pfr0, boot->reg_id_aa64pfr0); |
| 875 | taint |= check_update_ftr_reg(SYS_ID_AA64PFR1_EL1, cpu, |
| 876 | info->reg_id_aa64pfr1, boot->reg_id_aa64pfr1); |
| 877 | |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 878 | taint |= check_update_ftr_reg(SYS_ID_AA64ZFR0_EL1, cpu, |
| 879 | info->reg_id_aa64zfr0, boot->reg_id_aa64zfr0); |
| 880 | |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 881 | if (id_aa64pfr0_sve(info->reg_id_aa64pfr0)) { |
| 882 | taint |= check_update_ftr_reg(SYS_ZCR_EL1, cpu, |
| 883 | info->reg_zcr, boot->reg_zcr); |
| 884 | |
| 885 | /* Probe vector lengths, unless we already gave up on SVE */ |
| 886 | if (id_aa64pfr0_sve(read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1)) && |
Suzuki K Poulose | b51c6ac | 2020-01-13 23:30:17 +0000 | [diff] [blame] | 887 | !system_capabilities_finalized()) |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 888 | sve_update_vq_map(); |
| 889 | } |
| 890 | |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 891 | /* |
Will Deacon | 1efcfe7 | 2020-04-21 15:29:19 +0100 | [diff] [blame] | 892 | * This relies on a sanitised view of the AArch64 ID registers |
| 893 | * (e.g. SYS_ID_AA64PFR0_EL1), so we call it last. |
| 894 | */ |
| 895 | taint |= update_32bit_cpu_features(cpu, info, boot); |
| 896 | |
| 897 | /* |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 898 | * Mismatched CPU features are a recipe for disaster. Don't even |
| 899 | * pretend to support them. |
| 900 | */ |
Will Deacon | 8dd0ee6 | 2017-06-05 11:40:23 +0100 | [diff] [blame] | 901 | if (taint) { |
| 902 | pr_warn_once("Unsupported CPU feature variation detected.\n"); |
| 903 | add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); |
| 904 | } |
Suzuki K. Poulose | cdcf817 | 2015-10-19 14:24:42 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Dave Martin | 46823dd | 2017-03-23 15:14:39 +0000 | [diff] [blame] | 907 | u64 read_sanitised_ftr_reg(u32 id) |
Suzuki K. Poulose | b3f1537 | 2015-10-19 14:24:47 +0100 | [diff] [blame] | 908 | { |
| 909 | struct arm64_ftr_reg *regp = get_arm64_ftr_reg(id); |
| 910 | |
| 911 | /* We shouldn't get a request for an unsupported register */ |
| 912 | BUG_ON(!regp); |
| 913 | return regp->sys_val; |
| 914 | } |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 915 | |
Mark Rutland | 965861d | 2017-02-02 17:32:15 +0000 | [diff] [blame] | 916 | #define read_sysreg_case(r) \ |
| 917 | case r: return read_sysreg_s(r) |
| 918 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 919 | /* |
Dave Martin | 46823dd | 2017-03-23 15:14:39 +0000 | [diff] [blame] | 920 | * __read_sysreg_by_encoding() - Used by a STARTING cpu before cpuinfo is populated. |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 921 | * Read the system register on the current CPU |
| 922 | */ |
Dave Martin | 46823dd | 2017-03-23 15:14:39 +0000 | [diff] [blame] | 923 | static u64 __read_sysreg_by_encoding(u32 sys_id) |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 924 | { |
| 925 | switch (sys_id) { |
Mark Rutland | 965861d | 2017-02-02 17:32:15 +0000 | [diff] [blame] | 926 | read_sysreg_case(SYS_ID_PFR0_EL1); |
| 927 | read_sysreg_case(SYS_ID_PFR1_EL1); |
| 928 | read_sysreg_case(SYS_ID_DFR0_EL1); |
| 929 | read_sysreg_case(SYS_ID_MMFR0_EL1); |
| 930 | read_sysreg_case(SYS_ID_MMFR1_EL1); |
| 931 | read_sysreg_case(SYS_ID_MMFR2_EL1); |
| 932 | read_sysreg_case(SYS_ID_MMFR3_EL1); |
| 933 | read_sysreg_case(SYS_ID_ISAR0_EL1); |
| 934 | read_sysreg_case(SYS_ID_ISAR1_EL1); |
| 935 | read_sysreg_case(SYS_ID_ISAR2_EL1); |
| 936 | read_sysreg_case(SYS_ID_ISAR3_EL1); |
| 937 | read_sysreg_case(SYS_ID_ISAR4_EL1); |
| 938 | read_sysreg_case(SYS_ID_ISAR5_EL1); |
Anshuman Khandual | 8e3747b | 2019-12-17 20:17:32 +0530 | [diff] [blame] | 939 | read_sysreg_case(SYS_ID_ISAR6_EL1); |
Mark Rutland | 965861d | 2017-02-02 17:32:15 +0000 | [diff] [blame] | 940 | read_sysreg_case(SYS_MVFR0_EL1); |
| 941 | read_sysreg_case(SYS_MVFR1_EL1); |
| 942 | read_sysreg_case(SYS_MVFR2_EL1); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 943 | |
Mark Rutland | 965861d | 2017-02-02 17:32:15 +0000 | [diff] [blame] | 944 | read_sysreg_case(SYS_ID_AA64PFR0_EL1); |
| 945 | read_sysreg_case(SYS_ID_AA64PFR1_EL1); |
Dave Martin | 78ed70b | 2019-06-03 16:35:02 +0100 | [diff] [blame] | 946 | read_sysreg_case(SYS_ID_AA64ZFR0_EL1); |
Mark Rutland | 965861d | 2017-02-02 17:32:15 +0000 | [diff] [blame] | 947 | read_sysreg_case(SYS_ID_AA64DFR0_EL1); |
| 948 | read_sysreg_case(SYS_ID_AA64DFR1_EL1); |
| 949 | read_sysreg_case(SYS_ID_AA64MMFR0_EL1); |
| 950 | read_sysreg_case(SYS_ID_AA64MMFR1_EL1); |
| 951 | read_sysreg_case(SYS_ID_AA64MMFR2_EL1); |
| 952 | read_sysreg_case(SYS_ID_AA64ISAR0_EL1); |
| 953 | read_sysreg_case(SYS_ID_AA64ISAR1_EL1); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 954 | |
Mark Rutland | 965861d | 2017-02-02 17:32:15 +0000 | [diff] [blame] | 955 | read_sysreg_case(SYS_CNTFRQ_EL0); |
| 956 | read_sysreg_case(SYS_CTR_EL0); |
| 957 | read_sysreg_case(SYS_DCZID_EL0); |
| 958 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 959 | default: |
| 960 | BUG(); |
| 961 | return 0; |
| 962 | } |
| 963 | } |
| 964 | |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 965 | #include <linux/irqchip/arm-gic-v3.h> |
| 966 | |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 967 | static bool |
James Morse | 18ffa04 | 2015-07-21 13:23:29 +0100 | [diff] [blame] | 968 | feature_matches(u64 reg, const struct arm64_cpu_capabilities *entry) |
| 969 | { |
Suzuki K Poulose | 28c5dcb | 2016-01-26 10:58:16 +0000 | [diff] [blame] | 970 | int val = cpuid_feature_extract_field(reg, entry->field_pos, entry->sign); |
James Morse | 18ffa04 | 2015-07-21 13:23:29 +0100 | [diff] [blame] | 971 | |
| 972 | return val >= entry->min_field_value; |
| 973 | } |
| 974 | |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 975 | static bool |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 976 | has_cpuid_feature(const struct arm64_cpu_capabilities *entry, int scope) |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 977 | { |
| 978 | u64 val; |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 979 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 980 | WARN_ON(scope == SCOPE_LOCAL_CPU && preemptible()); |
| 981 | if (scope == SCOPE_SYSTEM) |
Dave Martin | 46823dd | 2017-03-23 15:14:39 +0000 | [diff] [blame] | 982 | val = read_sanitised_ftr_reg(entry->sys_reg); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 983 | else |
Dave Martin | 46823dd | 2017-03-23 15:14:39 +0000 | [diff] [blame] | 984 | val = __read_sysreg_by_encoding(entry->sys_reg); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 985 | |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 986 | return feature_matches(val, entry); |
| 987 | } |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 988 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 989 | static bool has_useable_gicv3_cpuif(const struct arm64_cpu_capabilities *entry, int scope) |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 990 | { |
| 991 | bool has_sre; |
| 992 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 993 | if (!has_cpuid_feature(entry, scope)) |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 994 | return false; |
| 995 | |
| 996 | has_sre = gic_enable_sre(); |
| 997 | if (!has_sre) |
| 998 | pr_warn_once("%s present but disabled by higher exception level\n", |
| 999 | entry->desc); |
| 1000 | |
| 1001 | return has_sre; |
| 1002 | } |
| 1003 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 1004 | static bool has_no_hw_prefetch(const struct arm64_cpu_capabilities *entry, int __unused) |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 1005 | { |
| 1006 | u32 midr = read_cpuid_id(); |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 1007 | |
| 1008 | /* Cavium ThunderX pass 1.x and 2.x */ |
Qian Cai | b99286b | 2019-08-05 23:05:03 -0400 | [diff] [blame] | 1009 | return midr_is_cpu_model_range(midr, MIDR_THUNDERX, |
Robert Richter | fa5ce3d | 2017-01-13 14:12:09 +0100 | [diff] [blame] | 1010 | MIDR_CPU_VAR_REV(0, 0), |
| 1011 | MIDR_CPU_VAR_REV(1, MIDR_REVISION_MASK)); |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 1014 | static bool has_no_fpsimd(const struct arm64_cpu_capabilities *entry, int __unused) |
| 1015 | { |
Dave Martin | 46823dd | 2017-03-23 15:14:39 +0000 | [diff] [blame] | 1016 | u64 pfr0 = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 1017 | |
| 1018 | return cpuid_feature_extract_signed_field(pfr0, |
| 1019 | ID_AA64PFR0_FP_SHIFT) < 0; |
| 1020 | } |
| 1021 | |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1022 | static bool has_cache_idc(const struct arm64_cpu_capabilities *entry, |
Suzuki K Poulose | 8ab66cb | 2018-10-09 14:47:05 +0100 | [diff] [blame] | 1023 | int scope) |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1024 | { |
Suzuki K Poulose | 8ab66cb | 2018-10-09 14:47:05 +0100 | [diff] [blame] | 1025 | u64 ctr; |
| 1026 | |
| 1027 | if (scope == SCOPE_SYSTEM) |
| 1028 | ctr = arm64_ftr_reg_ctrel0.sys_val; |
| 1029 | else |
Suzuki K Poulose | 1602df0 | 2018-10-09 14:47:06 +0100 | [diff] [blame] | 1030 | ctr = read_cpuid_effective_cachetype(); |
Suzuki K Poulose | 8ab66cb | 2018-10-09 14:47:05 +0100 | [diff] [blame] | 1031 | |
| 1032 | return ctr & BIT(CTR_IDC_SHIFT); |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1033 | } |
| 1034 | |
Suzuki K Poulose | 1602df0 | 2018-10-09 14:47:06 +0100 | [diff] [blame] | 1035 | static void cpu_emulate_effective_ctr(const struct arm64_cpu_capabilities *__unused) |
| 1036 | { |
| 1037 | /* |
| 1038 | * If the CPU exposes raw CTR_EL0.IDC = 0, while effectively |
| 1039 | * CTR_EL0.IDC = 1 (from CLIDR values), we need to trap accesses |
| 1040 | * to the CTR_EL0 on this CPU and emulate it with the real/safe |
| 1041 | * value. |
| 1042 | */ |
| 1043 | if (!(read_cpuid_cachetype() & BIT(CTR_IDC_SHIFT))) |
| 1044 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0); |
| 1045 | } |
| 1046 | |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1047 | static bool has_cache_dic(const struct arm64_cpu_capabilities *entry, |
Suzuki K Poulose | 8ab66cb | 2018-10-09 14:47:05 +0100 | [diff] [blame] | 1048 | int scope) |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1049 | { |
Suzuki K Poulose | 8ab66cb | 2018-10-09 14:47:05 +0100 | [diff] [blame] | 1050 | u64 ctr; |
| 1051 | |
| 1052 | if (scope == SCOPE_SYSTEM) |
| 1053 | ctr = arm64_ftr_reg_ctrel0.sys_val; |
| 1054 | else |
| 1055 | ctr = read_cpuid_cachetype(); |
| 1056 | |
| 1057 | return ctr & BIT(CTR_DIC_SHIFT); |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1058 | } |
| 1059 | |
Vladimir Murzin | 5ffdfae | 2018-07-31 14:08:56 +0100 | [diff] [blame] | 1060 | static bool __maybe_unused |
| 1061 | has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) |
| 1062 | { |
| 1063 | /* |
| 1064 | * Kdump isn't guaranteed to power-off all secondary CPUs, CNP |
| 1065 | * may share TLB entries with a CPU stuck in the crashed |
| 1066 | * kernel. |
| 1067 | */ |
| 1068 | if (is_kdump_kernel()) |
| 1069 | return false; |
| 1070 | |
| 1071 | return has_cpuid_feature(entry, scope); |
| 1072 | } |
| 1073 | |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1074 | /* |
| 1075 | * This check is triggered during the early boot before the cpufeature |
| 1076 | * is initialised. Checking the status on the local CPU allows the boot |
| 1077 | * CPU to detect the need for non-global mappings and thus avoiding a |
| 1078 | * pagetable re-write after all the CPUs are booted. This check will be |
| 1079 | * anyway run on individual CPUs, allowing us to get the consistent |
| 1080 | * state once the SMP CPUs are up and thus make the switch to non-global |
| 1081 | * mappings if required. |
| 1082 | */ |
| 1083 | bool kaslr_requires_kpti(void) |
| 1084 | { |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1085 | if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE)) |
| 1086 | return false; |
| 1087 | |
| 1088 | /* |
| 1089 | * E0PD does a similar job to KPTI so can be used instead |
| 1090 | * where available. |
| 1091 | */ |
| 1092 | if (IS_ENABLED(CONFIG_ARM64_E0PD)) { |
Will Deacon | a569f5f | 2020-01-15 14:06:37 +0000 | [diff] [blame] | 1093 | u64 mmfr2 = read_sysreg_s(SYS_ID_AA64MMFR2_EL1); |
| 1094 | if (cpuid_feature_extract_unsigned_field(mmfr2, |
| 1095 | ID_AA64MMFR2_E0PD_SHIFT)) |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1096 | return false; |
| 1097 | } |
| 1098 | |
| 1099 | /* |
| 1100 | * Systems affected by Cavium erratum 24756 are incompatible |
| 1101 | * with KPTI. |
| 1102 | */ |
Will Deacon | ebac96e | 2020-01-15 13:59:58 +0000 | [diff] [blame] | 1103 | if (IS_ENABLED(CONFIG_CAVIUM_ERRATUM_27456)) { |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1104 | extern const struct midr_range cavium_erratum_27456_cpus[]; |
| 1105 | |
Will Deacon | ebac96e | 2020-01-15 13:59:58 +0000 | [diff] [blame] | 1106 | if (is_midr_in_range_list(read_cpuid_id(), |
| 1107 | cavium_erratum_27456_cpus)) |
| 1108 | return false; |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1109 | } |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1110 | |
| 1111 | return kaslr_offset() > 0; |
| 1112 | } |
| 1113 | |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1114 | static bool __meltdown_safe = true; |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1115 | static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ |
| 1116 | |
| 1117 | static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, |
Suzuki K Poulose | d3aec8a | 2018-03-26 15:12:40 +0100 | [diff] [blame] | 1118 | int scope) |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1119 | { |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 1120 | /* List of CPUs that are not vulnerable and don't need KPTI */ |
| 1121 | static const struct midr_range kpti_safe_list[] = { |
| 1122 | MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), |
| 1123 | MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), |
Florian Fainelli | 31d868c | 2020-01-06 14:54:12 -0800 | [diff] [blame] | 1124 | MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53), |
Will Deacon | 2a355ec | 2018-12-13 13:47:38 +0000 | [diff] [blame] | 1125 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 1126 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 1127 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
| 1128 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), |
| 1129 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), |
| 1130 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), |
Hanjun Guo | 0ecc471 | 2019-03-05 21:40:58 +0800 | [diff] [blame] | 1131 | MIDR_ALL_VERSIONS(MIDR_HISI_TSV110), |
Rich Wiley | 918e194 | 2019-11-05 10:45:10 -0800 | [diff] [blame] | 1132 | MIDR_ALL_VERSIONS(MIDR_NVIDIA_CARMEL), |
Mark Rutland | 71c751f | 2018-04-23 11:41:33 +0100 | [diff] [blame] | 1133 | { /* sentinel */ } |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 1134 | }; |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 1135 | char const *str = "kpti command line option"; |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1136 | bool meltdown_safe; |
| 1137 | |
| 1138 | meltdown_safe = is_midr_in_range_list(read_cpuid_id(), kpti_safe_list); |
| 1139 | |
| 1140 | /* Defer to CPU feature registers */ |
| 1141 | if (has_cpuid_feature(entry, scope)) |
| 1142 | meltdown_safe = true; |
| 1143 | |
| 1144 | if (!meltdown_safe) |
| 1145 | __meltdown_safe = false; |
Will Deacon | 179a56f | 2017-11-27 18:29:30 +0000 | [diff] [blame] | 1146 | |
Marc Zyngier | 6dc52b1 | 2018-01-29 11:59:56 +0000 | [diff] [blame] | 1147 | /* |
| 1148 | * For reasons that aren't entirely clear, enabling KPTI on Cavium |
| 1149 | * ThunderX leads to apparent I-cache corruption of kernel text, which |
| 1150 | * ends as well as you might imagine. Don't even try. |
| 1151 | */ |
| 1152 | if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_27456)) { |
| 1153 | str = "ARM64_WORKAROUND_CAVIUM_27456"; |
| 1154 | __kpti_forced = -1; |
| 1155 | } |
| 1156 | |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1157 | /* Useful for KASLR robustness */ |
Mark Brown | c2d9235 | 2019-12-09 18:12:15 +0000 | [diff] [blame] | 1158 | if (kaslr_requires_kpti()) { |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1159 | if (!__kpti_forced) { |
| 1160 | str = "KASLR"; |
| 1161 | __kpti_forced = 1; |
| 1162 | } |
| 1163 | } |
| 1164 | |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 1165 | if (cpu_mitigations_off() && !__kpti_forced) { |
| 1166 | str = "mitigations=off"; |
| 1167 | __kpti_forced = -1; |
| 1168 | } |
| 1169 | |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1170 | if (!IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0)) { |
| 1171 | pr_info_once("kernel page table isolation disabled by kernel configuration\n"); |
| 1172 | return false; |
| 1173 | } |
| 1174 | |
Marc Zyngier | 6dc52b1 | 2018-01-29 11:59:56 +0000 | [diff] [blame] | 1175 | /* Forced? */ |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1176 | if (__kpti_forced) { |
Marc Zyngier | 6dc52b1 | 2018-01-29 11:59:56 +0000 | [diff] [blame] | 1177 | pr_info_once("kernel page table isolation forced %s by %s\n", |
| 1178 | __kpti_forced > 0 ? "ON" : "OFF", str); |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1179 | return __kpti_forced > 0; |
| 1180 | } |
| 1181 | |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1182 | return !meltdown_safe; |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1185 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1186 | static void |
| 1187 | kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) |
Will Deacon | f992b4d | 2018-02-06 22:22:50 +0000 | [diff] [blame] | 1188 | { |
| 1189 | typedef void (kpti_remap_fn)(int, int, phys_addr_t); |
| 1190 | extern kpti_remap_fn idmap_kpti_install_ng_mappings; |
| 1191 | kpti_remap_fn *remap_fn; |
| 1192 | |
Will Deacon | f992b4d | 2018-02-06 22:22:50 +0000 | [diff] [blame] | 1193 | int cpu = smp_processor_id(); |
| 1194 | |
Will Deacon | b89d82e | 2019-01-08 16:19:01 +0000 | [diff] [blame] | 1195 | /* |
| 1196 | * We don't need to rewrite the page-tables if either we've done |
| 1197 | * it already or we have KASLR enabled and therefore have not |
| 1198 | * created any global mappings at all. |
| 1199 | */ |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1200 | if (arm64_use_ng_mappings) |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1201 | return; |
Will Deacon | f992b4d | 2018-02-06 22:22:50 +0000 | [diff] [blame] | 1202 | |
| 1203 | remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings); |
| 1204 | |
| 1205 | cpu_install_idmap(); |
| 1206 | remap_fn(cpu, num_online_cpus(), __pa_symbol(swapper_pg_dir)); |
| 1207 | cpu_uninstall_idmap(); |
| 1208 | |
| 1209 | if (!cpu) |
Mark Brown | 09e3c22 | 2019-12-09 18:12:17 +0000 | [diff] [blame] | 1210 | arm64_use_ng_mappings = true; |
Will Deacon | f992b4d | 2018-02-06 22:22:50 +0000 | [diff] [blame] | 1211 | |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1212 | return; |
Will Deacon | f992b4d | 2018-02-06 22:22:50 +0000 | [diff] [blame] | 1213 | } |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 1214 | #else |
| 1215 | static void |
| 1216 | kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) |
| 1217 | { |
| 1218 | } |
| 1219 | #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ |
Will Deacon | f992b4d | 2018-02-06 22:22:50 +0000 | [diff] [blame] | 1220 | |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1221 | static int __init parse_kpti(char *str) |
| 1222 | { |
| 1223 | bool enabled; |
| 1224 | int ret = strtobool(str, &enabled); |
| 1225 | |
| 1226 | if (ret) |
| 1227 | return ret; |
| 1228 | |
| 1229 | __kpti_forced = enabled ? 1 : -1; |
| 1230 | return 0; |
| 1231 | } |
Will Deacon | b5b7dd6 | 2018-06-22 10:25:25 +0100 | [diff] [blame] | 1232 | early_param("kpti", parse_kpti); |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1233 | |
Suzuki K Poulose | 05abb59 | 2018-03-26 15:12:48 +0100 | [diff] [blame] | 1234 | #ifdef CONFIG_ARM64_HW_AFDBM |
| 1235 | static inline void __cpu_enable_hw_dbm(void) |
| 1236 | { |
| 1237 | u64 tcr = read_sysreg(tcr_el1) | TCR_HD; |
| 1238 | |
| 1239 | write_sysreg(tcr, tcr_el1); |
| 1240 | isb(); |
| 1241 | } |
| 1242 | |
Suzuki K Poulose | ece1397 | 2018-03-26 15:12:49 +0100 | [diff] [blame] | 1243 | static bool cpu_has_broken_dbm(void) |
| 1244 | { |
| 1245 | /* List of CPUs which have broken DBM support. */ |
| 1246 | static const struct midr_range cpus[] = { |
| 1247 | #ifdef CONFIG_ARM64_ERRATUM_1024718 |
| 1248 | MIDR_RANGE(MIDR_CORTEX_A55, 0, 0, 1, 0), // A55 r0p0 -r1p0 |
| 1249 | #endif |
| 1250 | {}, |
| 1251 | }; |
| 1252 | |
| 1253 | return is_midr_in_range_list(read_cpuid_id(), cpus); |
| 1254 | } |
| 1255 | |
Suzuki K Poulose | 05abb59 | 2018-03-26 15:12:48 +0100 | [diff] [blame] | 1256 | static bool cpu_can_use_dbm(const struct arm64_cpu_capabilities *cap) |
| 1257 | { |
Suzuki K Poulose | ece1397 | 2018-03-26 15:12:49 +0100 | [diff] [blame] | 1258 | return has_cpuid_feature(cap, SCOPE_LOCAL_CPU) && |
| 1259 | !cpu_has_broken_dbm(); |
Suzuki K Poulose | 05abb59 | 2018-03-26 15:12:48 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | static void cpu_enable_hw_dbm(struct arm64_cpu_capabilities const *cap) |
| 1263 | { |
| 1264 | if (cpu_can_use_dbm(cap)) |
| 1265 | __cpu_enable_hw_dbm(); |
| 1266 | } |
| 1267 | |
| 1268 | static bool has_hw_dbm(const struct arm64_cpu_capabilities *cap, |
| 1269 | int __unused) |
| 1270 | { |
| 1271 | static bool detected = false; |
| 1272 | /* |
| 1273 | * DBM is a non-conflicting feature. i.e, the kernel can safely |
| 1274 | * run a mix of CPUs with and without the feature. So, we |
| 1275 | * unconditionally enable the capability to allow any late CPU |
| 1276 | * to use the feature. We only enable the control bits on the |
| 1277 | * CPU, if it actually supports. |
| 1278 | * |
| 1279 | * We have to make sure we print the "feature" detection only |
| 1280 | * when at least one CPU actually uses it. So check if this CPU |
| 1281 | * can actually use it and print the message exactly once. |
| 1282 | * |
| 1283 | * This is safe as all CPUs (including secondary CPUs - due to the |
| 1284 | * LOCAL_CPU scope - and the hotplugged CPUs - via verification) |
| 1285 | * goes through the "matches" check exactly once. Also if a CPU |
| 1286 | * matches the criteria, it is guaranteed that the CPU will turn |
| 1287 | * the DBM on, as the capability is unconditionally enabled. |
| 1288 | */ |
| 1289 | if (!detected && cpu_can_use_dbm(cap)) { |
| 1290 | detected = true; |
| 1291 | pr_info("detected: Hardware dirty bit management\n"); |
| 1292 | } |
| 1293 | |
| 1294 | return true; |
| 1295 | } |
| 1296 | |
| 1297 | #endif |
| 1298 | |
Ionela Voinescu | 2c9d45b | 2020-03-05 09:06:21 +0000 | [diff] [blame] | 1299 | #ifdef CONFIG_ARM64_AMU_EXTN |
| 1300 | |
| 1301 | /* |
| 1302 | * The "amu_cpus" cpumask only signals that the CPU implementation for the |
| 1303 | * flagged CPUs supports the Activity Monitors Unit (AMU) but does not provide |
| 1304 | * information regarding all the events that it supports. When a CPU bit is |
| 1305 | * set in the cpumask, the user of this feature can only rely on the presence |
| 1306 | * of the 4 fixed counters for that CPU. But this does not guarantee that the |
| 1307 | * counters are enabled or access to these counters is enabled by code |
| 1308 | * executed at higher exception levels (firmware). |
| 1309 | */ |
| 1310 | static struct cpumask amu_cpus __read_mostly; |
| 1311 | |
| 1312 | bool cpu_has_amu_feat(int cpu) |
| 1313 | { |
| 1314 | return cpumask_test_cpu(cpu, &amu_cpus); |
| 1315 | } |
| 1316 | |
Ionela Voinescu | cd0ed03 | 2020-03-05 09:06:26 +0000 | [diff] [blame] | 1317 | /* Initialize the use of AMU counters for frequency invariance */ |
| 1318 | extern void init_cpu_freq_invariance_counters(void); |
| 1319 | |
Ionela Voinescu | 2c9d45b | 2020-03-05 09:06:21 +0000 | [diff] [blame] | 1320 | static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap) |
| 1321 | { |
| 1322 | if (has_cpuid_feature(cap, SCOPE_LOCAL_CPU)) { |
| 1323 | pr_info("detected CPU%d: Activity Monitors Unit (AMU)\n", |
| 1324 | smp_processor_id()); |
| 1325 | cpumask_set_cpu(smp_processor_id(), &amu_cpus); |
Ionela Voinescu | cd0ed03 | 2020-03-05 09:06:26 +0000 | [diff] [blame] | 1326 | init_cpu_freq_invariance_counters(); |
Ionela Voinescu | 2c9d45b | 2020-03-05 09:06:21 +0000 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | static bool has_amu(const struct arm64_cpu_capabilities *cap, |
| 1331 | int __unused) |
| 1332 | { |
| 1333 | /* |
| 1334 | * The AMU extension is a non-conflicting feature: the kernel can |
| 1335 | * safely run a mix of CPUs with and without support for the |
| 1336 | * activity monitors extension. Therefore, unconditionally enable |
| 1337 | * the capability to allow any late CPU to use the feature. |
| 1338 | * |
| 1339 | * With this feature unconditionally enabled, the cpu_enable |
| 1340 | * function will be called for all CPUs that match the criteria, |
| 1341 | * including secondary and hotplugged, marking this feature as |
| 1342 | * present on that respective CPU. The enable function will also |
| 1343 | * print a detection message. |
| 1344 | */ |
| 1345 | |
| 1346 | return true; |
| 1347 | } |
| 1348 | #endif |
| 1349 | |
Will Deacon | 12eb369 | 2018-03-27 11:51:12 +0100 | [diff] [blame] | 1350 | #ifdef CONFIG_ARM64_VHE |
| 1351 | static bool runs_at_el2(const struct arm64_cpu_capabilities *entry, int __unused) |
| 1352 | { |
| 1353 | return is_kernel_in_hyp_mode(); |
| 1354 | } |
| 1355 | |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1356 | static void cpu_copy_el2regs(const struct arm64_cpu_capabilities *__unused) |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 1357 | { |
| 1358 | /* |
| 1359 | * Copy register values that aren't redirected by hardware. |
| 1360 | * |
| 1361 | * Before code patching, we only set tpidr_el1, all CPUs need to copy |
| 1362 | * this value to tpidr_el2 before we patch the code. Once we've done |
| 1363 | * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to |
| 1364 | * do anything here. |
| 1365 | */ |
Julien Thierry | e9ab7a2 | 2019-01-31 14:58:52 +0000 | [diff] [blame] | 1366 | if (!alternative_is_applied(ARM64_HAS_VIRT_HOST_EXTN)) |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 1367 | write_sysreg(read_sysreg(tpidr_el1), tpidr_el2); |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 1368 | } |
Will Deacon | 12eb369 | 2018-03-27 11:51:12 +0100 | [diff] [blame] | 1369 | #endif |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 1370 | |
Marc Zyngier | e48d53a | 2018-04-06 12:27:28 +0100 | [diff] [blame] | 1371 | static void cpu_has_fwb(const struct arm64_cpu_capabilities *__unused) |
| 1372 | { |
| 1373 | u64 val = read_sysreg_s(SYS_CLIDR_EL1); |
| 1374 | |
| 1375 | /* Check that CLIDR_EL1.LOU{U,IS} are both 0 */ |
| 1376 | WARN_ON(val & (7 << 27 | 7 << 21)); |
| 1377 | } |
| 1378 | |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1379 | #ifdef CONFIG_ARM64_SSBD |
| 1380 | static int ssbs_emulation_handler(struct pt_regs *regs, u32 instr) |
| 1381 | { |
| 1382 | if (user_mode(regs)) |
| 1383 | return 1; |
| 1384 | |
Suzuki K Poulose | 74e2482 | 2018-09-16 23:17:23 +0100 | [diff] [blame] | 1385 | if (instr & BIT(PSTATE_Imm_shift)) |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1386 | regs->pstate |= PSR_SSBS_BIT; |
| 1387 | else |
| 1388 | regs->pstate &= ~PSR_SSBS_BIT; |
| 1389 | |
| 1390 | arm64_skip_faulting_instruction(regs, 4); |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | static struct undef_hook ssbs_emulation_hook = { |
Suzuki K Poulose | 74e2482 | 2018-09-16 23:17:23 +0100 | [diff] [blame] | 1395 | .instr_mask = ~(1U << PSTATE_Imm_shift), |
| 1396 | .instr_val = 0xd500401f | PSTATE_SSBS, |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1397 | .fn = ssbs_emulation_handler, |
| 1398 | }; |
| 1399 | |
| 1400 | static void cpu_enable_ssbs(const struct arm64_cpu_capabilities *__unused) |
| 1401 | { |
| 1402 | static bool undef_hook_registered = false; |
Julien Grall | 27e6e7d | 2019-05-30 12:30:58 +0100 | [diff] [blame] | 1403 | static DEFINE_RAW_SPINLOCK(hook_lock); |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1404 | |
Julien Grall | 27e6e7d | 2019-05-30 12:30:58 +0100 | [diff] [blame] | 1405 | raw_spin_lock(&hook_lock); |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1406 | if (!undef_hook_registered) { |
| 1407 | register_undef_hook(&ssbs_emulation_hook); |
| 1408 | undef_hook_registered = true; |
| 1409 | } |
Julien Grall | 27e6e7d | 2019-05-30 12:30:58 +0100 | [diff] [blame] | 1410 | raw_spin_unlock(&hook_lock); |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1411 | |
| 1412 | if (arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE) { |
| 1413 | sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_DSSBS); |
| 1414 | arm64_set_ssbd_mitigation(false); |
| 1415 | } else { |
| 1416 | arm64_set_ssbd_mitigation(true); |
| 1417 | } |
| 1418 | } |
| 1419 | #endif /* CONFIG_ARM64_SSBD */ |
| 1420 | |
Will Deacon | b8925ee | 2018-08-07 13:53:41 +0100 | [diff] [blame] | 1421 | #ifdef CONFIG_ARM64_PAN |
| 1422 | static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) |
| 1423 | { |
| 1424 | /* |
| 1425 | * We modify PSTATE. This won't work from irq context as the PSTATE |
| 1426 | * is discarded once we return from the exception. |
| 1427 | */ |
| 1428 | WARN_ON_ONCE(in_interrupt()); |
| 1429 | |
| 1430 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0); |
| 1431 | asm(SET_PSTATE_PAN(1)); |
| 1432 | } |
| 1433 | #endif /* CONFIG_ARM64_PAN */ |
| 1434 | |
| 1435 | #ifdef CONFIG_ARM64_RAS_EXTN |
| 1436 | static void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused) |
| 1437 | { |
| 1438 | /* Firmware may have left a deferred SError in this register. */ |
| 1439 | write_sysreg_s(0, SYS_DISR_EL1); |
| 1440 | } |
| 1441 | #endif /* CONFIG_ARM64_RAS_EXTN */ |
| 1442 | |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 1443 | #ifdef CONFIG_ARM64_PTR_AUTH |
Kristina Martsenko | cfef06b | 2020-03-13 14:34:49 +0530 | [diff] [blame] | 1444 | static bool has_address_auth(const struct arm64_cpu_capabilities *entry, |
| 1445 | int __unused) |
Mark Rutland | 7503197 | 2018-12-07 18:39:25 +0000 | [diff] [blame] | 1446 | { |
Kristina Martsenko | cfef06b | 2020-03-13 14:34:49 +0530 | [diff] [blame] | 1447 | return __system_matches_cap(ARM64_HAS_ADDRESS_AUTH_ARCH) || |
| 1448 | __system_matches_cap(ARM64_HAS_ADDRESS_AUTH_IMP_DEF); |
| 1449 | } |
| 1450 | |
| 1451 | static bool has_generic_auth(const struct arm64_cpu_capabilities *entry, |
| 1452 | int __unused) |
| 1453 | { |
| 1454 | return __system_matches_cap(ARM64_HAS_GENERIC_AUTH_ARCH) || |
| 1455 | __system_matches_cap(ARM64_HAS_GENERIC_AUTH_IMP_DEF); |
Mark Rutland | 7503197 | 2018-12-07 18:39:25 +0000 | [diff] [blame] | 1456 | } |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 1457 | #endif /* CONFIG_ARM64_PTR_AUTH */ |
| 1458 | |
Mark Brown | 3e6c69a | 2019-12-09 18:12:14 +0000 | [diff] [blame] | 1459 | #ifdef CONFIG_ARM64_E0PD |
| 1460 | static void cpu_enable_e0pd(struct arm64_cpu_capabilities const *cap) |
| 1461 | { |
| 1462 | if (this_cpu_has_cap(ARM64_HAS_E0PD)) |
| 1463 | sysreg_clear_set(tcr_el1, 0, TCR_E0PD1); |
| 1464 | } |
| 1465 | #endif /* CONFIG_ARM64_E0PD */ |
| 1466 | |
Julien Thierry | b90d2b2 | 2019-01-31 14:58:42 +0000 | [diff] [blame] | 1467 | #ifdef CONFIG_ARM64_PSEUDO_NMI |
Julien Thierry | bc3c03c | 2019-01-31 14:59:03 +0000 | [diff] [blame] | 1468 | static bool enable_pseudo_nmi; |
| 1469 | |
| 1470 | static int __init early_enable_pseudo_nmi(char *p) |
| 1471 | { |
| 1472 | return strtobool(p, &enable_pseudo_nmi); |
| 1473 | } |
| 1474 | early_param("irqchip.gicv3_pseudo_nmi", early_enable_pseudo_nmi); |
| 1475 | |
Julien Thierry | b90d2b2 | 2019-01-31 14:58:42 +0000 | [diff] [blame] | 1476 | static bool can_use_gic_priorities(const struct arm64_cpu_capabilities *entry, |
| 1477 | int scope) |
| 1478 | { |
Julien Thierry | bc3c03c | 2019-01-31 14:59:03 +0000 | [diff] [blame] | 1479 | return enable_pseudo_nmi && has_useable_gicv3_cpuif(entry, scope); |
Julien Thierry | b90d2b2 | 2019-01-31 14:58:42 +0000 | [diff] [blame] | 1480 | } |
| 1481 | #endif |
| 1482 | |
Amit Daniel Kachhap | 8c176e1 | 2020-03-13 14:34:53 +0530 | [diff] [blame] | 1483 | /* Internal helper functions to match cpu capability type */ |
| 1484 | static bool |
| 1485 | cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap) |
| 1486 | { |
| 1487 | return !!(cap->type & ARM64_CPUCAP_OPTIONAL_FOR_LATE_CPU); |
| 1488 | } |
| 1489 | |
| 1490 | static bool |
| 1491 | cpucap_late_cpu_permitted(const struct arm64_cpu_capabilities *cap) |
| 1492 | { |
| 1493 | return !!(cap->type & ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU); |
| 1494 | } |
| 1495 | |
Kristina Martsenko | deeaac5 | 2020-03-13 14:34:54 +0530 | [diff] [blame] | 1496 | static bool |
| 1497 | cpucap_panic_on_conflict(const struct arm64_cpu_capabilities *cap) |
| 1498 | { |
| 1499 | return !!(cap->type & ARM64_CPUCAP_PANIC_ON_CONFLICT); |
| 1500 | } |
| 1501 | |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1502 | static const struct arm64_cpu_capabilities arm64_features[] = { |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 1503 | { |
| 1504 | .desc = "GIC system register CPU interface", |
| 1505 | .capability = ARM64_HAS_SYSREG_GIC_CPUIF, |
Julien Thierry | c9bfdf7 | 2019-01-31 14:58:41 +0000 | [diff] [blame] | 1506 | .type = ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE, |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 1507 | .matches = has_useable_gicv3_cpuif, |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 1508 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1509 | .field_pos = ID_AA64PFR0_GIC_SHIFT, |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1510 | .sign = FTR_UNSIGNED, |
James Morse | 18ffa04 | 2015-07-21 13:23:29 +0100 | [diff] [blame] | 1511 | .min_field_value = 1, |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 1512 | }, |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 1513 | #ifdef CONFIG_ARM64_PAN |
| 1514 | { |
| 1515 | .desc = "Privileged Access Never", |
| 1516 | .capability = ARM64_HAS_PAN, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1517 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 1518 | .matches = has_cpuid_feature, |
| 1519 | .sys_reg = SYS_ID_AA64MMFR1_EL1, |
| 1520 | .field_pos = ID_AA64MMFR1_PAN_SHIFT, |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1521 | .sign = FTR_UNSIGNED, |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 1522 | .min_field_value = 1, |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1523 | .cpu_enable = cpu_enable_pan, |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 1524 | }, |
| 1525 | #endif /* CONFIG_ARM64_PAN */ |
Catalin Marinas | 395af86 | 2020-01-15 11:30:08 +0000 | [diff] [blame] | 1526 | #ifdef CONFIG_ARM64_LSE_ATOMICS |
Will Deacon | 2e94da1 | 2015-07-27 16:23:58 +0100 | [diff] [blame] | 1527 | { |
| 1528 | .desc = "LSE atomic instructions", |
| 1529 | .capability = ARM64_HAS_LSE_ATOMICS, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1530 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 1531 | .matches = has_cpuid_feature, |
| 1532 | .sys_reg = SYS_ID_AA64ISAR0_EL1, |
| 1533 | .field_pos = ID_AA64ISAR0_ATOMICS_SHIFT, |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1534 | .sign = FTR_UNSIGNED, |
Will Deacon | 2e94da1 | 2015-07-27 16:23:58 +0100 | [diff] [blame] | 1535 | .min_field_value = 2, |
| 1536 | }, |
Catalin Marinas | 395af86 | 2020-01-15 11:30:08 +0000 | [diff] [blame] | 1537 | #endif /* CONFIG_ARM64_LSE_ATOMICS */ |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 1538 | { |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 1539 | .desc = "Software prefetching using PRFM", |
| 1540 | .capability = ARM64_HAS_NO_HW_PREFETCH, |
Suzuki K Poulose | 5c13771 | 2018-03-26 15:12:39 +0100 | [diff] [blame] | 1541 | .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 1542 | .matches = has_no_hw_prefetch, |
| 1543 | }, |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 1544 | #ifdef CONFIG_ARM64_UAO |
| 1545 | { |
| 1546 | .desc = "User Access Override", |
| 1547 | .capability = ARM64_HAS_UAO, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1548 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 1549 | .matches = has_cpuid_feature, |
| 1550 | .sys_reg = SYS_ID_AA64MMFR2_EL1, |
| 1551 | .field_pos = ID_AA64MMFR2_UAO_SHIFT, |
| 1552 | .min_field_value = 1, |
James Morse | c8b06e3 | 2017-01-09 18:14:02 +0000 | [diff] [blame] | 1553 | /* |
| 1554 | * We rely on stop_machine() calling uao_thread_switch() to set |
| 1555 | * UAO immediately after patching. |
| 1556 | */ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 1557 | }, |
| 1558 | #endif /* CONFIG_ARM64_UAO */ |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 1559 | #ifdef CONFIG_ARM64_PAN |
| 1560 | { |
| 1561 | .capability = ARM64_ALT_PAN_NOT_UAO, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1562 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 1563 | .matches = cpufeature_pan_not_uao, |
| 1564 | }, |
| 1565 | #endif /* CONFIG_ARM64_PAN */ |
Suzuki K Poulose | 830dcc9 | 2018-03-26 15:12:42 +0100 | [diff] [blame] | 1566 | #ifdef CONFIG_ARM64_VHE |
Linus Torvalds | 588ab3f | 2016-03-17 20:03:47 -0700 | [diff] [blame] | 1567 | { |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 1568 | .desc = "Virtualization Host Extensions", |
| 1569 | .capability = ARM64_HAS_VIRT_HOST_EXTN, |
Suzuki K Poulose | 830dcc9 | 2018-03-26 15:12:42 +0100 | [diff] [blame] | 1570 | .type = ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE, |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 1571 | .matches = runs_at_el2, |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1572 | .cpu_enable = cpu_copy_el2regs, |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 1573 | }, |
Suzuki K Poulose | 830dcc9 | 2018-03-26 15:12:42 +0100 | [diff] [blame] | 1574 | #endif /* CONFIG_ARM64_VHE */ |
Suzuki K Poulose | 042446a | 2016-04-18 10:28:36 +0100 | [diff] [blame] | 1575 | { |
| 1576 | .desc = "32-bit EL0 Support", |
| 1577 | .capability = ARM64_HAS_32BIT_EL0, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1578 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Suzuki K Poulose | 042446a | 2016-04-18 10:28:36 +0100 | [diff] [blame] | 1579 | .matches = has_cpuid_feature, |
| 1580 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1581 | .sign = FTR_UNSIGNED, |
| 1582 | .field_pos = ID_AA64PFR0_EL0_SHIFT, |
| 1583 | .min_field_value = ID_AA64PFR0_EL0_32BIT_64BIT, |
| 1584 | }, |
Will Deacon | 540f76d | 2020-04-21 15:29:17 +0100 | [diff] [blame] | 1585 | #ifdef CONFIG_KVM |
| 1586 | { |
| 1587 | .desc = "32-bit EL1 Support", |
| 1588 | .capability = ARM64_HAS_32BIT_EL1, |
| 1589 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1590 | .matches = has_cpuid_feature, |
| 1591 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1592 | .sign = FTR_UNSIGNED, |
| 1593 | .field_pos = ID_AA64PFR0_EL1_SHIFT, |
| 1594 | .min_field_value = ID_AA64PFR0_EL1_32BIT_64BIT, |
| 1595 | }, |
| 1596 | #endif |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1597 | { |
Will Deacon | 179a56f | 2017-11-27 18:29:30 +0000 | [diff] [blame] | 1598 | .desc = "Kernel page table isolation (KPTI)", |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1599 | .capability = ARM64_UNMAP_KERNEL_AT_EL0, |
Suzuki K Poulose | d3aec8a | 2018-03-26 15:12:40 +0100 | [diff] [blame] | 1600 | .type = ARM64_CPUCAP_BOOT_RESTRICTED_CPU_LOCAL_FEATURE, |
| 1601 | /* |
| 1602 | * The ID feature fields below are used to indicate that |
| 1603 | * the CPU doesn't need KPTI. See unmap_kernel_at_el0 for |
| 1604 | * more details. |
| 1605 | */ |
| 1606 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1607 | .field_pos = ID_AA64PFR0_CSV3_SHIFT, |
| 1608 | .min_field_value = 1, |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1609 | .matches = unmap_kernel_at_el0, |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1610 | .cpu_enable = kpti_install_ng_mappings, |
Will Deacon | ea1e3de | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 1611 | }, |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 1612 | { |
| 1613 | /* FP/SIMD is not implemented */ |
| 1614 | .capability = ARM64_HAS_NO_FPSIMD, |
Suzuki K Poulose | 449443c | 2020-01-13 23:30:19 +0000 | [diff] [blame] | 1615 | .type = ARM64_CPUCAP_BOOT_RESTRICTED_CPU_LOCAL_FEATURE, |
Suzuki K Poulose | 82e0191 | 2016-11-08 13:56:21 +0000 | [diff] [blame] | 1616 | .min_field_value = 0, |
| 1617 | .matches = has_no_fpsimd, |
| 1618 | }, |
Robin Murphy | d50e071 | 2017-07-25 11:55:42 +0100 | [diff] [blame] | 1619 | #ifdef CONFIG_ARM64_PMEM |
| 1620 | { |
| 1621 | .desc = "Data cache clean to Point of Persistence", |
| 1622 | .capability = ARM64_HAS_DCPOP, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1623 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Robin Murphy | d50e071 | 2017-07-25 11:55:42 +0100 | [diff] [blame] | 1624 | .matches = has_cpuid_feature, |
| 1625 | .sys_reg = SYS_ID_AA64ISAR1_EL1, |
| 1626 | .field_pos = ID_AA64ISAR1_DPB_SHIFT, |
| 1627 | .min_field_value = 1, |
| 1628 | }, |
Andrew Murray | b9585f5 | 2019-04-09 10:52:45 +0100 | [diff] [blame] | 1629 | { |
| 1630 | .desc = "Data cache clean to Point of Deep Persistence", |
| 1631 | .capability = ARM64_HAS_DCPODP, |
| 1632 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1633 | .matches = has_cpuid_feature, |
| 1634 | .sys_reg = SYS_ID_AA64ISAR1_EL1, |
| 1635 | .sign = FTR_UNSIGNED, |
| 1636 | .field_pos = ID_AA64ISAR1_DPB_SHIFT, |
| 1637 | .min_field_value = 2, |
| 1638 | }, |
Robin Murphy | d50e071 | 2017-07-25 11:55:42 +0100 | [diff] [blame] | 1639 | #endif |
Dave Martin | 43994d8 | 2017-10-31 15:51:19 +0000 | [diff] [blame] | 1640 | #ifdef CONFIG_ARM64_SVE |
| 1641 | { |
| 1642 | .desc = "Scalable Vector Extension", |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1643 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Dave Martin | 43994d8 | 2017-10-31 15:51:19 +0000 | [diff] [blame] | 1644 | .capability = ARM64_SVE, |
Dave Martin | 43994d8 | 2017-10-31 15:51:19 +0000 | [diff] [blame] | 1645 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1646 | .sign = FTR_UNSIGNED, |
| 1647 | .field_pos = ID_AA64PFR0_SVE_SHIFT, |
| 1648 | .min_field_value = ID_AA64PFR0_SVE, |
| 1649 | .matches = has_cpuid_feature, |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1650 | .cpu_enable = sve_kernel_enable, |
Dave Martin | 43994d8 | 2017-10-31 15:51:19 +0000 | [diff] [blame] | 1651 | }, |
| 1652 | #endif /* CONFIG_ARM64_SVE */ |
Xie XiuQi | 64c0272 | 2018-01-15 19:38:56 +0000 | [diff] [blame] | 1653 | #ifdef CONFIG_ARM64_RAS_EXTN |
| 1654 | { |
| 1655 | .desc = "RAS Extension Support", |
| 1656 | .capability = ARM64_HAS_RAS_EXTN, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1657 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Xie XiuQi | 64c0272 | 2018-01-15 19:38:56 +0000 | [diff] [blame] | 1658 | .matches = has_cpuid_feature, |
| 1659 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1660 | .sign = FTR_UNSIGNED, |
| 1661 | .field_pos = ID_AA64PFR0_RAS_SHIFT, |
| 1662 | .min_field_value = ID_AA64PFR0_RAS_V1, |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 1663 | .cpu_enable = cpu_clear_disr, |
Xie XiuQi | 64c0272 | 2018-01-15 19:38:56 +0000 | [diff] [blame] | 1664 | }, |
| 1665 | #endif /* CONFIG_ARM64_RAS_EXTN */ |
Ionela Voinescu | 2c9d45b | 2020-03-05 09:06:21 +0000 | [diff] [blame] | 1666 | #ifdef CONFIG_ARM64_AMU_EXTN |
| 1667 | { |
| 1668 | /* |
| 1669 | * The feature is enabled by default if CONFIG_ARM64_AMU_EXTN=y. |
| 1670 | * Therefore, don't provide .desc as we don't want the detection |
| 1671 | * message to be shown until at least one CPU is detected to |
| 1672 | * support the feature. |
| 1673 | */ |
| 1674 | .capability = ARM64_HAS_AMU_EXTN, |
| 1675 | .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, |
| 1676 | .matches = has_amu, |
| 1677 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1678 | .sign = FTR_UNSIGNED, |
| 1679 | .field_pos = ID_AA64PFR0_AMU_SHIFT, |
| 1680 | .min_field_value = ID_AA64PFR0_AMU, |
| 1681 | .cpu_enable = cpu_amu_enable, |
| 1682 | }, |
| 1683 | #endif /* CONFIG_ARM64_AMU_EXTN */ |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1684 | { |
| 1685 | .desc = "Data cache clean to the PoU not required for I/D coherence", |
| 1686 | .capability = ARM64_HAS_CACHE_IDC, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1687 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1688 | .matches = has_cache_idc, |
Suzuki K Poulose | 1602df0 | 2018-10-09 14:47:06 +0100 | [diff] [blame] | 1689 | .cpu_enable = cpu_emulate_effective_ctr, |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1690 | }, |
| 1691 | { |
| 1692 | .desc = "Instruction cache invalidation not required for I/D coherence", |
| 1693 | .capability = ARM64_HAS_CACHE_DIC, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 1694 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Shanker Donthineni | 6ae4b6e | 2018-03-07 09:00:08 -0600 | [diff] [blame] | 1695 | .matches = has_cache_dic, |
| 1696 | }, |
Marc Zyngier | e48d53a | 2018-04-06 12:27:28 +0100 | [diff] [blame] | 1697 | { |
| 1698 | .desc = "Stage-2 Force Write-Back", |
| 1699 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1700 | .capability = ARM64_HAS_STAGE2_FWB, |
| 1701 | .sys_reg = SYS_ID_AA64MMFR2_EL1, |
| 1702 | .sign = FTR_UNSIGNED, |
| 1703 | .field_pos = ID_AA64MMFR2_FWB_SHIFT, |
| 1704 | .min_field_value = 1, |
| 1705 | .matches = has_cpuid_feature, |
| 1706 | .cpu_enable = cpu_has_fwb, |
| 1707 | }, |
Suzuki K Poulose | 05abb59 | 2018-03-26 15:12:48 +0100 | [diff] [blame] | 1708 | #ifdef CONFIG_ARM64_HW_AFDBM |
| 1709 | { |
| 1710 | /* |
| 1711 | * Since we turn this on always, we don't want the user to |
| 1712 | * think that the feature is available when it may not be. |
| 1713 | * So hide the description. |
| 1714 | * |
| 1715 | * .desc = "Hardware pagetable Dirty Bit Management", |
| 1716 | * |
| 1717 | */ |
| 1718 | .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, |
| 1719 | .capability = ARM64_HW_DBM, |
| 1720 | .sys_reg = SYS_ID_AA64MMFR1_EL1, |
| 1721 | .sign = FTR_UNSIGNED, |
| 1722 | .field_pos = ID_AA64MMFR1_HADBS_SHIFT, |
| 1723 | .min_field_value = 2, |
| 1724 | .matches = has_hw_dbm, |
| 1725 | .cpu_enable = cpu_enable_hw_dbm, |
| 1726 | }, |
| 1727 | #endif |
Ard Biesheuvel | 86d0dd3 | 2018-08-27 13:02:43 +0200 | [diff] [blame] | 1728 | { |
| 1729 | .desc = "CRC32 instructions", |
| 1730 | .capability = ARM64_HAS_CRC32, |
| 1731 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1732 | .matches = has_cpuid_feature, |
| 1733 | .sys_reg = SYS_ID_AA64ISAR0_EL1, |
| 1734 | .field_pos = ID_AA64ISAR0_CRC32_SHIFT, |
| 1735 | .min_field_value = 1, |
| 1736 | }, |
Will Deacon | 4f9f496 | 2018-11-21 15:07:00 +0000 | [diff] [blame] | 1737 | #ifdef CONFIG_ARM64_SSBD |
Will Deacon | d71be2b | 2018-06-15 11:37:34 +0100 | [diff] [blame] | 1738 | { |
| 1739 | .desc = "Speculative Store Bypassing Safe (SSBS)", |
| 1740 | .capability = ARM64_SSBS, |
| 1741 | .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, |
| 1742 | .matches = has_cpuid_feature, |
| 1743 | .sys_reg = SYS_ID_AA64PFR1_EL1, |
| 1744 | .field_pos = ID_AA64PFR1_SSBS_SHIFT, |
| 1745 | .sign = FTR_UNSIGNED, |
| 1746 | .min_field_value = ID_AA64PFR1_SSBS_PSTATE_ONLY, |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1747 | .cpu_enable = cpu_enable_ssbs, |
Will Deacon | d71be2b | 2018-06-15 11:37:34 +0100 | [diff] [blame] | 1748 | }, |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 1749 | #endif |
Vladimir Murzin | 5ffdfae | 2018-07-31 14:08:56 +0100 | [diff] [blame] | 1750 | #ifdef CONFIG_ARM64_CNP |
| 1751 | { |
| 1752 | .desc = "Common not Private translations", |
| 1753 | .capability = ARM64_HAS_CNP, |
| 1754 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1755 | .matches = has_useable_cnp, |
| 1756 | .sys_reg = SYS_ID_AA64MMFR2_EL1, |
| 1757 | .sign = FTR_UNSIGNED, |
| 1758 | .field_pos = ID_AA64MMFR2_CNP_SHIFT, |
| 1759 | .min_field_value = 1, |
| 1760 | .cpu_enable = cpu_enable_cnp, |
| 1761 | }, |
| 1762 | #endif |
Will Deacon | bd4fb6d | 2018-06-14 11:21:34 +0100 | [diff] [blame] | 1763 | { |
| 1764 | .desc = "Speculation barrier (SB)", |
| 1765 | .capability = ARM64_HAS_SB, |
| 1766 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1767 | .matches = has_cpuid_feature, |
| 1768 | .sys_reg = SYS_ID_AA64ISAR1_EL1, |
| 1769 | .field_pos = ID_AA64ISAR1_SB_SHIFT, |
| 1770 | .sign = FTR_UNSIGNED, |
| 1771 | .min_field_value = 1, |
| 1772 | }, |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 1773 | #ifdef CONFIG_ARM64_PTR_AUTH |
| 1774 | { |
| 1775 | .desc = "Address authentication (architected algorithm)", |
| 1776 | .capability = ARM64_HAS_ADDRESS_AUTH_ARCH, |
Kristina Martsenko | 6982934 | 2020-03-13 14:34:55 +0530 | [diff] [blame] | 1777 | .type = ARM64_CPUCAP_BOOT_CPU_FEATURE, |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 1778 | .sys_reg = SYS_ID_AA64ISAR1_EL1, |
| 1779 | .sign = FTR_UNSIGNED, |
| 1780 | .field_pos = ID_AA64ISAR1_APA_SHIFT, |
| 1781 | .min_field_value = ID_AA64ISAR1_APA_ARCHITECTED, |
| 1782 | .matches = has_cpuid_feature, |
| 1783 | }, |
| 1784 | { |
| 1785 | .desc = "Address authentication (IMP DEF algorithm)", |
| 1786 | .capability = ARM64_HAS_ADDRESS_AUTH_IMP_DEF, |
Kristina Martsenko | 6982934 | 2020-03-13 14:34:55 +0530 | [diff] [blame] | 1787 | .type = ARM64_CPUCAP_BOOT_CPU_FEATURE, |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 1788 | .sys_reg = SYS_ID_AA64ISAR1_EL1, |
| 1789 | .sign = FTR_UNSIGNED, |
| 1790 | .field_pos = ID_AA64ISAR1_API_SHIFT, |
| 1791 | .min_field_value = ID_AA64ISAR1_API_IMP_DEF, |
| 1792 | .matches = has_cpuid_feature, |
Kristina Martsenko | cfef06b | 2020-03-13 14:34:49 +0530 | [diff] [blame] | 1793 | }, |
| 1794 | { |
| 1795 | .capability = ARM64_HAS_ADDRESS_AUTH, |
Kristina Martsenko | 6982934 | 2020-03-13 14:34:55 +0530 | [diff] [blame] | 1796 | .type = ARM64_CPUCAP_BOOT_CPU_FEATURE, |
Kristina Martsenko | cfef06b | 2020-03-13 14:34:49 +0530 | [diff] [blame] | 1797 | .matches = has_address_auth, |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 1798 | }, |
| 1799 | { |
| 1800 | .desc = "Generic authentication (architected algorithm)", |
| 1801 | .capability = ARM64_HAS_GENERIC_AUTH_ARCH, |
| 1802 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1803 | .sys_reg = SYS_ID_AA64ISAR1_EL1, |
| 1804 | .sign = FTR_UNSIGNED, |
| 1805 | .field_pos = ID_AA64ISAR1_GPA_SHIFT, |
| 1806 | .min_field_value = ID_AA64ISAR1_GPA_ARCHITECTED, |
| 1807 | .matches = has_cpuid_feature, |
| 1808 | }, |
| 1809 | { |
| 1810 | .desc = "Generic authentication (IMP DEF algorithm)", |
| 1811 | .capability = ARM64_HAS_GENERIC_AUTH_IMP_DEF, |
| 1812 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1813 | .sys_reg = SYS_ID_AA64ISAR1_EL1, |
| 1814 | .sign = FTR_UNSIGNED, |
| 1815 | .field_pos = ID_AA64ISAR1_GPI_SHIFT, |
| 1816 | .min_field_value = ID_AA64ISAR1_GPI_IMP_DEF, |
| 1817 | .matches = has_cpuid_feature, |
| 1818 | }, |
Kristina Martsenko | cfef06b | 2020-03-13 14:34:49 +0530 | [diff] [blame] | 1819 | { |
| 1820 | .capability = ARM64_HAS_GENERIC_AUTH, |
| 1821 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1822 | .matches = has_generic_auth, |
| 1823 | }, |
Mark Rutland | 6984eb4 | 2018-12-07 18:39:24 +0000 | [diff] [blame] | 1824 | #endif /* CONFIG_ARM64_PTR_AUTH */ |
Julien Thierry | b90d2b2 | 2019-01-31 14:58:42 +0000 | [diff] [blame] | 1825 | #ifdef CONFIG_ARM64_PSEUDO_NMI |
| 1826 | { |
| 1827 | /* |
| 1828 | * Depends on having GICv3 |
| 1829 | */ |
| 1830 | .desc = "IRQ priority masking", |
| 1831 | .capability = ARM64_HAS_IRQ_PRIO_MASKING, |
| 1832 | .type = ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE, |
| 1833 | .matches = can_use_gic_priorities, |
| 1834 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 1835 | .field_pos = ID_AA64PFR0_GIC_SHIFT, |
| 1836 | .sign = FTR_UNSIGNED, |
| 1837 | .min_field_value = 1, |
| 1838 | }, |
| 1839 | #endif |
Mark Brown | 3e6c69a | 2019-12-09 18:12:14 +0000 | [diff] [blame] | 1840 | #ifdef CONFIG_ARM64_E0PD |
| 1841 | { |
| 1842 | .desc = "E0PD", |
| 1843 | .capability = ARM64_HAS_E0PD, |
| 1844 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1845 | .sys_reg = SYS_ID_AA64MMFR2_EL1, |
| 1846 | .sign = FTR_UNSIGNED, |
| 1847 | .field_pos = ID_AA64MMFR2_E0PD_SHIFT, |
| 1848 | .matches = has_cpuid_feature, |
| 1849 | .min_field_value = 1, |
| 1850 | .cpu_enable = cpu_enable_e0pd, |
| 1851 | }, |
| 1852 | #endif |
Richard Henderson | 1a50ec0 | 2020-01-21 12:58:52 +0000 | [diff] [blame] | 1853 | #ifdef CONFIG_ARCH_RANDOM |
| 1854 | { |
| 1855 | .desc = "Random Number Generator", |
| 1856 | .capability = ARM64_HAS_RNG, |
| 1857 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
| 1858 | .matches = has_cpuid_feature, |
| 1859 | .sys_reg = SYS_ID_AA64ISAR0_EL1, |
| 1860 | .field_pos = ID_AA64ISAR0_RNDR_SHIFT, |
| 1861 | .sign = FTR_UNSIGNED, |
| 1862 | .min_field_value = 1, |
| 1863 | }, |
| 1864 | #endif |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1865 | {}, |
| 1866 | }; |
| 1867 | |
Will Deacon | 1e013d0 | 2018-12-12 15:53:54 +0000 | [diff] [blame] | 1868 | #define HWCAP_CPUID_MATCH(reg, field, s, min_value) \ |
| 1869 | .matches = has_cpuid_feature, \ |
| 1870 | .sys_reg = reg, \ |
| 1871 | .field_pos = field, \ |
| 1872 | .sign = s, \ |
| 1873 | .min_field_value = min_value, |
| 1874 | |
| 1875 | #define __HWCAP_CAP(name, cap_type, cap) \ |
| 1876 | .desc = name, \ |
| 1877 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, \ |
| 1878 | .hwcap_type = cap_type, \ |
| 1879 | .hwcap = cap, \ |
| 1880 | |
| 1881 | #define HWCAP_CAP(reg, field, s, min_value, cap_type, cap) \ |
| 1882 | { \ |
| 1883 | __HWCAP_CAP(#cap, cap_type, cap) \ |
| 1884 | HWCAP_CPUID_MATCH(reg, field, s, min_value) \ |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1885 | } |
| 1886 | |
Will Deacon | 1e013d0 | 2018-12-12 15:53:54 +0000 | [diff] [blame] | 1887 | #define HWCAP_MULTI_CAP(list, cap_type, cap) \ |
| 1888 | { \ |
| 1889 | __HWCAP_CAP(#cap, cap_type, cap) \ |
| 1890 | .matches = cpucap_multi_entry_cap_matches, \ |
| 1891 | .match_list = list, \ |
| 1892 | } |
| 1893 | |
Suzuki K Poulose | 7559950a | 2020-01-13 23:30:20 +0000 | [diff] [blame] | 1894 | #define HWCAP_CAP_MATCH(match, cap_type, cap) \ |
| 1895 | { \ |
| 1896 | __HWCAP_CAP(#cap, cap_type, cap) \ |
| 1897 | .matches = match, \ |
| 1898 | } |
| 1899 | |
Will Deacon | 1e013d0 | 2018-12-12 15:53:54 +0000 | [diff] [blame] | 1900 | #ifdef CONFIG_ARM64_PTR_AUTH |
| 1901 | static const struct arm64_cpu_capabilities ptr_auth_hwcap_addr_matches[] = { |
| 1902 | { |
| 1903 | HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_APA_SHIFT, |
| 1904 | FTR_UNSIGNED, ID_AA64ISAR1_APA_ARCHITECTED) |
| 1905 | }, |
| 1906 | { |
| 1907 | HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_API_SHIFT, |
| 1908 | FTR_UNSIGNED, ID_AA64ISAR1_API_IMP_DEF) |
| 1909 | }, |
| 1910 | {}, |
| 1911 | }; |
| 1912 | |
| 1913 | static const struct arm64_cpu_capabilities ptr_auth_hwcap_gen_matches[] = { |
| 1914 | { |
| 1915 | HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_GPA_SHIFT, |
| 1916 | FTR_UNSIGNED, ID_AA64ISAR1_GPA_ARCHITECTED) |
| 1917 | }, |
| 1918 | { |
| 1919 | HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_GPI_SHIFT, |
| 1920 | FTR_UNSIGNED, ID_AA64ISAR1_GPI_IMP_DEF) |
| 1921 | }, |
| 1922 | {}, |
| 1923 | }; |
| 1924 | #endif |
| 1925 | |
Suzuki K Poulose | f3efb67 | 2016-04-18 10:28:32 +0100 | [diff] [blame] | 1926 | static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1927 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_PMULL), |
| 1928 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_AES), |
| 1929 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA1), |
| 1930 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA2), |
| 1931 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_SHA512), |
| 1932 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_CRC32), |
| 1933 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_ATOMICS_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_ATOMICS), |
| 1934 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_RDM_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDRDM), |
| 1935 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA3), |
| 1936 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM3), |
| 1937 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM4_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM4), |
| 1938 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_DP_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDDP), |
| 1939 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_FHM_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDFHM), |
| 1940 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_TS_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FLAGM), |
Mark Brown | 1201937 | 2019-06-18 19:10:54 +0100 | [diff] [blame] | 1941 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_TS_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_FLAGM2), |
Richard Henderson | 1a50ec0 | 2020-01-21 12:58:52 +0000 | [diff] [blame] | 1942 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_RNDR_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_RNG), |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1943 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, KERNEL_HWCAP_FP), |
| 1944 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FPHP), |
| 1945 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, KERNEL_HWCAP_ASIMD), |
| 1946 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDHP), |
| 1947 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_DIT_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_DIT), |
| 1948 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_DPB_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_DCPOP), |
Andrew Murray | 671db58 | 2019-04-09 10:52:43 +0100 | [diff] [blame] | 1949 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_DPB_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_DCPODP), |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1950 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_JSCVT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_JSCVT), |
| 1951 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_FCMA_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FCMA), |
| 1952 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_LRCPC), |
| 1953 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_ILRCPC), |
Mark Brown | ca9503f | 2019-06-18 19:10:55 +0100 | [diff] [blame] | 1954 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_FRINTTS_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FRINT), |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1955 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_SB_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SB), |
Steven Price | d4209d8 | 2019-12-16 11:33:37 +0000 | [diff] [blame] | 1956 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_BF16_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_BF16), |
| 1957 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_DGH_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_DGH), |
| 1958 | HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_I8MM_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_I8MM), |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1959 | HWCAP_CAP(SYS_ID_AA64MMFR2_EL1, ID_AA64MMFR2_AT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_USCAT), |
Dave Martin | 43994d8 | 2017-10-31 15:51:19 +0000 | [diff] [blame] | 1960 | #ifdef CONFIG_ARM64_SVE |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1961 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_SVE_SHIFT, FTR_UNSIGNED, ID_AA64PFR0_SVE, CAP_HWCAP, KERNEL_HWCAP_SVE), |
Dave Martin | 06a916f | 2019-04-18 18:41:38 +0100 | [diff] [blame] | 1962 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SVEVER_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SVEVER_SVE2, CAP_HWCAP, KERNEL_HWCAP_SVE2), |
| 1963 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES, CAP_HWCAP, KERNEL_HWCAP_SVEAES), |
| 1964 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES_PMULL, CAP_HWCAP, KERNEL_HWCAP_SVEPMULL), |
| 1965 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_BITPERM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_BITPERM, CAP_HWCAP, KERNEL_HWCAP_SVEBITPERM), |
Steven Price | d4209d8 | 2019-12-16 11:33:37 +0000 | [diff] [blame] | 1966 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_BF16_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_BF16, CAP_HWCAP, KERNEL_HWCAP_SVEBF16), |
Dave Martin | 06a916f | 2019-04-18 18:41:38 +0100 | [diff] [blame] | 1967 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SHA3_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SHA3, CAP_HWCAP, KERNEL_HWCAP_SVESHA3), |
| 1968 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SM4_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SM4, CAP_HWCAP, KERNEL_HWCAP_SVESM4), |
Steven Price | d4209d8 | 2019-12-16 11:33:37 +0000 | [diff] [blame] | 1969 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_I8MM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_I8MM, CAP_HWCAP, KERNEL_HWCAP_SVEI8MM), |
| 1970 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_F32MM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_F32MM, CAP_HWCAP, KERNEL_HWCAP_SVEF32MM), |
| 1971 | HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_F64MM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_F64MM, CAP_HWCAP, KERNEL_HWCAP_SVEF64MM), |
Dave Martin | 43994d8 | 2017-10-31 15:51:19 +0000 | [diff] [blame] | 1972 | #endif |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1973 | HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, KERNEL_HWCAP_SSBS), |
Mark Rutland | 7503197 | 2018-12-07 18:39:25 +0000 | [diff] [blame] | 1974 | #ifdef CONFIG_ARM64_PTR_AUTH |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 1975 | HWCAP_MULTI_CAP(ptr_auth_hwcap_addr_matches, CAP_HWCAP, KERNEL_HWCAP_PACA), |
| 1976 | HWCAP_MULTI_CAP(ptr_auth_hwcap_gen_matches, CAP_HWCAP, KERNEL_HWCAP_PACG), |
Mark Rutland | 7503197 | 2018-12-07 18:39:25 +0000 | [diff] [blame] | 1977 | #endif |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1978 | {}, |
| 1979 | }; |
| 1980 | |
Suzuki K Poulose | 7559950a | 2020-01-13 23:30:20 +0000 | [diff] [blame] | 1981 | #ifdef CONFIG_COMPAT |
| 1982 | static bool compat_has_neon(const struct arm64_cpu_capabilities *cap, int scope) |
| 1983 | { |
| 1984 | /* |
| 1985 | * Check that all of MVFR1_EL1.{SIMDSP, SIMDInt, SIMDLS} are available, |
| 1986 | * in line with that of arm32 as in vfp_init(). We make sure that the |
| 1987 | * check is future proof, by making sure value is non-zero. |
| 1988 | */ |
| 1989 | u32 mvfr1; |
| 1990 | |
| 1991 | WARN_ON(scope == SCOPE_LOCAL_CPU && preemptible()); |
| 1992 | if (scope == SCOPE_SYSTEM) |
| 1993 | mvfr1 = read_sanitised_ftr_reg(SYS_MVFR1_EL1); |
| 1994 | else |
| 1995 | mvfr1 = read_sysreg_s(SYS_MVFR1_EL1); |
| 1996 | |
| 1997 | return cpuid_feature_extract_unsigned_field(mvfr1, MVFR1_SIMDSP_SHIFT) && |
| 1998 | cpuid_feature_extract_unsigned_field(mvfr1, MVFR1_SIMDINT_SHIFT) && |
| 1999 | cpuid_feature_extract_unsigned_field(mvfr1, MVFR1_SIMDLS_SHIFT); |
| 2000 | } |
| 2001 | #endif |
| 2002 | |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2003 | static const struct arm64_cpu_capabilities compat_elf_hwcaps[] = { |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2004 | #ifdef CONFIG_COMPAT |
Suzuki K Poulose | 7559950a | 2020-01-13 23:30:20 +0000 | [diff] [blame] | 2005 | HWCAP_CAP_MATCH(compat_has_neon, CAP_COMPAT_HWCAP, COMPAT_HWCAP_NEON), |
| 2006 | HWCAP_CAP(SYS_MVFR1_EL1, MVFR1_SIMDFMAC_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP, COMPAT_HWCAP_VFPv4), |
| 2007 | /* Arm v8 mandates MVFR0.FPDP == {0, 2}. So, piggy back on this for the presence of VFP support */ |
| 2008 | HWCAP_CAP(SYS_MVFR0_EL1, MVFR0_FPDP_SHIFT, FTR_UNSIGNED, 2, CAP_COMPAT_HWCAP, COMPAT_HWCAP_VFP), |
| 2009 | HWCAP_CAP(SYS_MVFR0_EL1, MVFR0_FPDP_SHIFT, FTR_UNSIGNED, 2, CAP_COMPAT_HWCAP, COMPAT_HWCAP_VFPv3), |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 2010 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, FTR_UNSIGNED, 2, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_PMULL), |
| 2011 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_AES), |
| 2012 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA1), |
| 2013 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA2), |
| 2014 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_CRC32), |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2015 | #endif |
| 2016 | {}, |
| 2017 | }; |
| 2018 | |
Suzuki K Poulose | f3efb67 | 2016-04-18 10:28:32 +0100 | [diff] [blame] | 2019 | static void __init cap_set_elf_hwcap(const struct arm64_cpu_capabilities *cap) |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2020 | { |
| 2021 | switch (cap->hwcap_type) { |
| 2022 | case CAP_HWCAP: |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 2023 | cpu_set_feature(cap->hwcap); |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2024 | break; |
| 2025 | #ifdef CONFIG_COMPAT |
| 2026 | case CAP_COMPAT_HWCAP: |
| 2027 | compat_elf_hwcap |= (u32)cap->hwcap; |
| 2028 | break; |
| 2029 | case CAP_COMPAT_HWCAP2: |
| 2030 | compat_elf_hwcap2 |= (u32)cap->hwcap; |
| 2031 | break; |
| 2032 | #endif |
| 2033 | default: |
| 2034 | WARN_ON(1); |
| 2035 | break; |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | /* Check if we have a particular HWCAP enabled */ |
Suzuki K Poulose | f3efb67 | 2016-04-18 10:28:32 +0100 | [diff] [blame] | 2040 | static bool cpus_have_elf_hwcap(const struct arm64_cpu_capabilities *cap) |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2041 | { |
| 2042 | bool rc; |
| 2043 | |
| 2044 | switch (cap->hwcap_type) { |
| 2045 | case CAP_HWCAP: |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 2046 | rc = cpu_have_feature(cap->hwcap); |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2047 | break; |
| 2048 | #ifdef CONFIG_COMPAT |
| 2049 | case CAP_COMPAT_HWCAP: |
| 2050 | rc = (compat_elf_hwcap & (u32)cap->hwcap) != 0; |
| 2051 | break; |
| 2052 | case CAP_COMPAT_HWCAP2: |
| 2053 | rc = (compat_elf_hwcap2 & (u32)cap->hwcap) != 0; |
| 2054 | break; |
| 2055 | #endif |
| 2056 | default: |
| 2057 | WARN_ON(1); |
| 2058 | rc = false; |
| 2059 | } |
| 2060 | |
| 2061 | return rc; |
| 2062 | } |
| 2063 | |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2064 | static void __init setup_elf_hwcaps(const struct arm64_cpu_capabilities *hwcaps) |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2065 | { |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2066 | /* We support emulation of accesses to CPU ID feature registers */ |
Andrew Murray | aaba098 | 2019-04-09 10:52:40 +0100 | [diff] [blame] | 2067 | cpu_set_named_feature(CPUID); |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2068 | for (; hwcaps->matches; hwcaps++) |
Suzuki K Poulose | 143ba05 | 2018-03-26 15:12:31 +0100 | [diff] [blame] | 2069 | if (hwcaps->matches(hwcaps, cpucap_default_scope(hwcaps))) |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2070 | cap_set_elf_hwcap(hwcaps); |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 2071 | } |
| 2072 | |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2073 | static void update_cpu_capabilities(u16 scope_mask) |
Suzuki K Poulose | 67948af | 2018-01-09 16:12:18 +0000 | [diff] [blame] | 2074 | { |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2075 | int i; |
Suzuki K Poulose | 67948af | 2018-01-09 16:12:18 +0000 | [diff] [blame] | 2076 | const struct arm64_cpu_capabilities *caps; |
| 2077 | |
Suzuki K Poulose | cce360b | 2018-03-26 15:12:34 +0100 | [diff] [blame] | 2078 | scope_mask &= ARM64_CPUCAP_SCOPE_MASK; |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2079 | for (i = 0; i < ARM64_NCAPS; i++) { |
| 2080 | caps = cpu_hwcaps_ptrs[i]; |
| 2081 | if (!caps || !(caps->type & scope_mask) || |
| 2082 | cpus_have_cap(caps->capability) || |
Suzuki K Poulose | cce360b | 2018-03-26 15:12:34 +0100 | [diff] [blame] | 2083 | !caps->matches(caps, cpucap_default_scope(caps))) |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 2084 | continue; |
| 2085 | |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2086 | if (caps->desc) |
| 2087 | pr_info("detected: %s\n", caps->desc); |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2088 | cpus_set_cap(caps->capability); |
Daniel Thompson | 0ceb0d5 | 2019-01-31 14:58:53 +0000 | [diff] [blame] | 2089 | |
| 2090 | if ((scope_mask & SCOPE_BOOT_CPU) && (caps->type & SCOPE_BOOT_CPU)) |
| 2091 | set_bit(caps->capability, boot_capabilities); |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 2092 | } |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 2093 | } |
James Morse | 1c07630 | 2015-07-21 13:23:28 +0100 | [diff] [blame] | 2094 | |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2095 | /* |
| 2096 | * Enable all the available capabilities on this CPU. The capabilities |
| 2097 | * with BOOT_CPU scope are handled separately and hence skipped here. |
| 2098 | */ |
| 2099 | static int cpu_enable_non_boot_scope_capabilities(void *__unused) |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2100 | { |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2101 | int i; |
| 2102 | u16 non_boot_scope = SCOPE_ALL & ~SCOPE_BOOT_CPU; |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2103 | |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2104 | for_each_available_cap(i) { |
| 2105 | const struct arm64_cpu_capabilities *cap = cpu_hwcaps_ptrs[i]; |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 2106 | |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2107 | if (WARN_ON(!cap)) |
| 2108 | continue; |
| 2109 | |
| 2110 | if (!(cap->type & non_boot_scope)) |
| 2111 | continue; |
| 2112 | |
| 2113 | if (cap->cpu_enable) |
| 2114 | cap->cpu_enable(cap); |
| 2115 | } |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 2116 | return 0; |
| 2117 | } |
| 2118 | |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 2119 | /* |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2120 | * Run through the enabled capabilities and enable() it on all active |
| 2121 | * CPUs |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 2122 | */ |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2123 | static void __init enable_cpu_capabilities(u16 scope_mask) |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 2124 | { |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2125 | int i; |
| 2126 | const struct arm64_cpu_capabilities *caps; |
| 2127 | bool boot_scope; |
Mark Rutland | 63a1e1c | 2017-05-16 15:18:05 +0100 | [diff] [blame] | 2128 | |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2129 | scope_mask &= ARM64_CPUCAP_SCOPE_MASK; |
| 2130 | boot_scope = !!(scope_mask & SCOPE_BOOT_CPU); |
| 2131 | |
| 2132 | for (i = 0; i < ARM64_NCAPS; i++) { |
| 2133 | unsigned int num; |
| 2134 | |
| 2135 | caps = cpu_hwcaps_ptrs[i]; |
| 2136 | if (!caps || !(caps->type & scope_mask)) |
| 2137 | continue; |
| 2138 | num = caps->capability; |
| 2139 | if (!cpus_have_cap(num)) |
Mark Rutland | 63a1e1c | 2017-05-16 15:18:05 +0100 | [diff] [blame] | 2140 | continue; |
| 2141 | |
| 2142 | /* Ensure cpus_have_const_cap(num) works */ |
| 2143 | static_branch_enable(&cpu_hwcap_keys[num]); |
| 2144 | |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2145 | if (boot_scope && caps->cpu_enable) |
James Morse | 2a6dcb2 | 2016-10-18 11:27:46 +0100 | [diff] [blame] | 2146 | /* |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 2147 | * Capabilities with SCOPE_BOOT_CPU scope are finalised |
| 2148 | * before any secondary CPU boots. Thus, each secondary |
| 2149 | * will enable the capability as appropriate via |
| 2150 | * check_local_cpu_capabilities(). The only exception is |
| 2151 | * the boot CPU, for which the capability must be |
| 2152 | * enabled here. This approach avoids costly |
| 2153 | * stop_machine() calls for this case. |
James Morse | 2a6dcb2 | 2016-10-18 11:27:46 +0100 | [diff] [blame] | 2154 | */ |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2155 | caps->cpu_enable(caps); |
Mark Rutland | 63a1e1c | 2017-05-16 15:18:05 +0100 | [diff] [blame] | 2156 | } |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2157 | |
Suzuki K Poulose | 0b587c84 | 2018-11-30 17:18:06 +0000 | [diff] [blame] | 2158 | /* |
| 2159 | * For all non-boot scope capabilities, use stop_machine() |
| 2160 | * as it schedules the work allowing us to modify PSTATE, |
| 2161 | * instead of on_each_cpu() which uses an IPI, giving us a |
| 2162 | * PSTATE that disappears when we return. |
| 2163 | */ |
| 2164 | if (!boot_scope) |
| 2165 | stop_machine(cpu_enable_non_boot_scope_capabilities, |
| 2166 | NULL, cpu_online_mask); |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2167 | } |
| 2168 | |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2169 | /* |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2170 | * Run through the list of capabilities to check for conflicts. |
| 2171 | * If the system has already detected a capability, take necessary |
| 2172 | * action on this CPU. |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2173 | */ |
Kristina Martsenko | deeaac5 | 2020-03-13 14:34:54 +0530 | [diff] [blame] | 2174 | static void verify_local_cpu_caps(u16 scope_mask) |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2175 | { |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2176 | int i; |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2177 | bool cpu_has_cap, system_has_cap; |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2178 | const struct arm64_cpu_capabilities *caps; |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2179 | |
Suzuki K Poulose | cce360b | 2018-03-26 15:12:34 +0100 | [diff] [blame] | 2180 | scope_mask &= ARM64_CPUCAP_SCOPE_MASK; |
| 2181 | |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2182 | for (i = 0; i < ARM64_NCAPS; i++) { |
| 2183 | caps = cpu_hwcaps_ptrs[i]; |
| 2184 | if (!caps || !(caps->type & scope_mask)) |
Suzuki K Poulose | cce360b | 2018-03-26 15:12:34 +0100 | [diff] [blame] | 2185 | continue; |
| 2186 | |
Suzuki K Poulose | ba7d923 | 2018-03-26 15:12:46 +0100 | [diff] [blame] | 2187 | cpu_has_cap = caps->matches(caps, SCOPE_LOCAL_CPU); |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2188 | system_has_cap = cpus_have_cap(caps->capability); |
| 2189 | |
| 2190 | if (system_has_cap) { |
| 2191 | /* |
| 2192 | * Check if the new CPU misses an advertised feature, |
| 2193 | * which is not safe to miss. |
| 2194 | */ |
| 2195 | if (!cpu_has_cap && !cpucap_late_cpu_optional(caps)) |
| 2196 | break; |
| 2197 | /* |
| 2198 | * We have to issue cpu_enable() irrespective of |
| 2199 | * whether the CPU has it or not, as it is enabeld |
| 2200 | * system wide. It is upto the call back to take |
| 2201 | * appropriate action on this CPU. |
| 2202 | */ |
| 2203 | if (caps->cpu_enable) |
| 2204 | caps->cpu_enable(caps); |
| 2205 | } else { |
| 2206 | /* |
| 2207 | * Check if the CPU has this capability if it isn't |
| 2208 | * safe to have when the system doesn't. |
| 2209 | */ |
| 2210 | if (cpu_has_cap && !cpucap_late_cpu_permitted(caps)) |
| 2211 | break; |
| 2212 | } |
| 2213 | } |
| 2214 | |
Suzuki K Poulose | 606f8e7 | 2018-11-30 17:18:05 +0000 | [diff] [blame] | 2215 | if (i < ARM64_NCAPS) { |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2216 | pr_crit("CPU%d: Detected conflict for capability %d (%s), System: %d, CPU: %d\n", |
| 2217 | smp_processor_id(), caps->capability, |
| 2218 | caps->desc, system_has_cap, cpu_has_cap); |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2219 | |
Kristina Martsenko | deeaac5 | 2020-03-13 14:34:54 +0530 | [diff] [blame] | 2220 | if (cpucap_panic_on_conflict(caps)) |
| 2221 | cpu_panic_kernel(); |
| 2222 | else |
| 2223 | cpu_die_early(); |
| 2224 | } |
Suzuki K Poulose | eaac4d8 | 2018-03-26 15:12:33 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | /* |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 2228 | * Check for CPU features that are used in early boot |
| 2229 | * based on the Boot CPU value. |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2230 | */ |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 2231 | static void check_early_cpu_features(void) |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 2232 | { |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 2233 | verify_cpu_asid_bits(); |
Kristina Martsenko | deeaac5 | 2020-03-13 14:34:54 +0530 | [diff] [blame] | 2234 | |
| 2235 | verify_local_cpu_caps(SCOPE_BOOT_CPU); |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2236 | } |
| 2237 | |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2238 | static void |
| 2239 | verify_local_elf_hwcaps(const struct arm64_cpu_capabilities *caps) |
| 2240 | { |
| 2241 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 2242 | for (; caps->matches; caps++) |
| 2243 | if (cpus_have_elf_hwcap(caps) && !caps->matches(caps, SCOPE_LOCAL_CPU)) { |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2244 | pr_crit("CPU%d: missing HWCAP: %s\n", |
| 2245 | smp_processor_id(), caps->desc); |
| 2246 | cpu_die_early(); |
| 2247 | } |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2248 | } |
| 2249 | |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 2250 | static void verify_sve_features(void) |
| 2251 | { |
| 2252 | u64 safe_zcr = read_sanitised_ftr_reg(SYS_ZCR_EL1); |
| 2253 | u64 zcr = read_zcr_features(); |
| 2254 | |
| 2255 | unsigned int safe_len = safe_zcr & ZCR_ELx_LEN_MASK; |
| 2256 | unsigned int len = zcr & ZCR_ELx_LEN_MASK; |
| 2257 | |
| 2258 | if (len < safe_len || sve_verify_vq_map()) { |
Dave Martin | d06b76b | 2018-09-28 14:39:10 +0100 | [diff] [blame] | 2259 | pr_crit("CPU%d: SVE: vector length support mismatch\n", |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 2260 | smp_processor_id()); |
| 2261 | cpu_die_early(); |
| 2262 | } |
| 2263 | |
| 2264 | /* Add checks on other ZCR bits here if necessary */ |
| 2265 | } |
| 2266 | |
Suzuki K Poulose | 1e89bae | 2018-03-26 15:12:30 +0100 | [diff] [blame] | 2267 | |
| 2268 | /* |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2269 | * Run through the enabled system capabilities and enable() it on this CPU. |
| 2270 | * The capabilities were decided based on the available CPUs at the boot time. |
| 2271 | * Any new CPU should match the system wide status of the capability. If the |
| 2272 | * new CPU doesn't have a capability which the system now has enabled, we |
| 2273 | * cannot do anything to fix it up and could cause unexpected failures. So |
| 2274 | * we park the CPU. |
| 2275 | */ |
Suzuki K Poulose | c47a190 | 2016-09-09 14:07:10 +0100 | [diff] [blame] | 2276 | static void verify_local_cpu_capabilities(void) |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2277 | { |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 2278 | /* |
| 2279 | * The capabilities with SCOPE_BOOT_CPU are checked from |
| 2280 | * check_early_cpu_features(), as they need to be verified |
| 2281 | * on all secondary CPUs. |
| 2282 | */ |
Kristina Martsenko | deeaac5 | 2020-03-13 14:34:54 +0530 | [diff] [blame] | 2283 | verify_local_cpu_caps(SCOPE_ALL & ~SCOPE_BOOT_CPU); |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2284 | |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2285 | verify_local_elf_hwcaps(arm64_elf_hwcaps); |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 2286 | |
Suzuki K Poulose | 643d703 | 2016-04-18 10:28:37 +0100 | [diff] [blame] | 2287 | if (system_supports_32bit_el0()) |
| 2288 | verify_local_elf_hwcaps(compat_elf_hwcaps); |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 2289 | |
| 2290 | if (system_supports_sve()) |
| 2291 | verify_sve_features(); |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
Suzuki K Poulose | c47a190 | 2016-09-09 14:07:10 +0100 | [diff] [blame] | 2294 | void check_local_cpu_capabilities(void) |
| 2295 | { |
| 2296 | /* |
| 2297 | * All secondary CPUs should conform to the early CPU features |
| 2298 | * in use by the kernel based on boot CPU. |
| 2299 | */ |
| 2300 | check_early_cpu_features(); |
| 2301 | |
| 2302 | /* |
| 2303 | * If we haven't finalised the system capabilities, this CPU gets |
Suzuki K Poulose | fbd890b | 2018-03-26 15:12:37 +0100 | [diff] [blame] | 2304 | * a chance to update the errata work arounds and local features. |
Suzuki K Poulose | c47a190 | 2016-09-09 14:07:10 +0100 | [diff] [blame] | 2305 | * Otherwise, this CPU should verify that it has all the system |
| 2306 | * advertised capabilities. |
| 2307 | */ |
Suzuki K Poulose | b51c6ac | 2020-01-13 23:30:17 +0000 | [diff] [blame] | 2308 | if (!system_capabilities_finalized()) |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2309 | update_cpu_capabilities(SCOPE_LOCAL_CPU); |
| 2310 | else |
Suzuki K Poulose | c47a190 | 2016-09-09 14:07:10 +0100 | [diff] [blame] | 2311 | verify_local_cpu_capabilities(); |
| 2312 | } |
| 2313 | |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 2314 | static void __init setup_boot_cpu_capabilities(void) |
| 2315 | { |
| 2316 | /* Detect capabilities with either SCOPE_BOOT_CPU or SCOPE_LOCAL_CPU */ |
| 2317 | update_cpu_capabilities(SCOPE_BOOT_CPU | SCOPE_LOCAL_CPU); |
| 2318 | /* Enable the SCOPE_BOOT_CPU capabilities alone right away */ |
| 2319 | enable_cpu_capabilities(SCOPE_BOOT_CPU); |
| 2320 | } |
| 2321 | |
Suzuki K Poulose | f7bfc14 | 2018-11-30 17:18:04 +0000 | [diff] [blame] | 2322 | bool this_cpu_has_cap(unsigned int n) |
Marc Zyngier | 8f413758 | 2017-01-30 15:39:52 +0000 | [diff] [blame] | 2323 | { |
Suzuki K Poulose | f7bfc14 | 2018-11-30 17:18:04 +0000 | [diff] [blame] | 2324 | if (!WARN_ON(preemptible()) && n < ARM64_NCAPS) { |
| 2325 | const struct arm64_cpu_capabilities *cap = cpu_hwcaps_ptrs[n]; |
| 2326 | |
| 2327 | if (cap) |
| 2328 | return cap->matches(cap, SCOPE_LOCAL_CPU); |
| 2329 | } |
| 2330 | |
| 2331 | return false; |
Marc Zyngier | 8f413758 | 2017-01-30 15:39:52 +0000 | [diff] [blame] | 2332 | } |
| 2333 | |
Amit Daniel Kachhap | 3ff047f | 2020-03-13 14:34:48 +0530 | [diff] [blame] | 2334 | /* |
| 2335 | * This helper function is used in a narrow window when, |
| 2336 | * - The system wide safe registers are set with all the SMP CPUs and, |
| 2337 | * - The SYSTEM_FEATURE cpu_hwcaps may not have been set. |
| 2338 | * In all other cases cpus_have_{const_}cap() should be used. |
| 2339 | */ |
| 2340 | static bool __system_matches_cap(unsigned int n) |
| 2341 | { |
| 2342 | if (n < ARM64_NCAPS) { |
| 2343 | const struct arm64_cpu_capabilities *cap = cpu_hwcaps_ptrs[n]; |
| 2344 | |
| 2345 | if (cap) |
| 2346 | return cap->matches(cap, SCOPE_SYSTEM); |
| 2347 | } |
| 2348 | return false; |
| 2349 | } |
| 2350 | |
Andrew Murray | aec0bff | 2019-04-09 10:52:41 +0100 | [diff] [blame] | 2351 | void cpu_set_feature(unsigned int num) |
| 2352 | { |
| 2353 | WARN_ON(num >= MAX_CPU_FEATURES); |
| 2354 | elf_hwcap |= BIT(num); |
| 2355 | } |
| 2356 | EXPORT_SYMBOL_GPL(cpu_set_feature); |
| 2357 | |
| 2358 | bool cpu_have_feature(unsigned int num) |
| 2359 | { |
| 2360 | WARN_ON(num >= MAX_CPU_FEATURES); |
| 2361 | return elf_hwcap & BIT(num); |
| 2362 | } |
| 2363 | EXPORT_SYMBOL_GPL(cpu_have_feature); |
| 2364 | |
| 2365 | unsigned long cpu_get_elf_hwcap(void) |
| 2366 | { |
| 2367 | /* |
| 2368 | * We currently only populate the first 32 bits of AT_HWCAP. Please |
| 2369 | * note that for userspace compatibility we guarantee that bits 62 |
| 2370 | * and 63 will always be returned as 0. |
| 2371 | */ |
| 2372 | return lower_32_bits(elf_hwcap); |
| 2373 | } |
| 2374 | |
| 2375 | unsigned long cpu_get_elf_hwcap2(void) |
| 2376 | { |
| 2377 | return upper_32_bits(elf_hwcap); |
| 2378 | } |
| 2379 | |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2380 | static void __init setup_system_capabilities(void) |
| 2381 | { |
| 2382 | /* |
| 2383 | * We have finalised the system-wide safe feature |
| 2384 | * registers, finalise the capabilities that depend |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 2385 | * on it. Also enable all the available capabilities, |
| 2386 | * that are not enabled already. |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2387 | */ |
| 2388 | update_cpu_capabilities(SCOPE_SYSTEM); |
Suzuki K Poulose | fd9d63d | 2018-03-26 15:12:41 +0100 | [diff] [blame] | 2389 | enable_cpu_capabilities(SCOPE_ALL & ~SCOPE_BOOT_CPU); |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2390 | } |
| 2391 | |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 2392 | void __init setup_cpu_features(void) |
| 2393 | { |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 2394 | u32 cwg; |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 2395 | |
Suzuki K Poulose | ed478b3 | 2018-03-26 15:12:38 +0100 | [diff] [blame] | 2396 | setup_system_capabilities(); |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 2397 | setup_elf_hwcaps(arm64_elf_hwcaps); |
Suzuki K Poulose | 643d703 | 2016-04-18 10:28:37 +0100 | [diff] [blame] | 2398 | |
| 2399 | if (system_supports_32bit_el0()) |
| 2400 | setup_elf_hwcaps(compat_elf_hwcaps); |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2401 | |
Kees Cook | 2e6f549 | 2018-02-21 10:18:21 -0800 | [diff] [blame] | 2402 | if (system_uses_ttbr0_pan()) |
| 2403 | pr_info("emulated: Privileged Access Never (PAN) using TTBR0_EL1 switching\n"); |
| 2404 | |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 2405 | sve_setup(); |
Dave Martin | 94b07c1 | 2018-06-01 11:10:14 +0100 | [diff] [blame] | 2406 | minsigstksz_setup(); |
Dave Martin | 2e0f247 | 2017-10-31 15:51:10 +0000 | [diff] [blame] | 2407 | |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2408 | /* Advertise that we have computed the system capabilities */ |
Suzuki K Poulose | b51c6ac | 2020-01-13 23:30:17 +0000 | [diff] [blame] | 2409 | finalize_system_capabilities(); |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 2410 | |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 2411 | /* |
| 2412 | * Check for sane CTR_EL0.CWG value. |
| 2413 | */ |
| 2414 | cwg = cache_type_cwg(); |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 2415 | if (!cwg) |
Catalin Marinas | ebc7e21 | 2018-05-11 13:33:12 +0100 | [diff] [blame] | 2416 | pr_warn("No Cache Writeback Granule information, assuming %d\n", |
| 2417 | ARCH_DMA_MINALIGN); |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 2418 | } |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 2419 | |
| 2420 | static bool __maybe_unused |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 2421 | cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused) |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 2422 | { |
Amit Daniel Kachhap | 3ff047f | 2020-03-13 14:34:48 +0530 | [diff] [blame] | 2423 | return (__system_matches_cap(ARM64_HAS_PAN) && !__system_matches_cap(ARM64_HAS_UAO)); |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 2424 | } |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2425 | |
Vladimir Murzin | 5ffdfae | 2018-07-31 14:08:56 +0100 | [diff] [blame] | 2426 | static void __maybe_unused cpu_enable_cnp(struct arm64_cpu_capabilities const *cap) |
| 2427 | { |
| 2428 | cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); |
| 2429 | } |
| 2430 | |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2431 | /* |
| 2432 | * We emulate only the following system register space. |
| 2433 | * Op0 = 0x3, CRn = 0x0, Op1 = 0x0, CRm = [0, 4 - 7] |
| 2434 | * See Table C5-6 System instruction encodings for System register accesses, |
| 2435 | * ARMv8 ARM(ARM DDI 0487A.f) for more details. |
| 2436 | */ |
| 2437 | static inline bool __attribute_const__ is_emulated(u32 id) |
| 2438 | { |
| 2439 | return (sys_reg_Op0(id) == 0x3 && |
| 2440 | sys_reg_CRn(id) == 0x0 && |
| 2441 | sys_reg_Op1(id) == 0x0 && |
| 2442 | (sys_reg_CRm(id) == 0 || |
| 2443 | ((sys_reg_CRm(id) >= 4) && (sys_reg_CRm(id) <= 7)))); |
| 2444 | } |
| 2445 | |
| 2446 | /* |
| 2447 | * With CRm == 0, reg should be one of : |
| 2448 | * MIDR_EL1, MPIDR_EL1 or REVIDR_EL1. |
| 2449 | */ |
| 2450 | static inline int emulate_id_reg(u32 id, u64 *valp) |
| 2451 | { |
| 2452 | switch (id) { |
| 2453 | case SYS_MIDR_EL1: |
| 2454 | *valp = read_cpuid_id(); |
| 2455 | break; |
| 2456 | case SYS_MPIDR_EL1: |
| 2457 | *valp = SYS_MPIDR_SAFE_VAL; |
| 2458 | break; |
| 2459 | case SYS_REVIDR_EL1: |
| 2460 | /* IMPLEMENTATION DEFINED values are emulated with 0 */ |
| 2461 | *valp = 0; |
| 2462 | break; |
| 2463 | default: |
| 2464 | return -EINVAL; |
| 2465 | } |
| 2466 | |
| 2467 | return 0; |
| 2468 | } |
| 2469 | |
| 2470 | static int emulate_sys_reg(u32 id, u64 *valp) |
| 2471 | { |
| 2472 | struct arm64_ftr_reg *regp; |
| 2473 | |
| 2474 | if (!is_emulated(id)) |
| 2475 | return -EINVAL; |
| 2476 | |
| 2477 | if (sys_reg_CRm(id) == 0) |
| 2478 | return emulate_id_reg(id, valp); |
| 2479 | |
| 2480 | regp = get_arm64_ftr_reg(id); |
| 2481 | if (regp) |
| 2482 | *valp = arm64_ftr_reg_user_value(regp); |
| 2483 | else |
| 2484 | /* |
| 2485 | * The untracked registers are either IMPLEMENTATION DEFINED |
| 2486 | * (e.g, ID_AFR0_EL1) or reserved RAZ. |
| 2487 | */ |
| 2488 | *valp = 0; |
| 2489 | return 0; |
| 2490 | } |
| 2491 | |
Anshuman Khandual | 520ad98 | 2018-09-20 09:36:20 +0530 | [diff] [blame] | 2492 | int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt) |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2493 | { |
| 2494 | int rc; |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2495 | u64 val; |
| 2496 | |
Anshuman Khandual | 520ad98 | 2018-09-20 09:36:20 +0530 | [diff] [blame] | 2497 | rc = emulate_sys_reg(sys_reg, &val); |
| 2498 | if (!rc) { |
| 2499 | pt_regs_write_reg(regs, rt, val); |
| 2500 | arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE); |
| 2501 | } |
| 2502 | return rc; |
| 2503 | } |
| 2504 | |
| 2505 | static int emulate_mrs(struct pt_regs *regs, u32 insn) |
| 2506 | { |
| 2507 | u32 sys_reg, rt; |
| 2508 | |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2509 | /* |
| 2510 | * sys_reg values are defined as used in mrs/msr instruction. |
| 2511 | * shift the imm value to get the encoding. |
| 2512 | */ |
| 2513 | sys_reg = (u32)aarch64_insn_decode_immediate(AARCH64_INSN_IMM_16, insn) << 5; |
Anshuman Khandual | 520ad98 | 2018-09-20 09:36:20 +0530 | [diff] [blame] | 2514 | rt = aarch64_insn_decode_register(AARCH64_INSN_REGTYPE_RT, insn); |
| 2515 | return do_emulate_mrs(regs, sys_reg, rt); |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | static struct undef_hook mrs_hook = { |
| 2519 | .instr_mask = 0xfff00000, |
| 2520 | .instr_val = 0xd5300000, |
Mark Rutland | d64567f | 2018-07-05 15:16:52 +0100 | [diff] [blame] | 2521 | .pstate_mask = PSR_AA32_MODE_MASK, |
Suzuki K Poulose | 77c97b4 | 2017-01-09 17:28:31 +0000 | [diff] [blame] | 2522 | .pstate_val = PSR_MODE_EL0t, |
| 2523 | .fn = emulate_mrs, |
| 2524 | }; |
| 2525 | |
| 2526 | static int __init enable_mrs_emulation(void) |
| 2527 | { |
| 2528 | register_undef_hook(&mrs_hook); |
| 2529 | return 0; |
| 2530 | } |
| 2531 | |
Suzuki K Poulose | c0d8832 | 2017-10-06 14:16:52 +0100 | [diff] [blame] | 2532 | core_initcall(enable_mrs_emulation); |
Jeremy Linton | 1b3ccf4 | 2019-04-15 16:21:22 -0500 | [diff] [blame] | 2533 | |
| 2534 | ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, |
| 2535 | char *buf) |
| 2536 | { |
| 2537 | if (__meltdown_safe) |
| 2538 | return sprintf(buf, "Not affected\n"); |
| 2539 | |
| 2540 | if (arm64_kernel_unmapped_at_el0()) |
| 2541 | return sprintf(buf, "Mitigation: PTI\n"); |
| 2542 | |
| 2543 | return sprintf(buf, "Vulnerable\n"); |
| 2544 | } |