Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Contains CPU specific errata definitions |
| 4 | * |
| 5 | * Copyright (C) 2014 ARM Ltd. |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Arnd Bergmann | 94a5d87 | 2018-06-05 13:50:07 +0200 | [diff] [blame] | 8 | #include <linux/arm-smccc.h> |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 9 | #include <linux/types.h> |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 10 | #include <linux/cpu.h> |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 11 | #include <asm/cpu.h> |
| 12 | #include <asm/cputype.h> |
| 13 | #include <asm/cpufeature.h> |
Mark Brown | 4db61fe | 2020-02-18 19:58:39 +0000 | [diff] [blame] | 14 | #include <asm/kvm_asm.h> |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 15 | #include <asm/smp_plat.h> |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 16 | |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 17 | static bool __maybe_unused |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 18 | is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 19 | { |
Ard Biesheuvel | e8002e0 | 2018-03-06 17:15:34 +0000 | [diff] [blame] | 20 | const struct arm64_midr_revidr *fix; |
| 21 | u32 midr = read_cpuid_id(), revidr; |
| 22 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 23 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 24 | if (!is_midr_in_range(midr, &entry->midr_range)) |
Ard Biesheuvel | e8002e0 | 2018-03-06 17:15:34 +0000 | [diff] [blame] | 25 | return false; |
| 26 | |
| 27 | midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK; |
| 28 | revidr = read_cpuid(REVIDR_EL1); |
| 29 | for (fix = entry->fixed_revs; fix && fix->revidr_mask; fix++) |
| 30 | if (midr == fix->midr_rv && (revidr & fix->revidr_mask)) |
| 31 | return false; |
| 32 | |
| 33 | return true; |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 36 | static bool __maybe_unused |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 37 | is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry, |
| 38 | int scope) |
| 39 | { |
| 40 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 41 | return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list); |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 44 | static bool __maybe_unused |
| 45 | is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope) |
| 46 | { |
| 47 | u32 model; |
| 48 | |
| 49 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 50 | |
| 51 | model = read_cpuid_id(); |
| 52 | model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) | |
| 53 | MIDR_ARCHITECTURE_MASK; |
| 54 | |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 55 | return model == entry->midr_range.model; |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 58 | static bool |
Suzuki K Poulose | 314d53d | 2018-07-04 23:07:46 +0100 | [diff] [blame] | 59 | has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry, |
| 60 | int scope) |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 61 | { |
Suzuki K Poulose | 1602df0 | 2018-10-09 14:47:06 +0100 | [diff] [blame] | 62 | u64 mask = arm64_ftr_reg_ctrel0.strict_mask; |
| 63 | u64 sys = arm64_ftr_reg_ctrel0.sys_val & mask; |
| 64 | u64 ctr_raw, ctr_real; |
Suzuki K Poulose | 314d53d | 2018-07-04 23:07:46 +0100 | [diff] [blame] | 65 | |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 66 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
Suzuki K Poulose | 1602df0 | 2018-10-09 14:47:06 +0100 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * We want to make sure that all the CPUs in the system expose |
| 70 | * a consistent CTR_EL0 to make sure that applications behaves |
| 71 | * correctly with migration. |
| 72 | * |
| 73 | * If a CPU has CTR_EL0.IDC but does not advertise it via CTR_EL0 : |
| 74 | * |
| 75 | * 1) It is safe if the system doesn't support IDC, as CPU anyway |
| 76 | * reports IDC = 0, consistent with the rest. |
| 77 | * |
| 78 | * 2) If the system has IDC, it is still safe as we trap CTR_EL0 |
| 79 | * access on this CPU via the ARM64_HAS_CACHE_IDC capability. |
| 80 | * |
| 81 | * So, we need to make sure either the raw CTR_EL0 or the effective |
| 82 | * CTR_EL0 matches the system's copy to allow a secondary CPU to boot. |
| 83 | */ |
| 84 | ctr_raw = read_cpuid_cachetype() & mask; |
| 85 | ctr_real = read_cpuid_effective_cachetype() & mask; |
| 86 | |
| 87 | return (ctr_real != sys) && (ctr_raw != sys); |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 90 | static void |
James Morse | 0546084 | 2019-10-17 18:42:58 +0100 | [diff] [blame] | 91 | cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *cap) |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 92 | { |
Suzuki K Poulose | 4afe8e7 | 2018-10-09 14:47:07 +0100 | [diff] [blame] | 93 | u64 mask = arm64_ftr_reg_ctrel0.strict_mask; |
James Morse | 0546084 | 2019-10-17 18:42:58 +0100 | [diff] [blame] | 94 | bool enable_uct_trap = false; |
Suzuki K Poulose | 4afe8e7 | 2018-10-09 14:47:07 +0100 | [diff] [blame] | 95 | |
| 96 | /* Trap CTR_EL0 access on this CPU, only if it has a mismatch */ |
| 97 | if ((read_cpuid_cachetype() & mask) != |
| 98 | (arm64_ftr_reg_ctrel0.sys_val & mask)) |
James Morse | 0546084 | 2019-10-17 18:42:58 +0100 | [diff] [blame] | 99 | enable_uct_trap = true; |
| 100 | |
| 101 | /* ... or if the system is affected by an erratum */ |
| 102 | if (cap->capability == ARM64_WORKAROUND_1542419) |
| 103 | enable_uct_trap = true; |
| 104 | |
| 105 | if (enable_uct_trap) |
Suzuki K Poulose | 4afe8e7 | 2018-10-09 14:47:07 +0100 | [diff] [blame] | 106 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0); |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Marc Zyngier | 4205a89 | 2018-03-13 12:40:39 +0000 | [diff] [blame] | 109 | atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1); |
| 110 | |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 111 | #include <asm/mmu_context.h> |
| 112 | #include <asm/cacheflush.h> |
| 113 | |
| 114 | DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); |
| 115 | |
Marc Zyngier | e8b22d0f | 2018-04-10 11:36:45 +0100 | [diff] [blame] | 116 | #ifdef CONFIG_KVM_INDIRECT_VECTORS |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 117 | static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, |
| 118 | const char *hyp_vecs_end) |
| 119 | { |
Mark Brown | 6e52aab | 2020-02-18 19:58:38 +0000 | [diff] [blame] | 120 | void *dst = lm_alias(__bp_harden_hyp_vecs + slot * SZ_2K); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 121 | int i; |
| 122 | |
| 123 | for (i = 0; i < SZ_2K; i += 0x80) |
| 124 | memcpy(dst + i, hyp_vecs_start, hyp_vecs_end - hyp_vecs_start); |
| 125 | |
Will Deacon | 3b8c9f1 | 2018-06-11 14:22:09 +0100 | [diff] [blame] | 126 | __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 129 | static void install_bp_hardening_cb(bp_hardening_cb_t fn, |
| 130 | const char *hyp_vecs_start, |
| 131 | const char *hyp_vecs_end) |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 132 | { |
James Morse | d8797b1 | 2018-11-27 15:35:21 +0000 | [diff] [blame] | 133 | static DEFINE_RAW_SPINLOCK(bp_lock); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 134 | int cpu, slot = -1; |
| 135 | |
James Morse | 4debef5 | 2018-09-21 21:49:19 +0100 | [diff] [blame] | 136 | /* |
Thierry Reding | 7a292b6 | 2019-09-23 11:12:29 +0200 | [diff] [blame] | 137 | * detect_harden_bp_fw() passes NULL for the hyp_vecs start/end if |
| 138 | * we're a guest. Skip the hyp-vectors work. |
James Morse | 4debef5 | 2018-09-21 21:49:19 +0100 | [diff] [blame] | 139 | */ |
| 140 | if (!hyp_vecs_start) { |
| 141 | __this_cpu_write(bp_hardening_data.fn, fn); |
| 142 | return; |
| 143 | } |
| 144 | |
James Morse | d8797b1 | 2018-11-27 15:35:21 +0000 | [diff] [blame] | 145 | raw_spin_lock(&bp_lock); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 146 | for_each_possible_cpu(cpu) { |
| 147 | if (per_cpu(bp_hardening_data.fn, cpu) == fn) { |
| 148 | slot = per_cpu(bp_hardening_data.hyp_vectors_slot, cpu); |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | if (slot == -1) { |
Marc Zyngier | 4205a89 | 2018-03-13 12:40:39 +0000 | [diff] [blame] | 154 | slot = atomic_inc_return(&arm64_el2_vector_last_slot); |
| 155 | BUG_ON(slot >= BP_HARDEN_EL2_SLOTS); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 156 | __copy_hyp_vect_bpi(slot, hyp_vecs_start, hyp_vecs_end); |
| 157 | } |
| 158 | |
| 159 | __this_cpu_write(bp_hardening_data.hyp_vectors_slot, slot); |
| 160 | __this_cpu_write(bp_hardening_data.fn, fn); |
James Morse | d8797b1 | 2018-11-27 15:35:21 +0000 | [diff] [blame] | 161 | raw_spin_unlock(&bp_lock); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 162 | } |
| 163 | #else |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 164 | static void install_bp_hardening_cb(bp_hardening_cb_t fn, |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 165 | const char *hyp_vecs_start, |
| 166 | const char *hyp_vecs_end) |
| 167 | { |
| 168 | __this_cpu_write(bp_hardening_data.fn, fn); |
| 169 | } |
Marc Zyngier | e8b22d0f | 2018-04-10 11:36:45 +0100 | [diff] [blame] | 170 | #endif /* CONFIG_KVM_INDIRECT_VECTORS */ |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 171 | |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 172 | #include <linux/arm-smccc.h> |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 173 | |
Nathan Chancellor | 9a25136 | 2020-03-10 16:25:44 -0700 | [diff] [blame] | 174 | static void __maybe_unused call_smc_arch_workaround_1(void) |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 175 | { |
| 176 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); |
| 177 | } |
| 178 | |
| 179 | static void call_hvc_arch_workaround_1(void) |
| 180 | { |
| 181 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); |
| 182 | } |
| 183 | |
Shanker Donthineni | 4bc352f | 2018-04-10 11:36:42 +0100 | [diff] [blame] | 184 | static void qcom_link_stack_sanitization(void) |
| 185 | { |
| 186 | u64 tmp; |
| 187 | |
| 188 | asm volatile("mov %0, x30 \n" |
| 189 | ".rept 16 \n" |
| 190 | "bl . + 4 \n" |
| 191 | ".endr \n" |
| 192 | "mov x30, %0 \n" |
| 193 | : "=&r" (tmp)); |
| 194 | } |
| 195 | |
Jeremy Linton | e5ce5e7 | 2019-04-15 16:21:20 -0500 | [diff] [blame] | 196 | static bool __nospectre_v2; |
| 197 | static int __init parse_nospectre_v2(char *str) |
| 198 | { |
| 199 | __nospectre_v2 = true; |
| 200 | return 0; |
| 201 | } |
| 202 | early_param("nospectre_v2", parse_nospectre_v2); |
| 203 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 204 | /* |
| 205 | * -1: No workaround |
| 206 | * 0: No workaround required |
| 207 | * 1: Workaround installed |
| 208 | */ |
| 209 | static int detect_harden_bp_fw(void) |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 210 | { |
| 211 | bp_hardening_cb_t cb; |
| 212 | void *smccc_start, *smccc_end; |
| 213 | struct arm_smccc_res res; |
Shanker Donthineni | 4bc352f | 2018-04-10 11:36:42 +0100 | [diff] [blame] | 214 | u32 midr = read_cpuid_id(); |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 215 | |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 216 | arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 217 | ARM_SMCCC_ARCH_WORKAROUND_1, &res); |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 218 | |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 219 | switch ((int)res.a0) { |
| 220 | case 1: |
| 221 | /* Firmware says we're just fine */ |
| 222 | return 0; |
| 223 | case 0: |
| 224 | break; |
| 225 | default: |
| 226 | return -1; |
| 227 | } |
| 228 | |
Mark Rutland | c98bd29 | 2019-08-09 14:22:41 +0100 | [diff] [blame] | 229 | switch (arm_smccc_1_1_get_conduit()) { |
| 230 | case SMCCC_CONDUIT_HVC: |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 231 | cb = call_hvc_arch_workaround_1; |
| 232 | /* This is a guest, no need to patch KVM vectors */ |
| 233 | smccc_start = NULL; |
| 234 | smccc_end = NULL; |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 235 | break; |
| 236 | |
Will Deacon | d82755b | 2020-05-05 16:45:17 +0100 | [diff] [blame] | 237 | #if IS_ENABLED(CONFIG_KVM) |
Mark Rutland | c98bd29 | 2019-08-09 14:22:41 +0100 | [diff] [blame] | 238 | case SMCCC_CONDUIT_SMC: |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 239 | cb = call_smc_arch_workaround_1; |
Mark Brown | 4db61fe | 2020-02-18 19:58:39 +0000 | [diff] [blame] | 240 | smccc_start = __smccc_workaround_1_smc; |
| 241 | smccc_end = __smccc_workaround_1_smc + |
| 242 | __SMCCC_WORKAROUND_1_SMC_SZ; |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 243 | break; |
Mark Brown | 4db61fe | 2020-02-18 19:58:39 +0000 | [diff] [blame] | 244 | #endif |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 245 | |
| 246 | default: |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 247 | return -1; |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Shanker Donthineni | 4bc352f | 2018-04-10 11:36:42 +0100 | [diff] [blame] | 250 | if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) || |
| 251 | ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) |
| 252 | cb = qcom_link_stack_sanitization; |
| 253 | |
Jeremy Linton | 8c1e3d2 | 2019-04-15 16:21:25 -0500 | [diff] [blame] | 254 | if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) |
| 255 | install_bp_hardening_cb(cb, smccc_start, smccc_end); |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 256 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 257 | return 1; |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 258 | } |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 259 | |
Marc Zyngier | 5cf9ce6 | 2018-05-29 13:11:07 +0100 | [diff] [blame] | 260 | DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required); |
| 261 | |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 262 | int ssbd_state __read_mostly = ARM64_SSBD_KERNEL; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 263 | static bool __ssb_safe = true; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 264 | |
| 265 | static const struct ssbd_options { |
| 266 | const char *str; |
| 267 | int state; |
| 268 | } ssbd_options[] = { |
| 269 | { "force-on", ARM64_SSBD_FORCE_ENABLE, }, |
| 270 | { "force-off", ARM64_SSBD_FORCE_DISABLE, }, |
| 271 | { "kernel", ARM64_SSBD_KERNEL, }, |
| 272 | }; |
| 273 | |
| 274 | static int __init ssbd_cfg(char *buf) |
| 275 | { |
| 276 | int i; |
| 277 | |
| 278 | if (!buf || !buf[0]) |
| 279 | return -EINVAL; |
| 280 | |
| 281 | for (i = 0; i < ARRAY_SIZE(ssbd_options); i++) { |
| 282 | int len = strlen(ssbd_options[i].str); |
| 283 | |
| 284 | if (strncmp(buf, ssbd_options[i].str, len)) |
| 285 | continue; |
| 286 | |
| 287 | ssbd_state = ssbd_options[i].state; |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | return -EINVAL; |
| 292 | } |
| 293 | early_param("ssbd", ssbd_cfg); |
| 294 | |
Marc Zyngier | 8e29062 | 2018-05-29 13:11:06 +0100 | [diff] [blame] | 295 | void __init arm64_update_smccc_conduit(struct alt_instr *alt, |
| 296 | __le32 *origptr, __le32 *updptr, |
| 297 | int nr_inst) |
| 298 | { |
| 299 | u32 insn; |
| 300 | |
| 301 | BUG_ON(nr_inst != 1); |
| 302 | |
Mark Rutland | c98bd29 | 2019-08-09 14:22:41 +0100 | [diff] [blame] | 303 | switch (arm_smccc_1_1_get_conduit()) { |
| 304 | case SMCCC_CONDUIT_HVC: |
Marc Zyngier | 8e29062 | 2018-05-29 13:11:06 +0100 | [diff] [blame] | 305 | insn = aarch64_insn_get_hvc_value(); |
| 306 | break; |
Mark Rutland | c98bd29 | 2019-08-09 14:22:41 +0100 | [diff] [blame] | 307 | case SMCCC_CONDUIT_SMC: |
Marc Zyngier | 8e29062 | 2018-05-29 13:11:06 +0100 | [diff] [blame] | 308 | insn = aarch64_insn_get_smc_value(); |
| 309 | break; |
| 310 | default: |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | *updptr = cpu_to_le32(insn); |
| 315 | } |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 316 | |
Marc Zyngier | 986372c | 2018-05-29 13:11:11 +0100 | [diff] [blame] | 317 | void __init arm64_enable_wa2_handling(struct alt_instr *alt, |
| 318 | __le32 *origptr, __le32 *updptr, |
| 319 | int nr_inst) |
| 320 | { |
| 321 | BUG_ON(nr_inst != 1); |
| 322 | /* |
| 323 | * Only allow mitigation on EL1 entry/exit and guest |
| 324 | * ARCH_WORKAROUND_2 handling if the SSBD state allows it to |
| 325 | * be flipped. |
| 326 | */ |
| 327 | if (arm64_get_ssbd_state() == ARM64_SSBD_KERNEL) |
| 328 | *updptr = cpu_to_le32(aarch64_insn_gen_nop()); |
| 329 | } |
| 330 | |
Marc Zyngier | 647d051 | 2018-05-29 13:11:12 +0100 | [diff] [blame] | 331 | void arm64_set_ssbd_mitigation(bool state) |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 332 | { |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 333 | int conduit; |
| 334 | |
Jeremy Linton | d42281b | 2019-04-15 16:21:27 -0500 | [diff] [blame] | 335 | if (!IS_ENABLED(CONFIG_ARM64_SSBD)) { |
| 336 | pr_info_once("SSBD disabled by kernel configuration\n"); |
| 337 | return; |
| 338 | } |
| 339 | |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 340 | if (this_cpu_has_cap(ARM64_SSBS)) { |
| 341 | if (state) |
| 342 | asm volatile(SET_PSTATE_SSBS(0)); |
| 343 | else |
| 344 | asm volatile(SET_PSTATE_SSBS(1)); |
| 345 | return; |
| 346 | } |
| 347 | |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 348 | conduit = arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_WORKAROUND_2, state, |
| 349 | NULL); |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 350 | |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 351 | WARN_ON_ONCE(conduit == SMCCC_CONDUIT_NONE); |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, |
| 355 | int scope) |
| 356 | { |
| 357 | struct arm_smccc_res res; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 358 | bool required = true; |
| 359 | s32 val; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 360 | bool this_cpu_safe = false; |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 361 | int conduit; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 362 | |
| 363 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 364 | |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 365 | if (cpu_mitigations_off()) |
| 366 | ssbd_state = ARM64_SSBD_FORCE_DISABLE; |
| 367 | |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 368 | /* delay setting __ssb_safe until we get a firmware response */ |
| 369 | if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list)) |
| 370 | this_cpu_safe = true; |
| 371 | |
Will Deacon | eb337cd | 2019-04-30 16:58:56 +0100 | [diff] [blame] | 372 | if (this_cpu_has_cap(ARM64_SSBS)) { |
| 373 | if (!this_cpu_safe) |
| 374 | __ssb_safe = false; |
| 375 | required = false; |
| 376 | goto out_printmsg; |
| 377 | } |
| 378 | |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 379 | conduit = arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 380 | ARM_SMCCC_ARCH_WORKAROUND_2, &res); |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 381 | |
Steven Price | ce4d5ca | 2019-10-21 16:28:22 +0100 | [diff] [blame] | 382 | if (conduit == SMCCC_CONDUIT_NONE) { |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 383 | ssbd_state = ARM64_SSBD_UNKNOWN; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 384 | if (!this_cpu_safe) |
| 385 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 386 | return false; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 389 | val = (s32)res.a0; |
| 390 | |
| 391 | switch (val) { |
| 392 | case SMCCC_RET_NOT_SUPPORTED: |
| 393 | ssbd_state = ARM64_SSBD_UNKNOWN; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 394 | if (!this_cpu_safe) |
| 395 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 396 | return false; |
| 397 | |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 398 | /* machines with mixed mitigation requirements must not return this */ |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 399 | case SMCCC_RET_NOT_REQUIRED: |
| 400 | pr_info_once("%s mitigation not required\n", entry->desc); |
| 401 | ssbd_state = ARM64_SSBD_MITIGATED; |
| 402 | return false; |
| 403 | |
| 404 | case SMCCC_RET_SUCCESS: |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 405 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 406 | required = true; |
| 407 | break; |
| 408 | |
| 409 | case 1: /* Mitigation not required on this CPU */ |
| 410 | required = false; |
| 411 | break; |
| 412 | |
| 413 | default: |
| 414 | WARN_ON(1); |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 415 | if (!this_cpu_safe) |
| 416 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 417 | return false; |
| 418 | } |
| 419 | |
| 420 | switch (ssbd_state) { |
| 421 | case ARM64_SSBD_FORCE_DISABLE: |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 422 | arm64_set_ssbd_mitigation(false); |
| 423 | required = false; |
| 424 | break; |
| 425 | |
| 426 | case ARM64_SSBD_KERNEL: |
| 427 | if (required) { |
| 428 | __this_cpu_write(arm64_ssbd_callback_required, 1); |
| 429 | arm64_set_ssbd_mitigation(true); |
| 430 | } |
| 431 | break; |
| 432 | |
| 433 | case ARM64_SSBD_FORCE_ENABLE: |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 434 | arm64_set_ssbd_mitigation(true); |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 435 | required = true; |
| 436 | break; |
| 437 | |
| 438 | default: |
| 439 | WARN_ON(1); |
| 440 | break; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 441 | } |
| 442 | |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 443 | out_printmsg: |
| 444 | switch (ssbd_state) { |
| 445 | case ARM64_SSBD_FORCE_DISABLE: |
| 446 | pr_info_once("%s disabled from command-line\n", entry->desc); |
| 447 | break; |
| 448 | |
| 449 | case ARM64_SSBD_FORCE_ENABLE: |
| 450 | pr_info_once("%s forced from command-line\n", entry->desc); |
| 451 | break; |
| 452 | } |
| 453 | |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 454 | return required; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 455 | } |
Marc Zyngier | 8e29062 | 2018-05-29 13:11:06 +0100 | [diff] [blame] | 456 | |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 457 | /* known invulnerable cores */ |
| 458 | static const struct midr_range arm64_ssb_cpus[] = { |
| 459 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 460 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 461 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
Florian Fainelli | e059770 | 2019-10-31 14:47:24 -0700 | [diff] [blame] | 462 | MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53), |
Sai Prakash Ranjan | 108447f | 2020-06-25 16:01:23 +0530 | [diff] [blame] | 463 | MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER), |
| 464 | MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER), |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 465 | {}, |
| 466 | }; |
| 467 | |
Will Deacon | 969f5ea | 2019-04-29 13:03:57 +0100 | [diff] [blame] | 468 | #ifdef CONFIG_ARM64_ERRATUM_1463225 |
| 469 | DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa); |
| 470 | |
| 471 | static bool |
| 472 | has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry, |
| 473 | int scope) |
| 474 | { |
Sai Prakash Ranjan | a9e821b | 2020-06-30 23:30:54 +0530 | [diff] [blame] | 475 | return is_affected_midr_range_list(entry, scope) && is_kernel_in_hyp_mode(); |
Will Deacon | 969f5ea | 2019-04-29 13:03:57 +0100 | [diff] [blame] | 476 | } |
| 477 | #endif |
| 478 | |
Will Deacon | b8925ee | 2018-08-07 13:53:41 +0100 | [diff] [blame] | 479 | static void __maybe_unused |
| 480 | cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused) |
| 481 | { |
| 482 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCI, 0); |
| 483 | } |
| 484 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 485 | #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ |
| 486 | .matches = is_affected_midr_range, \ |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 487 | .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max) |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 488 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 489 | #define CAP_MIDR_ALL_VERSIONS(model) \ |
| 490 | .matches = is_affected_midr_range, \ |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 491 | .midr_range = MIDR_ALL_VERSIONS(model) |
Marc Zyngier | 06f1494 | 2017-02-01 14:38:46 +0000 | [diff] [blame] | 492 | |
Ard Biesheuvel | e8002e0 | 2018-03-06 17:15:34 +0000 | [diff] [blame] | 493 | #define MIDR_FIXED(rev, revidr_mask) \ |
| 494 | .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}} |
| 495 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 496 | #define ERRATA_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ |
| 497 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 498 | CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) |
| 499 | |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 500 | #define CAP_MIDR_RANGE_LIST(list) \ |
| 501 | .matches = is_affected_midr_range_list, \ |
| 502 | .midr_range_list = list |
| 503 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 504 | /* Errata affecting a range of revisions of given model variant */ |
| 505 | #define ERRATA_MIDR_REV_RANGE(m, var, r_min, r_max) \ |
| 506 | ERRATA_MIDR_RANGE(m, var, r_min, var, r_max) |
| 507 | |
| 508 | /* Errata affecting a single variant/revision of a model */ |
| 509 | #define ERRATA_MIDR_REV(model, var, rev) \ |
| 510 | ERRATA_MIDR_RANGE(model, var, rev, var, rev) |
| 511 | |
| 512 | /* Errata affecting all variants/revisions of a given a model */ |
| 513 | #define ERRATA_MIDR_ALL_VERSIONS(model) \ |
| 514 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 515 | CAP_MIDR_ALL_VERSIONS(model) |
| 516 | |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 517 | /* Errata affecting a list of midr ranges, with same work around */ |
| 518 | #define ERRATA_MIDR_RANGE_LIST(midr_list) \ |
| 519 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 520 | CAP_MIDR_RANGE_LIST(midr_list) |
| 521 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 522 | /* Track overall mitigation state. We are only mitigated if all cores are ok */ |
| 523 | static bool __hardenbp_enab = true; |
| 524 | static bool __spectrev2_safe = true; |
| 525 | |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 526 | int get_spectre_v2_workaround_state(void) |
| 527 | { |
| 528 | if (__spectrev2_safe) |
| 529 | return ARM64_BP_HARDEN_NOT_REQUIRED; |
| 530 | |
| 531 | if (!__hardenbp_enab) |
| 532 | return ARM64_BP_HARDEN_UNKNOWN; |
| 533 | |
| 534 | return ARM64_BP_HARDEN_WA_NEEDED; |
| 535 | } |
| 536 | |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 537 | /* |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 538 | * List of CPUs that do not need any Spectre-v2 mitigation at all. |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 539 | */ |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 540 | static const struct midr_range spectre_v2_safe_list[] = { |
| 541 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 542 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 543 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
Florian Fainelli | e059770 | 2019-10-31 14:47:24 -0700 | [diff] [blame] | 544 | MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53), |
Wei Li | aa638cf | 2019-12-20 17:17:10 +0800 | [diff] [blame] | 545 | MIDR_ALL_VERSIONS(MIDR_HISI_TSV110), |
Sai Prakash Ranjan | 83b0c36 | 2020-01-17 01:33:53 +0530 | [diff] [blame] | 546 | MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER), |
| 547 | MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER), |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 548 | { /* sentinel */ } |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 549 | }; |
| 550 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 551 | /* |
| 552 | * Track overall bp hardening for all heterogeneous cores in the machine. |
| 553 | * We are only considered "safe" if all booted cores are known safe. |
| 554 | */ |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 555 | static bool __maybe_unused |
| 556 | check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) |
| 557 | { |
| 558 | int need_wa; |
| 559 | |
| 560 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 561 | |
| 562 | /* If the CPU has CSV2 set, we're safe */ |
| 563 | if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1), |
| 564 | ID_AA64PFR0_CSV2_SHIFT)) |
| 565 | return false; |
| 566 | |
| 567 | /* Alternatively, we have a list of unaffected CPUs */ |
| 568 | if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list)) |
| 569 | return false; |
| 570 | |
| 571 | /* Fallback to firmware detection */ |
| 572 | need_wa = detect_harden_bp_fw(); |
| 573 | if (!need_wa) |
| 574 | return false; |
| 575 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 576 | __spectrev2_safe = false; |
| 577 | |
Jeremy Linton | 8c1e3d2 | 2019-04-15 16:21:25 -0500 | [diff] [blame] | 578 | if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) { |
| 579 | pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n"); |
| 580 | __hardenbp_enab = false; |
| 581 | return false; |
| 582 | } |
| 583 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 584 | /* forced off */ |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 585 | if (__nospectre_v2 || cpu_mitigations_off()) { |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 586 | pr_info_once("spectrev2 mitigation disabled by command line option\n"); |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 587 | __hardenbp_enab = false; |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 588 | return false; |
| 589 | } |
| 590 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 591 | if (need_wa < 0) { |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 592 | pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n"); |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 593 | __hardenbp_enab = false; |
| 594 | } |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 595 | |
| 596 | return (need_wa > 0); |
| 597 | } |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 598 | |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 599 | static const __maybe_unused struct midr_range tx2_family_cpus[] = { |
| 600 | MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), |
| 601 | MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), |
| 602 | {}, |
| 603 | }; |
| 604 | |
| 605 | static bool __maybe_unused |
| 606 | needs_tx2_tvm_workaround(const struct arm64_cpu_capabilities *entry, |
| 607 | int scope) |
| 608 | { |
| 609 | int i; |
| 610 | |
| 611 | if (!is_affected_midr_range_list(entry, scope) || |
| 612 | !is_hyp_mode_available()) |
| 613 | return false; |
| 614 | |
| 615 | for_each_possible_cpu(i) { |
| 616 | if (MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 0) != 0) |
| 617 | return true; |
| 618 | } |
| 619 | |
| 620 | return false; |
| 621 | } |
| 622 | |
James Morse | 0546084 | 2019-10-17 18:42:58 +0100 | [diff] [blame] | 623 | static bool __maybe_unused |
| 624 | has_neoverse_n1_erratum_1542419(const struct arm64_cpu_capabilities *entry, |
| 625 | int scope) |
| 626 | { |
| 627 | u32 midr = read_cpuid_id(); |
| 628 | bool has_dic = read_cpuid_cachetype() & BIT(CTR_DIC_SHIFT); |
| 629 | const struct midr_range range = MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1); |
Marc Zyngier | 8892b71 | 2018-04-10 11:36:43 +0100 | [diff] [blame] | 630 | |
James Morse | 0546084 | 2019-10-17 18:42:58 +0100 | [diff] [blame] | 631 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 632 | return is_midr_in_range(midr, &range) && has_dic; |
| 633 | } |
| 634 | |
Andrew Scull | 02ab1f5 | 2020-05-04 10:48:58 +0100 | [diff] [blame] | 635 | #if defined(CONFIG_HARDEN_EL2_VECTORS) |
Marc Zyngier | 8892b71 | 2018-04-10 11:36:43 +0100 | [diff] [blame] | 636 | |
Marc Zyngier | f75e229 | 2018-11-23 17:25:52 +0000 | [diff] [blame] | 637 | static const struct midr_range ca57_a72[] = { |
Marc Zyngier | 8892b71 | 2018-04-10 11:36:43 +0100 | [diff] [blame] | 638 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), |
| 639 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), |
| 640 | {}, |
| 641 | }; |
| 642 | |
Marc Zyngier | dc6ed61 | 2018-03-28 12:46:07 +0100 | [diff] [blame] | 643 | #endif |
| 644 | |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 645 | #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI |
Bjorn Andersson | 36c602d | 2019-10-29 16:27:38 -0700 | [diff] [blame] | 646 | static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = { |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 647 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009 |
Bjorn Andersson | 36c602d | 2019-10-29 16:27:38 -0700 | [diff] [blame] | 648 | { |
| 649 | ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0) |
| 650 | }, |
| 651 | { |
| 652 | .midr_range.model = MIDR_QCOM_KRYO, |
| 653 | .matches = is_kryo_midr, |
| 654 | }, |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 655 | #endif |
| 656 | #ifdef CONFIG_ARM64_ERRATUM_1286807 |
Bjorn Andersson | 36c602d | 2019-10-29 16:27:38 -0700 | [diff] [blame] | 657 | { |
| 658 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 0), |
| 659 | }, |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 660 | #endif |
| 661 | {}, |
| 662 | }; |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 663 | #endif |
| 664 | |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 665 | #ifdef CONFIG_CAVIUM_ERRATUM_27456 |
Will Deacon | b89d82e | 2019-01-08 16:19:01 +0000 | [diff] [blame] | 666 | const struct midr_range cavium_erratum_27456_cpus[] = { |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 667 | /* Cavium ThunderX, T88 pass 1.x - 2.1 */ |
| 668 | MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 1), |
| 669 | /* Cavium ThunderX, T81 pass 1.0 */ |
| 670 | MIDR_REV(MIDR_THUNDERX_81XX, 0, 0), |
| 671 | {}, |
| 672 | }; |
| 673 | #endif |
| 674 | |
| 675 | #ifdef CONFIG_CAVIUM_ERRATUM_30115 |
| 676 | static const struct midr_range cavium_erratum_30115_cpus[] = { |
| 677 | /* Cavium ThunderX, T88 pass 1.x - 2.2 */ |
| 678 | MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 2), |
| 679 | /* Cavium ThunderX, T81 pass 1.0 - 1.2 */ |
| 680 | MIDR_REV_RANGE(MIDR_THUNDERX_81XX, 0, 0, 2), |
| 681 | /* Cavium ThunderX, T83 pass 1.0 */ |
| 682 | MIDR_REV(MIDR_THUNDERX_83XX, 0, 0), |
| 683 | {}, |
| 684 | }; |
| 685 | #endif |
| 686 | |
Suzuki K Poulose | a3dcea2c | 2018-11-30 17:18:02 +0000 | [diff] [blame] | 687 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 |
| 688 | static const struct arm64_cpu_capabilities qcom_erratum_1003_list[] = { |
| 689 | { |
| 690 | ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0), |
| 691 | }, |
| 692 | { |
| 693 | .midr_range.model = MIDR_QCOM_KRYO, |
| 694 | .matches = is_kryo_midr, |
| 695 | }, |
| 696 | {}, |
| 697 | }; |
| 698 | #endif |
| 699 | |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 700 | #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE |
| 701 | static const struct midr_range workaround_clean_cache[] = { |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 702 | #if defined(CONFIG_ARM64_ERRATUM_826319) || \ |
| 703 | defined(CONFIG_ARM64_ERRATUM_827319) || \ |
| 704 | defined(CONFIG_ARM64_ERRATUM_824069) |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 705 | /* Cortex-A53 r0p[012]: ARM errata 826319, 827319, 824069 */ |
| 706 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 2), |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 707 | #endif |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 708 | #ifdef CONFIG_ARM64_ERRATUM_819472 |
| 709 | /* Cortex-A53 r0p[01] : ARM errata 819472 */ |
| 710 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1), |
| 711 | #endif |
| 712 | {}, |
| 713 | }; |
| 714 | #endif |
| 715 | |
Marc Zyngier | a532508 | 2019-05-23 11:24:50 +0100 | [diff] [blame] | 716 | #ifdef CONFIG_ARM64_ERRATUM_1418040 |
| 717 | /* |
| 718 | * - 1188873 affects r0p0 to r2p0 |
| 719 | * - 1418040 affects r0p0 to r3p1 |
| 720 | */ |
| 721 | static const struct midr_range erratum_1418040_list[] = { |
| 722 | /* Cortex-A76 r0p0 to r3p1 */ |
| 723 | MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1), |
| 724 | /* Neoverse-N1 r0p0 to r3p1 */ |
| 725 | MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 0, 3, 1), |
Sai Prakash Ranjan | a9e821b | 2020-06-30 23:30:54 +0530 | [diff] [blame] | 726 | /* Kryo4xx Gold (rcpe to rfpf) => (r0p0 to r3p1) */ |
| 727 | MIDR_RANGE(MIDR_QCOM_KRYO_4XX_GOLD, 0xc, 0xe, 0xf, 0xf), |
Marc Zyngier | 6989303 | 2019-04-15 13:03:54 +0100 | [diff] [blame] | 728 | {}, |
| 729 | }; |
| 730 | #endif |
| 731 | |
Doug Berger | bfc97f9 | 2019-10-31 14:47:23 -0700 | [diff] [blame] | 732 | #ifdef CONFIG_ARM64_ERRATUM_845719 |
| 733 | static const struct midr_range erratum_845719_list[] = { |
| 734 | /* Cortex-A53 r0p[01234] */ |
| 735 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4), |
| 736 | /* Brahma-B53 r0p[0] */ |
| 737 | MIDR_REV(MIDR_BRAHMA_B53, 0, 0), |
| 738 | {}, |
| 739 | }; |
| 740 | #endif |
| 741 | |
Florian Fainelli | 1cf45b8 | 2019-10-31 14:47:25 -0700 | [diff] [blame] | 742 | #ifdef CONFIG_ARM64_ERRATUM_843419 |
| 743 | static const struct arm64_cpu_capabilities erratum_843419_list[] = { |
| 744 | { |
| 745 | /* Cortex-A53 r0p[01234] */ |
| 746 | .matches = is_affected_midr_range, |
| 747 | ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4), |
| 748 | MIDR_FIXED(0x4, BIT(8)), |
| 749 | }, |
| 750 | { |
| 751 | /* Brahma-B53 r0p[0] */ |
| 752 | .matches = is_affected_midr_range, |
| 753 | ERRATA_MIDR_REV(MIDR_BRAHMA_B53, 0, 0), |
| 754 | }, |
| 755 | {}, |
| 756 | }; |
| 757 | #endif |
| 758 | |
Andrew Scull | 02ab1f5 | 2020-05-04 10:48:58 +0100 | [diff] [blame] | 759 | #ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_AT |
| 760 | static const struct midr_range erratum_speculative_at_list[] = { |
Steven Price | e85d68f | 2019-12-16 11:56:29 +0000 | [diff] [blame] | 761 | #ifdef CONFIG_ARM64_ERRATUM_1165522 |
| 762 | /* Cortex A76 r0p0 to r2p0 */ |
| 763 | MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 2, 0), |
| 764 | #endif |
Andrew Scull | 02ab1f5 | 2020-05-04 10:48:58 +0100 | [diff] [blame] | 765 | #ifdef CONFIG_ARM64_ERRATUM_1319367 |
| 766 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), |
| 767 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), |
| 768 | #endif |
Steven Price | 275fa0e | 2019-12-16 11:56:31 +0000 | [diff] [blame] | 769 | #ifdef CONFIG_ARM64_ERRATUM_1530923 |
| 770 | /* Cortex A55 r0p0 to r2p0 */ |
| 771 | MIDR_RANGE(MIDR_CORTEX_A55, 0, 0, 2, 0), |
Sai Prakash Ranjan | 9b23d95 | 2020-06-30 23:30:55 +0530 | [diff] [blame^] | 772 | /* Kryo4xx Silver (rdpe => r1p0) */ |
| 773 | MIDR_REV(MIDR_QCOM_KRYO_4XX_SILVER, 0xd, 0xe), |
Steven Price | 275fa0e | 2019-12-16 11:56:31 +0000 | [diff] [blame] | 774 | #endif |
Steven Price | e85d68f | 2019-12-16 11:56:29 +0000 | [diff] [blame] | 775 | {}, |
| 776 | }; |
| 777 | #endif |
| 778 | |
Sai Prakash Ranjan | a9e821b | 2020-06-30 23:30:54 +0530 | [diff] [blame] | 779 | #ifdef CONFIG_ARM64_ERRATUM_1463225 |
| 780 | static const struct midr_range erratum_1463225[] = { |
| 781 | /* Cortex-A76 r0p0 - r3p1 */ |
| 782 | MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1), |
| 783 | /* Kryo4xx Gold (rcpe to rfpf) => (r0p0 to r3p1) */ |
| 784 | MIDR_RANGE(MIDR_QCOM_KRYO_4XX_GOLD, 0xc, 0xe, 0xf, 0xf), |
| 785 | }; |
| 786 | #endif |
| 787 | |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 788 | const struct arm64_cpu_capabilities arm64_errata[] = { |
| 789 | #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 790 | { |
Geert Uytterhoeven | 357dd8a | 2020-05-12 16:52:55 +0200 | [diff] [blame] | 791 | .desc = "ARM errata 826319, 827319, 824069, or 819472", |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 792 | .capability = ARM64_WORKAROUND_CLEAN_CACHE, |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 793 | ERRATA_MIDR_RANGE_LIST(workaround_clean_cache), |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 794 | .cpu_enable = cpu_enable_cache_maint_trap, |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 795 | }, |
| 796 | #endif |
| 797 | #ifdef CONFIG_ARM64_ERRATUM_832075 |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 798 | { |
Andre Przywara | 5afaa1f | 2014-11-14 15:54:11 +0000 | [diff] [blame] | 799 | /* Cortex-A57 r0p0 - r1p2 */ |
| 800 | .desc = "ARM erratum 832075", |
| 801 | .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 802 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A57, |
| 803 | 0, 0, |
| 804 | 1, 2), |
Andre Przywara | 5afaa1f | 2014-11-14 15:54:11 +0000 | [diff] [blame] | 805 | }, |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 806 | #endif |
Marc Zyngier | 498cd5c | 2015-11-16 10:28:18 +0000 | [diff] [blame] | 807 | #ifdef CONFIG_ARM64_ERRATUM_834220 |
| 808 | { |
| 809 | /* Cortex-A57 r0p0 - r1p2 */ |
| 810 | .desc = "ARM erratum 834220", |
| 811 | .capability = ARM64_WORKAROUND_834220, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 812 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A57, |
| 813 | 0, 0, |
| 814 | 1, 2), |
Marc Zyngier | 498cd5c | 2015-11-16 10:28:18 +0000 | [diff] [blame] | 815 | }, |
| 816 | #endif |
Ard Biesheuvel | ca79acc | 2018-03-06 17:15:35 +0000 | [diff] [blame] | 817 | #ifdef CONFIG_ARM64_ERRATUM_843419 |
| 818 | { |
Ard Biesheuvel | ca79acc | 2018-03-06 17:15:35 +0000 | [diff] [blame] | 819 | .desc = "ARM erratum 843419", |
| 820 | .capability = ARM64_WORKAROUND_843419, |
Florian Fainelli | 1cf45b8 | 2019-10-31 14:47:25 -0700 | [diff] [blame] | 821 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 822 | .matches = cpucap_multi_entry_cap_matches, |
| 823 | .match_list = erratum_843419_list, |
Will Deacon | 905e8c5 | 2015-03-23 19:07:02 +0000 | [diff] [blame] | 824 | }, |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 825 | #endif |
| 826 | #ifdef CONFIG_ARM64_ERRATUM_845719 |
| 827 | { |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 828 | .desc = "ARM erratum 845719", |
| 829 | .capability = ARM64_WORKAROUND_845719, |
Doug Berger | bfc97f9 | 2019-10-31 14:47:23 -0700 | [diff] [blame] | 830 | ERRATA_MIDR_RANGE_LIST(erratum_845719_list), |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 831 | }, |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 832 | #endif |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 833 | #ifdef CONFIG_CAVIUM_ERRATUM_23154 |
| 834 | { |
| 835 | /* Cavium ThunderX, pass 1.x */ |
| 836 | .desc = "Cavium erratum 23154", |
| 837 | .capability = ARM64_WORKAROUND_CAVIUM_23154, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 838 | ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1), |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 839 | }, |
| 840 | #endif |
Andrew Pinski | 104a0c0 | 2016-02-24 17:44:57 -0800 | [diff] [blame] | 841 | #ifdef CONFIG_CAVIUM_ERRATUM_27456 |
| 842 | { |
Andrew Pinski | 104a0c0 | 2016-02-24 17:44:57 -0800 | [diff] [blame] | 843 | .desc = "Cavium erratum 27456", |
| 844 | .capability = ARM64_WORKAROUND_CAVIUM_27456, |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 845 | ERRATA_MIDR_RANGE_LIST(cavium_erratum_27456_cpus), |
Ganapatrao Kulkarni | 47c459b | 2016-07-07 10:18:17 +0530 | [diff] [blame] | 846 | }, |
Andrew Pinski | 104a0c0 | 2016-02-24 17:44:57 -0800 | [diff] [blame] | 847 | #endif |
David Daney | 690a341 | 2017-06-09 12:49:48 +0100 | [diff] [blame] | 848 | #ifdef CONFIG_CAVIUM_ERRATUM_30115 |
| 849 | { |
David Daney | 690a341 | 2017-06-09 12:49:48 +0100 | [diff] [blame] | 850 | .desc = "Cavium erratum 30115", |
| 851 | .capability = ARM64_WORKAROUND_CAVIUM_30115, |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 852 | ERRATA_MIDR_RANGE_LIST(cavium_erratum_30115_cpus), |
David Daney | 690a341 | 2017-06-09 12:49:48 +0100 | [diff] [blame] | 853 | }, |
| 854 | #endif |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 855 | { |
Will Deacon | 880f7cc | 2018-09-19 11:41:21 +0100 | [diff] [blame] | 856 | .desc = "Mismatched cache type (CTR_EL0)", |
Suzuki K Poulose | 314d53d | 2018-07-04 23:07:46 +0100 | [diff] [blame] | 857 | .capability = ARM64_MISMATCHED_CACHE_TYPE, |
| 858 | .matches = has_mismatched_cache_type, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 859 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 860 | .cpu_enable = cpu_enable_trap_ctr_access, |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 861 | }, |
Christopher Covington | 38fd94b | 2017-02-08 15:08:37 -0500 | [diff] [blame] | 862 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 |
| 863 | { |
Suzuki K Poulose | a3dcea2c | 2018-11-30 17:18:02 +0000 | [diff] [blame] | 864 | .desc = "Qualcomm Technologies Falkor/Kryo erratum 1003", |
Christopher Covington | 38fd94b | 2017-02-08 15:08:37 -0500 | [diff] [blame] | 865 | .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003, |
Bjorn Andersson | d4af3c4 | 2019-10-29 10:15:39 -0700 | [diff] [blame] | 866 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
Will Deacon | 1e013d0 | 2018-12-12 15:53:54 +0000 | [diff] [blame] | 867 | .matches = cpucap_multi_entry_cap_matches, |
Suzuki K Poulose | a3dcea2c | 2018-11-30 17:18:02 +0000 | [diff] [blame] | 868 | .match_list = qcom_erratum_1003_list, |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 869 | }, |
Christopher Covington | 38fd94b | 2017-02-08 15:08:37 -0500 | [diff] [blame] | 870 | #endif |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 871 | #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI |
Christopher Covington | d9ff80f | 2017-01-31 12:50:19 -0500 | [diff] [blame] | 872 | { |
Geert Uytterhoeven | 357dd8a | 2020-05-12 16:52:55 +0200 | [diff] [blame] | 873 | .desc = "Qualcomm erratum 1009, or ARM erratum 1286807", |
Christopher Covington | d9ff80f | 2017-01-31 12:50:19 -0500 | [diff] [blame] | 874 | .capability = ARM64_WORKAROUND_REPEAT_TLBI, |
Bjorn Andersson | 36c602d | 2019-10-29 16:27:38 -0700 | [diff] [blame] | 875 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 876 | .matches = cpucap_multi_entry_cap_matches, |
| 877 | .match_list = arm64_repeat_tlbi_list, |
Christopher Covington | d9ff80f | 2017-01-31 12:50:19 -0500 | [diff] [blame] | 878 | }, |
| 879 | #endif |
Marc Zyngier | eeb1efb | 2017-03-20 17:18:06 +0000 | [diff] [blame] | 880 | #ifdef CONFIG_ARM64_ERRATUM_858921 |
| 881 | { |
| 882 | /* Cortex-A73 all versions */ |
| 883 | .desc = "ARM erratum 858921", |
| 884 | .capability = ARM64_WORKAROUND_858921, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 885 | ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), |
Marc Zyngier | eeb1efb | 2017-03-20 17:18:06 +0000 | [diff] [blame] | 886 | }, |
| 887 | #endif |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 888 | { |
| 889 | .capability = ARM64_HARDEN_BRANCH_PREDICTOR, |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 890 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 891 | .matches = check_branch_predictor, |
Jayachandran C | f3d795d | 2018-01-19 04:22:47 -0800 | [diff] [blame] | 892 | }, |
Marc Zyngier | 4b472ff | 2018-02-15 11:49:20 +0000 | [diff] [blame] | 893 | #ifdef CONFIG_HARDEN_EL2_VECTORS |
| 894 | { |
Marc Zyngier | 8892b71 | 2018-04-10 11:36:43 +0100 | [diff] [blame] | 895 | .desc = "EL2 vector hardening", |
Marc Zyngier | 4b472ff | 2018-02-15 11:49:20 +0000 | [diff] [blame] | 896 | .capability = ARM64_HARDEN_EL2_VECTORS, |
Marc Zyngier | f75e229 | 2018-11-23 17:25:52 +0000 | [diff] [blame] | 897 | ERRATA_MIDR_RANGE_LIST(ca57_a72), |
Marc Zyngier | 4b472ff | 2018-02-15 11:49:20 +0000 | [diff] [blame] | 898 | }, |
| 899 | #endif |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 900 | { |
| 901 | .desc = "Speculative Store Bypass Disable", |
| 902 | .capability = ARM64_SSBD, |
| 903 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 904 | .matches = has_ssbd_mitigation, |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 905 | .midr_range_list = arm64_ssb_cpus, |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 906 | }, |
Marc Zyngier | a532508 | 2019-05-23 11:24:50 +0100 | [diff] [blame] | 907 | #ifdef CONFIG_ARM64_ERRATUM_1418040 |
Marc Zyngier | 95b861a4 | 2018-09-27 17:15:34 +0100 | [diff] [blame] | 908 | { |
Marc Zyngier | a532508 | 2019-05-23 11:24:50 +0100 | [diff] [blame] | 909 | .desc = "ARM erratum 1418040", |
| 910 | .capability = ARM64_WORKAROUND_1418040, |
| 911 | ERRATA_MIDR_RANGE_LIST(erratum_1418040_list), |
Marc Zyngier | 95b861a4 | 2018-09-27 17:15:34 +0100 | [diff] [blame] | 912 | }, |
| 913 | #endif |
Andrew Scull | 02ab1f5 | 2020-05-04 10:48:58 +0100 | [diff] [blame] | 914 | #ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_AT |
Marc Zyngier | 8b2cca9 | 2018-12-06 17:31:23 +0000 | [diff] [blame] | 915 | { |
Will Deacon | c350717 | 2020-05-28 18:02:51 +0100 | [diff] [blame] | 916 | .desc = "ARM errata 1165522, 1319367, or 1530923", |
Andrew Scull | 02ab1f5 | 2020-05-04 10:48:58 +0100 | [diff] [blame] | 917 | .capability = ARM64_WORKAROUND_SPECULATIVE_AT, |
| 918 | ERRATA_MIDR_RANGE_LIST(erratum_speculative_at_list), |
Marc Zyngier | 8b2cca9 | 2018-12-06 17:31:23 +0000 | [diff] [blame] | 919 | }, |
| 920 | #endif |
Will Deacon | 969f5ea | 2019-04-29 13:03:57 +0100 | [diff] [blame] | 921 | #ifdef CONFIG_ARM64_ERRATUM_1463225 |
| 922 | { |
| 923 | .desc = "ARM erratum 1463225", |
| 924 | .capability = ARM64_WORKAROUND_1463225, |
| 925 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 926 | .matches = has_cortex_a76_erratum_1463225, |
Sai Prakash Ranjan | a9e821b | 2020-06-30 23:30:54 +0530 | [diff] [blame] | 927 | .midr_range_list = erratum_1463225, |
Will Deacon | 969f5ea | 2019-04-29 13:03:57 +0100 | [diff] [blame] | 928 | }, |
| 929 | #endif |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 930 | #ifdef CONFIG_CAVIUM_TX2_ERRATUM_219 |
| 931 | { |
| 932 | .desc = "Cavium ThunderX2 erratum 219 (KVM guest sysreg trapping)", |
| 933 | .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_TVM, |
| 934 | ERRATA_MIDR_RANGE_LIST(tx2_family_cpus), |
| 935 | .matches = needs_tx2_tvm_workaround, |
| 936 | }, |
Marc Zyngier | 9405447 | 2019-04-09 16:22:24 +0100 | [diff] [blame] | 937 | { |
| 938 | .desc = "Cavium ThunderX2 erratum 219 (PRFM removal)", |
| 939 | .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM, |
| 940 | ERRATA_MIDR_RANGE_LIST(tx2_family_cpus), |
| 941 | }, |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 942 | #endif |
James Morse | 0546084 | 2019-10-17 18:42:58 +0100 | [diff] [blame] | 943 | #ifdef CONFIG_ARM64_ERRATUM_1542419 |
| 944 | { |
| 945 | /* we depend on the firmware portion for correctness */ |
| 946 | .desc = "ARM erratum 1542419 (kernel portion)", |
| 947 | .capability = ARM64_WORKAROUND_1542419, |
| 948 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 949 | .matches = has_neoverse_n1_erratum_1542419, |
| 950 | .cpu_enable = cpu_enable_trap_ctr_access, |
| 951 | }, |
| 952 | #endif |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 953 | { |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 954 | } |
| 955 | }; |
Mian Yousaf Kaukab | 3891ebc | 2019-04-15 16:21:21 -0500 | [diff] [blame] | 956 | |
| 957 | ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, |
| 958 | char *buf) |
| 959 | { |
| 960 | return sprintf(buf, "Mitigation: __user pointer sanitization\n"); |
| 961 | } |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 962 | |
| 963 | ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, |
| 964 | char *buf) |
| 965 | { |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 966 | switch (get_spectre_v2_workaround_state()) { |
| 967 | case ARM64_BP_HARDEN_NOT_REQUIRED: |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 968 | return sprintf(buf, "Not affected\n"); |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 969 | case ARM64_BP_HARDEN_WA_NEEDED: |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 970 | return sprintf(buf, "Mitigation: Branch predictor hardening\n"); |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 971 | case ARM64_BP_HARDEN_UNKNOWN: |
| 972 | default: |
| 973 | return sprintf(buf, "Vulnerable\n"); |
| 974 | } |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 975 | } |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 976 | |
| 977 | ssize_t cpu_show_spec_store_bypass(struct device *dev, |
| 978 | struct device_attribute *attr, char *buf) |
| 979 | { |
| 980 | if (__ssb_safe) |
| 981 | return sprintf(buf, "Not affected\n"); |
| 982 | |
| 983 | switch (ssbd_state) { |
| 984 | case ARM64_SSBD_KERNEL: |
| 985 | case ARM64_SSBD_FORCE_ENABLE: |
| 986 | if (IS_ENABLED(CONFIG_ARM64_SSBD)) |
| 987 | return sprintf(buf, |
| 988 | "Mitigation: Speculative Store Bypass disabled via prctl\n"); |
| 989 | } |
| 990 | |
| 991 | return sprintf(buf, "Vulnerable\n"); |
| 992 | } |