David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Contains CPU specific errata definitions |
| 4 | * |
| 5 | * Copyright (C) 2014 ARM Ltd. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/arm-smccc.h> |
| 9 | #include <linux/psci.h> |
| 10 | #include <linux/types.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11 | #include <linux/cpu.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12 | #include <asm/cpu.h> |
| 13 | #include <asm/cputype.h> |
| 14 | #include <asm/cpufeature.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15 | #include <asm/smp_plat.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16 | |
| 17 | static bool __maybe_unused |
| 18 | is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) |
| 19 | { |
| 20 | const struct arm64_midr_revidr *fix; |
| 21 | u32 midr = read_cpuid_id(), revidr; |
| 22 | |
| 23 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 24 | if (!is_midr_in_range(midr, &entry->midr_range)) |
| 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; |
| 34 | } |
| 35 | |
| 36 | static bool __maybe_unused |
| 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); |
| 42 | } |
| 43 | |
| 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 | |
| 55 | return model == entry->midr_range.model; |
| 56 | } |
| 57 | |
| 58 | static bool |
| 59 | has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry, |
| 60 | int scope) |
| 61 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [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; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 65 | |
| 66 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [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); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 91 | cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *cap) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 92 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 93 | u64 mask = arm64_ftr_reg_ctrel0.strict_mask; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 94 | bool enable_uct_trap = false; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [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)) |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [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) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 106 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1); |
| 110 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +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 | |
| 116 | #ifdef CONFIG_KVM_INDIRECT_VECTORS |
| 117 | extern char __smccc_workaround_1_smc_start[]; |
| 118 | extern char __smccc_workaround_1_smc_end[]; |
| 119 | |
| 120 | static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, |
| 121 | const char *hyp_vecs_end) |
| 122 | { |
| 123 | void *dst = lm_alias(__bp_harden_hyp_vecs_start + slot * SZ_2K); |
| 124 | int i; |
| 125 | |
| 126 | for (i = 0; i < SZ_2K; i += 0x80) |
| 127 | memcpy(dst + i, hyp_vecs_start, hyp_vecs_end - hyp_vecs_start); |
| 128 | |
| 129 | __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K); |
| 130 | } |
| 131 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 132 | static void install_bp_hardening_cb(bp_hardening_cb_t fn, |
| 133 | const char *hyp_vecs_start, |
| 134 | const char *hyp_vecs_end) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 135 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 136 | static DEFINE_RAW_SPINLOCK(bp_lock); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 137 | int cpu, slot = -1; |
| 138 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 139 | /* |
| 140 | * detect_harden_bp_fw() passes NULL for the hyp_vecs start/end if |
| 141 | * we're a guest. Skip the hyp-vectors work. |
| 142 | */ |
| 143 | if (!hyp_vecs_start) { |
| 144 | __this_cpu_write(bp_hardening_data.fn, fn); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | raw_spin_lock(&bp_lock); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 149 | for_each_possible_cpu(cpu) { |
| 150 | if (per_cpu(bp_hardening_data.fn, cpu) == fn) { |
| 151 | slot = per_cpu(bp_hardening_data.hyp_vectors_slot, cpu); |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (slot == -1) { |
| 157 | slot = atomic_inc_return(&arm64_el2_vector_last_slot); |
| 158 | BUG_ON(slot >= BP_HARDEN_EL2_SLOTS); |
| 159 | __copy_hyp_vect_bpi(slot, hyp_vecs_start, hyp_vecs_end); |
| 160 | } |
| 161 | |
| 162 | __this_cpu_write(bp_hardening_data.hyp_vectors_slot, slot); |
| 163 | __this_cpu_write(bp_hardening_data.fn, fn); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 164 | raw_spin_unlock(&bp_lock); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 165 | } |
| 166 | #else |
| 167 | #define __smccc_workaround_1_smc_start NULL |
| 168 | #define __smccc_workaround_1_smc_end NULL |
| 169 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 170 | static void install_bp_hardening_cb(bp_hardening_cb_t fn, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 171 | const char *hyp_vecs_start, |
| 172 | const char *hyp_vecs_end) |
| 173 | { |
| 174 | __this_cpu_write(bp_hardening_data.fn, fn); |
| 175 | } |
| 176 | #endif /* CONFIG_KVM_INDIRECT_VECTORS */ |
| 177 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 178 | #include <uapi/linux/psci.h> |
| 179 | #include <linux/arm-smccc.h> |
| 180 | #include <linux/psci.h> |
| 181 | |
| 182 | static void call_smc_arch_workaround_1(void) |
| 183 | { |
| 184 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); |
| 185 | } |
| 186 | |
| 187 | static void call_hvc_arch_workaround_1(void) |
| 188 | { |
| 189 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); |
| 190 | } |
| 191 | |
| 192 | static void qcom_link_stack_sanitization(void) |
| 193 | { |
| 194 | u64 tmp; |
| 195 | |
| 196 | asm volatile("mov %0, x30 \n" |
| 197 | ".rept 16 \n" |
| 198 | "bl . + 4 \n" |
| 199 | ".endr \n" |
| 200 | "mov x30, %0 \n" |
| 201 | : "=&r" (tmp)); |
| 202 | } |
| 203 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 204 | static bool __nospectre_v2; |
| 205 | static int __init parse_nospectre_v2(char *str) |
| 206 | { |
| 207 | __nospectre_v2 = true; |
| 208 | return 0; |
| 209 | } |
| 210 | early_param("nospectre_v2", parse_nospectre_v2); |
| 211 | |
| 212 | /* |
| 213 | * -1: No workaround |
| 214 | * 0: No workaround required |
| 215 | * 1: Workaround installed |
| 216 | */ |
| 217 | static int detect_harden_bp_fw(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 218 | { |
| 219 | bp_hardening_cb_t cb; |
| 220 | void *smccc_start, *smccc_end; |
| 221 | struct arm_smccc_res res; |
| 222 | u32 midr = read_cpuid_id(); |
| 223 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 224 | if (psci_ops.smccc_version == SMCCC_VERSION_1_0) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 225 | return -1; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 226 | |
| 227 | switch (psci_ops.conduit) { |
| 228 | case PSCI_CONDUIT_HVC: |
| 229 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 230 | ARM_SMCCC_ARCH_WORKAROUND_1, &res); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 231 | switch ((int)res.a0) { |
| 232 | case 1: |
| 233 | /* Firmware says we're just fine */ |
| 234 | return 0; |
| 235 | case 0: |
| 236 | cb = call_hvc_arch_workaround_1; |
| 237 | /* This is a guest, no need to patch KVM vectors */ |
| 238 | smccc_start = NULL; |
| 239 | smccc_end = NULL; |
| 240 | break; |
| 241 | default: |
| 242 | return -1; |
| 243 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 244 | break; |
| 245 | |
| 246 | case PSCI_CONDUIT_SMC: |
| 247 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 248 | ARM_SMCCC_ARCH_WORKAROUND_1, &res); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 249 | switch ((int)res.a0) { |
| 250 | case 1: |
| 251 | /* Firmware says we're just fine */ |
| 252 | return 0; |
| 253 | case 0: |
| 254 | cb = call_smc_arch_workaround_1; |
| 255 | smccc_start = __smccc_workaround_1_smc_start; |
| 256 | smccc_end = __smccc_workaround_1_smc_end; |
| 257 | break; |
| 258 | default: |
| 259 | return -1; |
| 260 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 261 | break; |
| 262 | |
| 263 | default: |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 264 | return -1; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) || |
| 268 | ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) |
| 269 | cb = qcom_link_stack_sanitization; |
| 270 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 271 | if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) |
| 272 | install_bp_hardening_cb(cb, smccc_start, smccc_end); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 273 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 274 | return 1; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 275 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 276 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 277 | DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required); |
| 278 | |
| 279 | int ssbd_state __read_mostly = ARM64_SSBD_KERNEL; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 280 | static bool __ssb_safe = true; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 281 | |
| 282 | static const struct ssbd_options { |
| 283 | const char *str; |
| 284 | int state; |
| 285 | } ssbd_options[] = { |
| 286 | { "force-on", ARM64_SSBD_FORCE_ENABLE, }, |
| 287 | { "force-off", ARM64_SSBD_FORCE_DISABLE, }, |
| 288 | { "kernel", ARM64_SSBD_KERNEL, }, |
| 289 | }; |
| 290 | |
| 291 | static int __init ssbd_cfg(char *buf) |
| 292 | { |
| 293 | int i; |
| 294 | |
| 295 | if (!buf || !buf[0]) |
| 296 | return -EINVAL; |
| 297 | |
| 298 | for (i = 0; i < ARRAY_SIZE(ssbd_options); i++) { |
| 299 | int len = strlen(ssbd_options[i].str); |
| 300 | |
| 301 | if (strncmp(buf, ssbd_options[i].str, len)) |
| 302 | continue; |
| 303 | |
| 304 | ssbd_state = ssbd_options[i].state; |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | return -EINVAL; |
| 309 | } |
| 310 | early_param("ssbd", ssbd_cfg); |
| 311 | |
| 312 | void __init arm64_update_smccc_conduit(struct alt_instr *alt, |
| 313 | __le32 *origptr, __le32 *updptr, |
| 314 | int nr_inst) |
| 315 | { |
| 316 | u32 insn; |
| 317 | |
| 318 | BUG_ON(nr_inst != 1); |
| 319 | |
| 320 | switch (psci_ops.conduit) { |
| 321 | case PSCI_CONDUIT_HVC: |
| 322 | insn = aarch64_insn_get_hvc_value(); |
| 323 | break; |
| 324 | case PSCI_CONDUIT_SMC: |
| 325 | insn = aarch64_insn_get_smc_value(); |
| 326 | break; |
| 327 | default: |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | *updptr = cpu_to_le32(insn); |
| 332 | } |
| 333 | |
| 334 | void __init arm64_enable_wa2_handling(struct alt_instr *alt, |
| 335 | __le32 *origptr, __le32 *updptr, |
| 336 | int nr_inst) |
| 337 | { |
| 338 | BUG_ON(nr_inst != 1); |
| 339 | /* |
| 340 | * Only allow mitigation on EL1 entry/exit and guest |
| 341 | * ARCH_WORKAROUND_2 handling if the SSBD state allows it to |
| 342 | * be flipped. |
| 343 | */ |
| 344 | if (arm64_get_ssbd_state() == ARM64_SSBD_KERNEL) |
| 345 | *updptr = cpu_to_le32(aarch64_insn_gen_nop()); |
| 346 | } |
| 347 | |
| 348 | void arm64_set_ssbd_mitigation(bool state) |
| 349 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 350 | if (!IS_ENABLED(CONFIG_ARM64_SSBD)) { |
| 351 | pr_info_once("SSBD disabled by kernel configuration\n"); |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | if (this_cpu_has_cap(ARM64_SSBS)) { |
| 356 | if (state) |
| 357 | asm volatile(SET_PSTATE_SSBS(0)); |
| 358 | else |
| 359 | asm volatile(SET_PSTATE_SSBS(1)); |
| 360 | return; |
| 361 | } |
| 362 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 363 | switch (psci_ops.conduit) { |
| 364 | case PSCI_CONDUIT_HVC: |
| 365 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL); |
| 366 | break; |
| 367 | |
| 368 | case PSCI_CONDUIT_SMC: |
| 369 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL); |
| 370 | break; |
| 371 | |
| 372 | default: |
| 373 | WARN_ON_ONCE(1); |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, |
| 379 | int scope) |
| 380 | { |
| 381 | struct arm_smccc_res res; |
| 382 | bool required = true; |
| 383 | s32 val; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 384 | bool this_cpu_safe = false; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 385 | |
| 386 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 387 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 388 | if (cpu_mitigations_off()) |
| 389 | ssbd_state = ARM64_SSBD_FORCE_DISABLE; |
| 390 | |
| 391 | /* delay setting __ssb_safe until we get a firmware response */ |
| 392 | if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list)) |
| 393 | this_cpu_safe = true; |
| 394 | |
| 395 | if (this_cpu_has_cap(ARM64_SSBS)) { |
| 396 | if (!this_cpu_safe) |
| 397 | __ssb_safe = false; |
| 398 | required = false; |
| 399 | goto out_printmsg; |
| 400 | } |
| 401 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 402 | if (psci_ops.smccc_version == SMCCC_VERSION_1_0) { |
| 403 | ssbd_state = ARM64_SSBD_UNKNOWN; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 404 | if (!this_cpu_safe) |
| 405 | __ssb_safe = false; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 406 | return false; |
| 407 | } |
| 408 | |
| 409 | switch (psci_ops.conduit) { |
| 410 | case PSCI_CONDUIT_HVC: |
| 411 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 412 | ARM_SMCCC_ARCH_WORKAROUND_2, &res); |
| 413 | break; |
| 414 | |
| 415 | case PSCI_CONDUIT_SMC: |
| 416 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 417 | ARM_SMCCC_ARCH_WORKAROUND_2, &res); |
| 418 | break; |
| 419 | |
| 420 | default: |
| 421 | ssbd_state = ARM64_SSBD_UNKNOWN; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 422 | if (!this_cpu_safe) |
| 423 | __ssb_safe = false; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 424 | return false; |
| 425 | } |
| 426 | |
| 427 | val = (s32)res.a0; |
| 428 | |
| 429 | switch (val) { |
| 430 | case SMCCC_RET_NOT_SUPPORTED: |
| 431 | ssbd_state = ARM64_SSBD_UNKNOWN; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 432 | if (!this_cpu_safe) |
| 433 | __ssb_safe = false; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 434 | return false; |
| 435 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 436 | /* machines with mixed mitigation requirements must not return this */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 437 | case SMCCC_RET_NOT_REQUIRED: |
| 438 | pr_info_once("%s mitigation not required\n", entry->desc); |
| 439 | ssbd_state = ARM64_SSBD_MITIGATED; |
| 440 | return false; |
| 441 | |
| 442 | case SMCCC_RET_SUCCESS: |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 443 | __ssb_safe = false; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 444 | required = true; |
| 445 | break; |
| 446 | |
| 447 | case 1: /* Mitigation not required on this CPU */ |
| 448 | required = false; |
| 449 | break; |
| 450 | |
| 451 | default: |
| 452 | WARN_ON(1); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 453 | if (!this_cpu_safe) |
| 454 | __ssb_safe = false; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 455 | return false; |
| 456 | } |
| 457 | |
| 458 | switch (ssbd_state) { |
| 459 | case ARM64_SSBD_FORCE_DISABLE: |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 460 | arm64_set_ssbd_mitigation(false); |
| 461 | required = false; |
| 462 | break; |
| 463 | |
| 464 | case ARM64_SSBD_KERNEL: |
| 465 | if (required) { |
| 466 | __this_cpu_write(arm64_ssbd_callback_required, 1); |
| 467 | arm64_set_ssbd_mitigation(true); |
| 468 | } |
| 469 | break; |
| 470 | |
| 471 | case ARM64_SSBD_FORCE_ENABLE: |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 472 | arm64_set_ssbd_mitigation(true); |
| 473 | required = true; |
| 474 | break; |
| 475 | |
| 476 | default: |
| 477 | WARN_ON(1); |
| 478 | break; |
| 479 | } |
| 480 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 481 | out_printmsg: |
| 482 | switch (ssbd_state) { |
| 483 | case ARM64_SSBD_FORCE_DISABLE: |
| 484 | pr_info_once("%s disabled from command-line\n", entry->desc); |
| 485 | break; |
| 486 | |
| 487 | case ARM64_SSBD_FORCE_ENABLE: |
| 488 | pr_info_once("%s forced from command-line\n", entry->desc); |
| 489 | break; |
| 490 | } |
| 491 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 492 | return required; |
| 493 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 494 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 495 | static void cpu_enable_ssbd_mitigation(const struct arm64_cpu_capabilities *cap) |
| 496 | { |
| 497 | if (ssbd_state != ARM64_SSBD_FORCE_DISABLE) |
| 498 | cap->matches(cap, SCOPE_LOCAL_CPU); |
| 499 | } |
| 500 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 501 | /* known invulnerable cores */ |
| 502 | static const struct midr_range arm64_ssb_cpus[] = { |
| 503 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 504 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 505 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
| 506 | MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53), |
| 507 | {}, |
| 508 | }; |
| 509 | |
| 510 | #ifdef CONFIG_ARM64_ERRATUM_1463225 |
| 511 | DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa); |
| 512 | |
| 513 | static bool |
| 514 | has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry, |
| 515 | int scope) |
| 516 | { |
| 517 | u32 midr = read_cpuid_id(); |
| 518 | /* Cortex-A76 r0p0 - r3p1 */ |
| 519 | struct midr_range range = MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1); |
| 520 | |
| 521 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 522 | return is_midr_in_range(midr, &range) && is_kernel_in_hyp_mode(); |
| 523 | } |
| 524 | #endif |
| 525 | |
| 526 | static void __maybe_unused |
| 527 | cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused) |
| 528 | { |
| 529 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCI, 0); |
| 530 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 531 | |
| 532 | #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ |
| 533 | .matches = is_affected_midr_range, \ |
| 534 | .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max) |
| 535 | |
| 536 | #define CAP_MIDR_ALL_VERSIONS(model) \ |
| 537 | .matches = is_affected_midr_range, \ |
| 538 | .midr_range = MIDR_ALL_VERSIONS(model) |
| 539 | |
| 540 | #define MIDR_FIXED(rev, revidr_mask) \ |
| 541 | .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}} |
| 542 | |
| 543 | #define ERRATA_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ |
| 544 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 545 | CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) |
| 546 | |
| 547 | #define CAP_MIDR_RANGE_LIST(list) \ |
| 548 | .matches = is_affected_midr_range_list, \ |
| 549 | .midr_range_list = list |
| 550 | |
| 551 | /* Errata affecting a range of revisions of given model variant */ |
| 552 | #define ERRATA_MIDR_REV_RANGE(m, var, r_min, r_max) \ |
| 553 | ERRATA_MIDR_RANGE(m, var, r_min, var, r_max) |
| 554 | |
| 555 | /* Errata affecting a single variant/revision of a model */ |
| 556 | #define ERRATA_MIDR_REV(model, var, rev) \ |
| 557 | ERRATA_MIDR_RANGE(model, var, rev, var, rev) |
| 558 | |
| 559 | /* Errata affecting all variants/revisions of a given a model */ |
| 560 | #define ERRATA_MIDR_ALL_VERSIONS(model) \ |
| 561 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 562 | CAP_MIDR_ALL_VERSIONS(model) |
| 563 | |
| 564 | /* Errata affecting a list of midr ranges, with same work around */ |
| 565 | #define ERRATA_MIDR_RANGE_LIST(midr_list) \ |
| 566 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 567 | CAP_MIDR_RANGE_LIST(midr_list) |
| 568 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 569 | /* Track overall mitigation state. We are only mitigated if all cores are ok */ |
| 570 | static bool __hardenbp_enab = true; |
| 571 | static bool __spectrev2_safe = true; |
| 572 | |
| 573 | int get_spectre_v2_workaround_state(void) |
| 574 | { |
| 575 | if (__spectrev2_safe) |
| 576 | return ARM64_BP_HARDEN_NOT_REQUIRED; |
| 577 | |
| 578 | if (!__hardenbp_enab) |
| 579 | return ARM64_BP_HARDEN_UNKNOWN; |
| 580 | |
| 581 | return ARM64_BP_HARDEN_WA_NEEDED; |
| 582 | } |
| 583 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 584 | /* |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 585 | * List of CPUs that do not need any Spectre-v2 mitigation at all. |
| 586 | */ |
| 587 | static const struct midr_range spectre_v2_safe_list[] = { |
| 588 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 589 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 590 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
| 591 | MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 592 | MIDR_ALL_VERSIONS(MIDR_HISI_TSV110), |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 593 | { /* sentinel */ } |
| 594 | }; |
| 595 | |
| 596 | /* |
| 597 | * Track overall bp hardening for all heterogeneous cores in the machine. |
| 598 | * We are only considered "safe" if all booted cores are known safe. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 599 | */ |
| 600 | static bool __maybe_unused |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 601 | check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 602 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 603 | int need_wa; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 604 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 605 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 606 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 607 | /* If the CPU has CSV2 set, we're safe */ |
| 608 | if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1), |
| 609 | ID_AA64PFR0_CSV2_SHIFT)) |
| 610 | return false; |
| 611 | |
| 612 | /* Alternatively, we have a list of unaffected CPUs */ |
| 613 | if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list)) |
| 614 | return false; |
| 615 | |
| 616 | /* Fallback to firmware detection */ |
| 617 | need_wa = detect_harden_bp_fw(); |
| 618 | if (!need_wa) |
| 619 | return false; |
| 620 | |
| 621 | __spectrev2_safe = false; |
| 622 | |
| 623 | if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) { |
| 624 | pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n"); |
| 625 | __hardenbp_enab = false; |
| 626 | return false; |
| 627 | } |
| 628 | |
| 629 | /* forced off */ |
| 630 | if (__nospectre_v2 || cpu_mitigations_off()) { |
| 631 | pr_info_once("spectrev2 mitigation disabled by command line option\n"); |
| 632 | __hardenbp_enab = false; |
| 633 | return false; |
| 634 | } |
| 635 | |
| 636 | if (need_wa < 0) { |
| 637 | pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n"); |
| 638 | __hardenbp_enab = false; |
| 639 | } |
| 640 | |
| 641 | return (need_wa > 0); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 644 | static void |
| 645 | cpu_enable_branch_predictor_hardening(const struct arm64_cpu_capabilities *cap) |
| 646 | { |
| 647 | cap->matches(cap, SCOPE_LOCAL_CPU); |
| 648 | } |
| 649 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 650 | static const __maybe_unused struct midr_range tx2_family_cpus[] = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 651 | MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), |
| 652 | MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 653 | {}, |
| 654 | }; |
| 655 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 656 | static bool __maybe_unused |
| 657 | needs_tx2_tvm_workaround(const struct arm64_cpu_capabilities *entry, |
| 658 | int scope) |
| 659 | { |
| 660 | int i; |
| 661 | |
| 662 | if (!is_affected_midr_range_list(entry, scope) || |
| 663 | !is_hyp_mode_available()) |
| 664 | return false; |
| 665 | |
| 666 | for_each_possible_cpu(i) { |
| 667 | if (MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 0) != 0) |
| 668 | return true; |
| 669 | } |
| 670 | |
| 671 | return false; |
| 672 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 673 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 674 | static bool __maybe_unused |
| 675 | has_neoverse_n1_erratum_1542419(const struct arm64_cpu_capabilities *entry, |
| 676 | int scope) |
| 677 | { |
| 678 | u32 midr = read_cpuid_id(); |
| 679 | bool has_dic = read_cpuid_cachetype() & BIT(CTR_DIC_SHIFT); |
| 680 | const struct midr_range range = MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1); |
| 681 | |
| 682 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 683 | return is_midr_in_range(midr, &range) && has_dic; |
| 684 | } |
| 685 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 686 | #ifdef CONFIG_HARDEN_EL2_VECTORS |
| 687 | |
| 688 | static const struct midr_range arm64_harden_el2_vectors[] = { |
| 689 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), |
| 690 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), |
| 691 | {}, |
| 692 | }; |
| 693 | |
| 694 | #endif |
| 695 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 696 | #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI |
| 697 | static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = { |
| 698 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009 |
| 699 | { |
| 700 | ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0) |
| 701 | }, |
| 702 | { |
| 703 | .midr_range.model = MIDR_QCOM_KRYO, |
| 704 | .matches = is_kryo_midr, |
| 705 | }, |
| 706 | #endif |
| 707 | #ifdef CONFIG_ARM64_ERRATUM_1286807 |
| 708 | { |
| 709 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 0), |
| 710 | }, |
| 711 | #endif |
| 712 | {}, |
| 713 | }; |
| 714 | #endif |
| 715 | |
| 716 | #ifdef CONFIG_CAVIUM_ERRATUM_27456 |
| 717 | const struct midr_range cavium_erratum_27456_cpus[] = { |
| 718 | /* Cavium ThunderX, T88 pass 1.x - 2.1 */ |
| 719 | MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 1), |
| 720 | /* Cavium ThunderX, T81 pass 1.0 */ |
| 721 | MIDR_REV(MIDR_THUNDERX_81XX, 0, 0), |
| 722 | {}, |
| 723 | }; |
| 724 | #endif |
| 725 | |
| 726 | #ifdef CONFIG_CAVIUM_ERRATUM_30115 |
| 727 | static const struct midr_range cavium_erratum_30115_cpus[] = { |
| 728 | /* Cavium ThunderX, T88 pass 1.x - 2.2 */ |
| 729 | MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 2), |
| 730 | /* Cavium ThunderX, T81 pass 1.0 - 1.2 */ |
| 731 | MIDR_REV_RANGE(MIDR_THUNDERX_81XX, 0, 0, 2), |
| 732 | /* Cavium ThunderX, T83 pass 1.0 */ |
| 733 | MIDR_REV(MIDR_THUNDERX_83XX, 0, 0), |
| 734 | {}, |
| 735 | }; |
| 736 | #endif |
| 737 | |
| 738 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 |
| 739 | static const struct arm64_cpu_capabilities qcom_erratum_1003_list[] = { |
| 740 | { |
| 741 | ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0), |
| 742 | }, |
| 743 | { |
| 744 | .midr_range.model = MIDR_QCOM_KRYO, |
| 745 | .matches = is_kryo_midr, |
| 746 | }, |
| 747 | {}, |
| 748 | }; |
| 749 | #endif |
| 750 | |
| 751 | #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE |
| 752 | static const struct midr_range workaround_clean_cache[] = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 753 | #if defined(CONFIG_ARM64_ERRATUM_826319) || \ |
| 754 | defined(CONFIG_ARM64_ERRATUM_827319) || \ |
| 755 | defined(CONFIG_ARM64_ERRATUM_824069) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 756 | /* Cortex-A53 r0p[012]: ARM errata 826319, 827319, 824069 */ |
| 757 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 2), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 758 | #endif |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 759 | #ifdef CONFIG_ARM64_ERRATUM_819472 |
| 760 | /* Cortex-A53 r0p[01] : ARM errata 819472 */ |
| 761 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1), |
| 762 | #endif |
| 763 | {}, |
| 764 | }; |
| 765 | #endif |
| 766 | |
| 767 | #ifdef CONFIG_ARM64_ERRATUM_1418040 |
| 768 | /* |
| 769 | * - 1188873 affects r0p0 to r2p0 |
| 770 | * - 1418040 affects r0p0 to r3p1 |
| 771 | */ |
| 772 | static const struct midr_range erratum_1418040_list[] = { |
| 773 | /* Cortex-A76 r0p0 to r3p1 */ |
| 774 | MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1), |
| 775 | /* Neoverse-N1 r0p0 to r3p1 */ |
| 776 | MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 0, 3, 1), |
| 777 | {}, |
| 778 | }; |
| 779 | #endif |
| 780 | |
| 781 | #ifdef CONFIG_ARM64_ERRATUM_845719 |
| 782 | static const struct midr_range erratum_845719_list[] = { |
| 783 | /* Cortex-A53 r0p[01234] */ |
| 784 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4), |
| 785 | /* Brahma-B53 r0p[0] */ |
| 786 | MIDR_REV(MIDR_BRAHMA_B53, 0, 0), |
| 787 | {}, |
| 788 | }; |
| 789 | #endif |
| 790 | |
| 791 | #ifdef CONFIG_ARM64_ERRATUM_843419 |
| 792 | static const struct arm64_cpu_capabilities erratum_843419_list[] = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 793 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 794 | /* Cortex-A53 r0p[01234] */ |
| 795 | .matches = is_affected_midr_range, |
| 796 | ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4), |
| 797 | MIDR_FIXED(0x4, BIT(8)), |
| 798 | }, |
| 799 | { |
| 800 | /* Brahma-B53 r0p[0] */ |
| 801 | .matches = is_affected_midr_range, |
| 802 | ERRATA_MIDR_REV(MIDR_BRAHMA_B53, 0, 0), |
| 803 | }, |
| 804 | {}, |
| 805 | }; |
| 806 | #endif |
| 807 | |
| 808 | const struct arm64_cpu_capabilities arm64_errata[] = { |
| 809 | #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE |
| 810 | { |
| 811 | .desc = "ARM errata 826319, 827319, 824069, 819472", |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 812 | .capability = ARM64_WORKAROUND_CLEAN_CACHE, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 813 | ERRATA_MIDR_RANGE_LIST(workaround_clean_cache), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 814 | .cpu_enable = cpu_enable_cache_maint_trap, |
| 815 | }, |
| 816 | #endif |
| 817 | #ifdef CONFIG_ARM64_ERRATUM_832075 |
| 818 | { |
| 819 | /* Cortex-A57 r0p0 - r1p2 */ |
| 820 | .desc = "ARM erratum 832075", |
| 821 | .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE, |
| 822 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A57, |
| 823 | 0, 0, |
| 824 | 1, 2), |
| 825 | }, |
| 826 | #endif |
| 827 | #ifdef CONFIG_ARM64_ERRATUM_834220 |
| 828 | { |
| 829 | /* Cortex-A57 r0p0 - r1p2 */ |
| 830 | .desc = "ARM erratum 834220", |
| 831 | .capability = ARM64_WORKAROUND_834220, |
| 832 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A57, |
| 833 | 0, 0, |
| 834 | 1, 2), |
| 835 | }, |
| 836 | #endif |
| 837 | #ifdef CONFIG_ARM64_ERRATUM_843419 |
| 838 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 839 | .desc = "ARM erratum 843419", |
| 840 | .capability = ARM64_WORKAROUND_843419, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 841 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 842 | .matches = cpucap_multi_entry_cap_matches, |
| 843 | .match_list = erratum_843419_list, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 844 | }, |
| 845 | #endif |
| 846 | #ifdef CONFIG_ARM64_ERRATUM_845719 |
| 847 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 848 | .desc = "ARM erratum 845719", |
| 849 | .capability = ARM64_WORKAROUND_845719, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 850 | ERRATA_MIDR_RANGE_LIST(erratum_845719_list), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 851 | }, |
| 852 | #endif |
| 853 | #ifdef CONFIG_CAVIUM_ERRATUM_23154 |
| 854 | { |
| 855 | /* Cavium ThunderX, pass 1.x */ |
| 856 | .desc = "Cavium erratum 23154", |
| 857 | .capability = ARM64_WORKAROUND_CAVIUM_23154, |
| 858 | ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1), |
| 859 | }, |
| 860 | #endif |
| 861 | #ifdef CONFIG_CAVIUM_ERRATUM_27456 |
| 862 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 863 | .desc = "Cavium erratum 27456", |
| 864 | .capability = ARM64_WORKAROUND_CAVIUM_27456, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 865 | ERRATA_MIDR_RANGE_LIST(cavium_erratum_27456_cpus), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 866 | }, |
| 867 | #endif |
| 868 | #ifdef CONFIG_CAVIUM_ERRATUM_30115 |
| 869 | { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 870 | .desc = "Cavium erratum 30115", |
| 871 | .capability = ARM64_WORKAROUND_CAVIUM_30115, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 872 | ERRATA_MIDR_RANGE_LIST(cavium_erratum_30115_cpus), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 873 | }, |
| 874 | #endif |
| 875 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 876 | .desc = "Mismatched cache type (CTR_EL0)", |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 877 | .capability = ARM64_MISMATCHED_CACHE_TYPE, |
| 878 | .matches = has_mismatched_cache_type, |
| 879 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 880 | .cpu_enable = cpu_enable_trap_ctr_access, |
| 881 | }, |
| 882 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 |
| 883 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 884 | .desc = "Qualcomm Technologies Falkor/Kryo erratum 1003", |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 885 | .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003, |
| 886 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 887 | .matches = cpucap_multi_entry_cap_matches, |
| 888 | .match_list = qcom_erratum_1003_list, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 889 | }, |
| 890 | #endif |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 891 | #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 892 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 893 | .desc = "Qualcomm erratum 1009, ARM erratum 1286807", |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 894 | .capability = ARM64_WORKAROUND_REPEAT_TLBI, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 895 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 896 | .matches = cpucap_multi_entry_cap_matches, |
| 897 | .match_list = arm64_repeat_tlbi_list, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 898 | }, |
| 899 | #endif |
| 900 | #ifdef CONFIG_ARM64_ERRATUM_858921 |
| 901 | { |
| 902 | /* Cortex-A73 all versions */ |
| 903 | .desc = "ARM erratum 858921", |
| 904 | .capability = ARM64_WORKAROUND_858921, |
| 905 | ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), |
| 906 | }, |
| 907 | #endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 908 | { |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 909 | .desc = "Branch predictor hardening", |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 910 | .capability = ARM64_HARDEN_BRANCH_PREDICTOR, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 911 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 912 | .matches = check_branch_predictor, |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 913 | .cpu_enable = cpu_enable_branch_predictor_hardening, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 914 | }, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 915 | #ifdef CONFIG_HARDEN_EL2_VECTORS |
| 916 | { |
| 917 | .desc = "EL2 vector hardening", |
| 918 | .capability = ARM64_HARDEN_EL2_VECTORS, |
| 919 | ERRATA_MIDR_RANGE_LIST(arm64_harden_el2_vectors), |
| 920 | }, |
| 921 | #endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 922 | { |
| 923 | .desc = "Speculative Store Bypass Disable", |
| 924 | .capability = ARM64_SSBD, |
| 925 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 926 | .matches = has_ssbd_mitigation, |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 927 | .cpu_enable = cpu_enable_ssbd_mitigation, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 928 | .midr_range_list = arm64_ssb_cpus, |
| 929 | }, |
| 930 | #ifdef CONFIG_ARM64_ERRATUM_1418040 |
| 931 | { |
| 932 | .desc = "ARM erratum 1418040", |
| 933 | .capability = ARM64_WORKAROUND_1418040, |
| 934 | ERRATA_MIDR_RANGE_LIST(erratum_1418040_list), |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 935 | /* |
| 936 | * We need to allow affected CPUs to come in late, but |
| 937 | * also need the non-affected CPUs to be able to come |
| 938 | * in at any point in time. Wonderful. |
| 939 | */ |
| 940 | .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 941 | }, |
| 942 | #endif |
| 943 | #ifdef CONFIG_ARM64_ERRATUM_1165522 |
| 944 | { |
| 945 | /* Cortex-A76 r0p0 to r2p0 */ |
| 946 | .desc = "ARM erratum 1165522", |
| 947 | .capability = ARM64_WORKAROUND_1165522, |
| 948 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 2, 0), |
| 949 | }, |
| 950 | #endif |
| 951 | #ifdef CONFIG_ARM64_ERRATUM_1463225 |
| 952 | { |
| 953 | .desc = "ARM erratum 1463225", |
| 954 | .capability = ARM64_WORKAROUND_1463225, |
| 955 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 956 | .matches = has_cortex_a76_erratum_1463225, |
| 957 | }, |
| 958 | #endif |
| 959 | #ifdef CONFIG_CAVIUM_TX2_ERRATUM_219 |
| 960 | { |
| 961 | .desc = "Cavium ThunderX2 erratum 219 (KVM guest sysreg trapping)", |
| 962 | .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_TVM, |
| 963 | ERRATA_MIDR_RANGE_LIST(tx2_family_cpus), |
| 964 | .matches = needs_tx2_tvm_workaround, |
| 965 | }, |
| 966 | { |
| 967 | .desc = "Cavium ThunderX2 erratum 219 (PRFM removal)", |
| 968 | .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM, |
| 969 | ERRATA_MIDR_RANGE_LIST(tx2_family_cpus), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 970 | }, |
| 971 | #endif |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 972 | #ifdef CONFIG_ARM64_ERRATUM_1542419 |
| 973 | { |
| 974 | /* we depend on the firmware portion for correctness */ |
| 975 | .desc = "ARM erratum 1542419 (kernel portion)", |
| 976 | .capability = ARM64_WORKAROUND_1542419, |
| 977 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 978 | .matches = has_neoverse_n1_erratum_1542419, |
| 979 | .cpu_enable = cpu_enable_trap_ctr_access, |
| 980 | }, |
| 981 | #endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 982 | { |
| 983 | } |
| 984 | }; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 985 | |
| 986 | ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, |
| 987 | char *buf) |
| 988 | { |
| 989 | return sprintf(buf, "Mitigation: __user pointer sanitization\n"); |
| 990 | } |
| 991 | |
| 992 | ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, |
| 993 | char *buf) |
| 994 | { |
| 995 | switch (get_spectre_v2_workaround_state()) { |
| 996 | case ARM64_BP_HARDEN_NOT_REQUIRED: |
| 997 | return sprintf(buf, "Not affected\n"); |
| 998 | case ARM64_BP_HARDEN_WA_NEEDED: |
| 999 | return sprintf(buf, "Mitigation: Branch predictor hardening\n"); |
| 1000 | case ARM64_BP_HARDEN_UNKNOWN: |
| 1001 | default: |
| 1002 | return sprintf(buf, "Vulnerable\n"); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | ssize_t cpu_show_spec_store_bypass(struct device *dev, |
| 1007 | struct device_attribute *attr, char *buf) |
| 1008 | { |
| 1009 | if (__ssb_safe) |
| 1010 | return sprintf(buf, "Not affected\n"); |
| 1011 | |
| 1012 | switch (ssbd_state) { |
| 1013 | case ARM64_SSBD_KERNEL: |
| 1014 | case ARM64_SSBD_FORCE_ENABLE: |
| 1015 | if (IS_ENABLED(CONFIG_ARM64_SSBD)) |
| 1016 | return sprintf(buf, |
| 1017 | "Mitigation: Speculative Store Bypass disabled via prctl\n"); |
| 1018 | } |
| 1019 | |
| 1020 | return sprintf(buf, "Vulnerable\n"); |
| 1021 | } |