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