cpu_errata.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*
  2. * Contains CPU specific errata definitions
  3. *
  4. * Copyright (C) 2014 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/arm-smccc.h>
  19. #include <linux/psci.h>
  20. #include <linux/types.h>
  21. #include <linux/cpu.h>
  22. #include <asm/cpu.h>
  23. #include <asm/cputype.h>
  24. #include <asm/cpufeature.h>
  25. static bool __maybe_unused
  26. is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope)
  27. {
  28. u32 midr = read_cpuid_id();
  29. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  30. return is_midr_in_range(midr, &entry->midr_range);
  31. }
  32. static bool __maybe_unused
  33. is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry,
  34. int scope)
  35. {
  36. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  37. return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list);
  38. }
  39. static bool __maybe_unused
  40. is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope)
  41. {
  42. u32 model;
  43. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  44. model = read_cpuid_id();
  45. model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) |
  46. MIDR_ARCHITECTURE_MASK;
  47. return model == entry->midr_range.model;
  48. }
  49. static bool
  50. has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry,
  51. int scope)
  52. {
  53. u64 mask = CTR_CACHE_MINLINE_MASK;
  54. /* Skip matching the min line sizes for cache type check */
  55. if (entry->capability == ARM64_MISMATCHED_CACHE_TYPE)
  56. mask ^= arm64_ftr_reg_ctrel0.strict_mask;
  57. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  58. return (read_cpuid_cachetype() & mask) !=
  59. (arm64_ftr_reg_ctrel0.sys_val & mask);
  60. }
  61. static void
  62. cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *__unused)
  63. {
  64. /* Clear SCTLR_EL1.UCT */
  65. config_sctlr_el1(SCTLR_EL1_UCT, 0);
  66. }
  67. #include <asm/mmu_context.h>
  68. #include <asm/cacheflush.h>
  69. DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
  70. #ifdef CONFIG_KVM
  71. extern char __smccc_workaround_1_smc_start[];
  72. extern char __smccc_workaround_1_smc_end[];
  73. static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start,
  74. const char *hyp_vecs_end)
  75. {
  76. void *dst = lm_alias(__bp_harden_hyp_vecs_start + slot * SZ_2K);
  77. int i;
  78. for (i = 0; i < SZ_2K; i += 0x80)
  79. memcpy(dst + i, hyp_vecs_start, hyp_vecs_end - hyp_vecs_start);
  80. flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K);
  81. }
  82. static void install_bp_hardening_cb(bp_hardening_cb_t fn,
  83. const char *hyp_vecs_start,
  84. const char *hyp_vecs_end)
  85. {
  86. static int last_slot = -1;
  87. static DEFINE_SPINLOCK(bp_lock);
  88. int cpu, slot = -1;
  89. spin_lock(&bp_lock);
  90. for_each_possible_cpu(cpu) {
  91. if (per_cpu(bp_hardening_data.fn, cpu) == fn) {
  92. slot = per_cpu(bp_hardening_data.hyp_vectors_slot, cpu);
  93. break;
  94. }
  95. }
  96. if (slot == -1) {
  97. last_slot++;
  98. BUG_ON(((__bp_harden_hyp_vecs_end - __bp_harden_hyp_vecs_start)
  99. / SZ_2K) <= last_slot);
  100. slot = last_slot;
  101. __copy_hyp_vect_bpi(slot, hyp_vecs_start, hyp_vecs_end);
  102. }
  103. __this_cpu_write(bp_hardening_data.hyp_vectors_slot, slot);
  104. __this_cpu_write(bp_hardening_data.fn, fn);
  105. spin_unlock(&bp_lock);
  106. }
  107. #else
  108. #define __smccc_workaround_1_smc_start NULL
  109. #define __smccc_workaround_1_smc_end NULL
  110. static void install_bp_hardening_cb(bp_hardening_cb_t fn,
  111. const char *hyp_vecs_start,
  112. const char *hyp_vecs_end)
  113. {
  114. __this_cpu_write(bp_hardening_data.fn, fn);
  115. }
  116. #endif /* CONFIG_KVM */
  117. #include <uapi/linux/psci.h>
  118. #include <linux/arm-smccc.h>
  119. #include <linux/psci.h>
  120. static void call_smc_arch_workaround_1(void)
  121. {
  122. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL);
  123. }
  124. static void call_hvc_arch_workaround_1(void)
  125. {
  126. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL);
  127. }
  128. static void qcom_link_stack_sanitization(void)
  129. {
  130. u64 tmp;
  131. asm volatile("mov %0, x30 \n"
  132. ".rept 16 \n"
  133. "bl . + 4 \n"
  134. ".endr \n"
  135. "mov x30, %0 \n"
  136. : "=&r" (tmp));
  137. }
  138. static bool __nospectre_v2;
  139. static int __init parse_nospectre_v2(char *str)
  140. {
  141. __nospectre_v2 = true;
  142. return 0;
  143. }
  144. early_param("nospectre_v2", parse_nospectre_v2);
  145. /*
  146. * -1: No workaround
  147. * 0: No workaround required
  148. * 1: Workaround installed
  149. */
  150. static int detect_harden_bp_fw(void)
  151. {
  152. bp_hardening_cb_t cb;
  153. void *smccc_start, *smccc_end;
  154. struct arm_smccc_res res;
  155. u32 midr = read_cpuid_id();
  156. if (psci_ops.smccc_version == SMCCC_VERSION_1_0)
  157. return -1;
  158. switch (psci_ops.conduit) {
  159. case PSCI_CONDUIT_HVC:
  160. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  161. ARM_SMCCC_ARCH_WORKAROUND_1, &res);
  162. switch ((int)res.a0) {
  163. case 1:
  164. /* Firmware says we're just fine */
  165. return 0;
  166. case 0:
  167. cb = call_hvc_arch_workaround_1;
  168. /* This is a guest, no need to patch KVM vectors */
  169. smccc_start = NULL;
  170. smccc_end = NULL;
  171. break;
  172. default:
  173. return -1;
  174. }
  175. break;
  176. case PSCI_CONDUIT_SMC:
  177. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  178. ARM_SMCCC_ARCH_WORKAROUND_1, &res);
  179. switch ((int)res.a0) {
  180. case 1:
  181. /* Firmware says we're just fine */
  182. return 0;
  183. case 0:
  184. cb = call_smc_arch_workaround_1;
  185. smccc_start = __smccc_workaround_1_smc_start;
  186. smccc_end = __smccc_workaround_1_smc_end;
  187. break;
  188. default:
  189. return -1;
  190. }
  191. break;
  192. default:
  193. return -1;
  194. }
  195. if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) ||
  196. ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1))
  197. cb = qcom_link_stack_sanitization;
  198. if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR))
  199. install_bp_hardening_cb(cb, smccc_start, smccc_end);
  200. return 1;
  201. }
  202. DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required);
  203. int ssbd_state __read_mostly = ARM64_SSBD_KERNEL;
  204. static bool __ssb_safe = true;
  205. static const struct ssbd_options {
  206. const char *str;
  207. int state;
  208. } ssbd_options[] = {
  209. { "force-on", ARM64_SSBD_FORCE_ENABLE, },
  210. { "force-off", ARM64_SSBD_FORCE_DISABLE, },
  211. { "kernel", ARM64_SSBD_KERNEL, },
  212. };
  213. static int __init ssbd_cfg(char *buf)
  214. {
  215. int i;
  216. if (!buf || !buf[0])
  217. return -EINVAL;
  218. for (i = 0; i < ARRAY_SIZE(ssbd_options); i++) {
  219. int len = strlen(ssbd_options[i].str);
  220. if (strncmp(buf, ssbd_options[i].str, len))
  221. continue;
  222. ssbd_state = ssbd_options[i].state;
  223. return 0;
  224. }
  225. return -EINVAL;
  226. }
  227. early_param("ssbd", ssbd_cfg);
  228. void __init arm64_update_smccc_conduit(struct alt_instr *alt,
  229. __le32 *origptr, __le32 *updptr,
  230. int nr_inst)
  231. {
  232. u32 insn;
  233. BUG_ON(nr_inst != 1);
  234. switch (psci_ops.conduit) {
  235. case PSCI_CONDUIT_HVC:
  236. insn = aarch64_insn_get_hvc_value();
  237. break;
  238. case PSCI_CONDUIT_SMC:
  239. insn = aarch64_insn_get_smc_value();
  240. break;
  241. default:
  242. return;
  243. }
  244. *updptr = cpu_to_le32(insn);
  245. }
  246. void __init arm64_enable_wa2_handling(struct alt_instr *alt,
  247. __le32 *origptr, __le32 *updptr,
  248. int nr_inst)
  249. {
  250. BUG_ON(nr_inst != 1);
  251. /*
  252. * Only allow mitigation on EL1 entry/exit and guest
  253. * ARCH_WORKAROUND_2 handling if the SSBD state allows it to
  254. * be flipped.
  255. */
  256. if (arm64_get_ssbd_state() == ARM64_SSBD_KERNEL)
  257. *updptr = cpu_to_le32(aarch64_insn_gen_nop());
  258. }
  259. void arm64_set_ssbd_mitigation(bool state)
  260. {
  261. if (!IS_ENABLED(CONFIG_ARM64_SSBD)) {
  262. pr_info_once("SSBD disabled by kernel configuration\n");
  263. return;
  264. }
  265. if (this_cpu_has_cap(ARM64_SSBS)) {
  266. if (state)
  267. asm volatile(SET_PSTATE_SSBS(0));
  268. else
  269. asm volatile(SET_PSTATE_SSBS(1));
  270. return;
  271. }
  272. switch (psci_ops.conduit) {
  273. case PSCI_CONDUIT_HVC:
  274. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL);
  275. break;
  276. case PSCI_CONDUIT_SMC:
  277. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL);
  278. break;
  279. default:
  280. WARN_ON_ONCE(1);
  281. break;
  282. }
  283. }
  284. static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry,
  285. int scope)
  286. {
  287. struct arm_smccc_res res;
  288. bool required = true;
  289. s32 val;
  290. bool this_cpu_safe = false;
  291. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  292. if (cpu_mitigations_off())
  293. ssbd_state = ARM64_SSBD_FORCE_DISABLE;
  294. /* delay setting __ssb_safe until we get a firmware response */
  295. if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list))
  296. this_cpu_safe = true;
  297. if (this_cpu_has_cap(ARM64_SSBS)) {
  298. if (!this_cpu_safe)
  299. __ssb_safe = false;
  300. required = false;
  301. goto out_printmsg;
  302. }
  303. if (psci_ops.smccc_version == SMCCC_VERSION_1_0) {
  304. ssbd_state = ARM64_SSBD_UNKNOWN;
  305. if (!this_cpu_safe)
  306. __ssb_safe = false;
  307. return false;
  308. }
  309. switch (psci_ops.conduit) {
  310. case PSCI_CONDUIT_HVC:
  311. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  312. ARM_SMCCC_ARCH_WORKAROUND_2, &res);
  313. break;
  314. case PSCI_CONDUIT_SMC:
  315. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  316. ARM_SMCCC_ARCH_WORKAROUND_2, &res);
  317. break;
  318. default:
  319. ssbd_state = ARM64_SSBD_UNKNOWN;
  320. if (!this_cpu_safe)
  321. __ssb_safe = false;
  322. return false;
  323. }
  324. val = (s32)res.a0;
  325. switch (val) {
  326. case SMCCC_RET_NOT_SUPPORTED:
  327. ssbd_state = ARM64_SSBD_UNKNOWN;
  328. if (!this_cpu_safe)
  329. __ssb_safe = false;
  330. return false;
  331. /* machines with mixed mitigation requirements must not return this */
  332. case SMCCC_RET_NOT_REQUIRED:
  333. pr_info_once("%s mitigation not required\n", entry->desc);
  334. ssbd_state = ARM64_SSBD_MITIGATED;
  335. return false;
  336. case SMCCC_RET_SUCCESS:
  337. __ssb_safe = false;
  338. required = true;
  339. break;
  340. case 1: /* Mitigation not required on this CPU */
  341. required = false;
  342. break;
  343. default:
  344. WARN_ON(1);
  345. if (!this_cpu_safe)
  346. __ssb_safe = false;
  347. return false;
  348. }
  349. switch (ssbd_state) {
  350. case ARM64_SSBD_FORCE_DISABLE:
  351. arm64_set_ssbd_mitigation(false);
  352. required = false;
  353. break;
  354. case ARM64_SSBD_KERNEL:
  355. if (required) {
  356. __this_cpu_write(arm64_ssbd_callback_required, 1);
  357. arm64_set_ssbd_mitigation(true);
  358. }
  359. break;
  360. case ARM64_SSBD_FORCE_ENABLE:
  361. arm64_set_ssbd_mitigation(true);
  362. required = true;
  363. break;
  364. default:
  365. WARN_ON(1);
  366. break;
  367. }
  368. out_printmsg:
  369. switch (ssbd_state) {
  370. case ARM64_SSBD_FORCE_DISABLE:
  371. pr_info_once("%s disabled from command-line\n", entry->desc);
  372. break;
  373. case ARM64_SSBD_FORCE_ENABLE:
  374. pr_info_once("%s forced from command-line\n", entry->desc);
  375. break;
  376. }
  377. return required;
  378. }
  379. /* known invulnerable cores */
  380. static const struct midr_range arm64_ssb_cpus[] = {
  381. MIDR_ALL_VERSIONS(MIDR_CORTEX_A35),
  382. MIDR_ALL_VERSIONS(MIDR_CORTEX_A53),
  383. MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
  384. {},
  385. };
  386. #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
  387. .matches = is_affected_midr_range, \
  388. .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max)
  389. #define CAP_MIDR_ALL_VERSIONS(model) \
  390. .matches = is_affected_midr_range, \
  391. .midr_range = MIDR_ALL_VERSIONS(model)
  392. #define MIDR_FIXED(rev, revidr_mask) \
  393. .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}}
  394. #define ERRATA_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
  395. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
  396. CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max)
  397. #define CAP_MIDR_RANGE_LIST(list) \
  398. .matches = is_affected_midr_range_list, \
  399. .midr_range_list = list
  400. /* Errata affecting a range of revisions of given model variant */
  401. #define ERRATA_MIDR_REV_RANGE(m, var, r_min, r_max) \
  402. ERRATA_MIDR_RANGE(m, var, r_min, var, r_max)
  403. /* Errata affecting a single variant/revision of a model */
  404. #define ERRATA_MIDR_REV(model, var, rev) \
  405. ERRATA_MIDR_RANGE(model, var, rev, var, rev)
  406. /* Errata affecting all variants/revisions of a given a model */
  407. #define ERRATA_MIDR_ALL_VERSIONS(model) \
  408. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
  409. CAP_MIDR_ALL_VERSIONS(model)
  410. /* Errata affecting a list of midr ranges, with same work around */
  411. #define ERRATA_MIDR_RANGE_LIST(midr_list) \
  412. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
  413. CAP_MIDR_RANGE_LIST(midr_list)
  414. /* Track overall mitigation state. We are only mitigated if all cores are ok */
  415. static bool __hardenbp_enab = true;
  416. static bool __spectrev2_safe = true;
  417. /*
  418. * List of CPUs that do not need any Spectre-v2 mitigation at all.
  419. */
  420. static const struct midr_range spectre_v2_safe_list[] = {
  421. MIDR_ALL_VERSIONS(MIDR_CORTEX_A35),
  422. MIDR_ALL_VERSIONS(MIDR_CORTEX_A53),
  423. MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
  424. { /* sentinel */ }
  425. };
  426. /*
  427. * Track overall bp hardening for all heterogeneous cores in the machine.
  428. * We are only considered "safe" if all booted cores are known safe.
  429. */
  430. static bool __maybe_unused
  431. check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope)
  432. {
  433. int need_wa;
  434. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  435. /* If the CPU has CSV2 set, we're safe */
  436. if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1),
  437. ID_AA64PFR0_CSV2_SHIFT))
  438. return false;
  439. /* Alternatively, we have a list of unaffected CPUs */
  440. if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list))
  441. return false;
  442. /* Fallback to firmware detection */
  443. need_wa = detect_harden_bp_fw();
  444. if (!need_wa)
  445. return false;
  446. __spectrev2_safe = false;
  447. if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) {
  448. pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n");
  449. __hardenbp_enab = false;
  450. return false;
  451. }
  452. /* forced off */
  453. if (__nospectre_v2 || cpu_mitigations_off()) {
  454. pr_info_once("spectrev2 mitigation disabled by command line option\n");
  455. __hardenbp_enab = false;
  456. return false;
  457. }
  458. if (need_wa < 0) {
  459. pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n");
  460. __hardenbp_enab = false;
  461. }
  462. return (need_wa > 0);
  463. }
  464. const struct arm64_cpu_capabilities arm64_errata[] = {
  465. #if defined(CONFIG_ARM64_ERRATUM_826319) || \
  466. defined(CONFIG_ARM64_ERRATUM_827319) || \
  467. defined(CONFIG_ARM64_ERRATUM_824069)
  468. {
  469. /* Cortex-A53 r0p[012] */
  470. .desc = "ARM errata 826319, 827319, 824069",
  471. .capability = ARM64_WORKAROUND_CLEAN_CACHE,
  472. ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 2),
  473. .cpu_enable = cpu_enable_cache_maint_trap,
  474. },
  475. #endif
  476. #ifdef CONFIG_ARM64_ERRATUM_819472
  477. {
  478. /* Cortex-A53 r0p[01] */
  479. .desc = "ARM errata 819472",
  480. .capability = ARM64_WORKAROUND_CLEAN_CACHE,
  481. ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1),
  482. .cpu_enable = cpu_enable_cache_maint_trap,
  483. },
  484. #endif
  485. #ifdef CONFIG_ARM64_ERRATUM_832075
  486. {
  487. /* Cortex-A57 r0p0 - r1p2 */
  488. .desc = "ARM erratum 832075",
  489. .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
  490. ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
  491. 0, 0,
  492. 1, 2),
  493. },
  494. #endif
  495. #ifdef CONFIG_ARM64_ERRATUM_834220
  496. {
  497. /* Cortex-A57 r0p0 - r1p2 */
  498. .desc = "ARM erratum 834220",
  499. .capability = ARM64_WORKAROUND_834220,
  500. ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
  501. 0, 0,
  502. 1, 2),
  503. },
  504. #endif
  505. #ifdef CONFIG_ARM64_ERRATUM_845719
  506. {
  507. /* Cortex-A53 r0p[01234] */
  508. .desc = "ARM erratum 845719",
  509. .capability = ARM64_WORKAROUND_845719,
  510. ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
  511. },
  512. #endif
  513. #ifdef CONFIG_CAVIUM_ERRATUM_23154
  514. {
  515. /* Cavium ThunderX, pass 1.x */
  516. .desc = "Cavium erratum 23154",
  517. .capability = ARM64_WORKAROUND_CAVIUM_23154,
  518. ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1),
  519. },
  520. #endif
  521. #ifdef CONFIG_CAVIUM_ERRATUM_27456
  522. {
  523. /* Cavium ThunderX, T88 pass 1.x - 2.1 */
  524. .desc = "Cavium erratum 27456",
  525. .capability = ARM64_WORKAROUND_CAVIUM_27456,
  526. ERRATA_MIDR_RANGE(MIDR_THUNDERX,
  527. 0, 0,
  528. 1, 1),
  529. },
  530. {
  531. /* Cavium ThunderX, T81 pass 1.0 */
  532. .desc = "Cavium erratum 27456",
  533. .capability = ARM64_WORKAROUND_CAVIUM_27456,
  534. ERRATA_MIDR_REV(MIDR_THUNDERX_81XX, 0, 0),
  535. },
  536. #endif
  537. #ifdef CONFIG_CAVIUM_ERRATUM_30115
  538. {
  539. /* Cavium ThunderX, T88 pass 1.x - 2.2 */
  540. .desc = "Cavium erratum 30115",
  541. .capability = ARM64_WORKAROUND_CAVIUM_30115,
  542. ERRATA_MIDR_RANGE(MIDR_THUNDERX,
  543. 0, 0,
  544. 1, 2),
  545. },
  546. {
  547. /* Cavium ThunderX, T81 pass 1.0 - 1.2 */
  548. .desc = "Cavium erratum 30115",
  549. .capability = ARM64_WORKAROUND_CAVIUM_30115,
  550. ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX_81XX, 0, 0, 2),
  551. },
  552. {
  553. /* Cavium ThunderX, T83 pass 1.0 */
  554. .desc = "Cavium erratum 30115",
  555. .capability = ARM64_WORKAROUND_CAVIUM_30115,
  556. ERRATA_MIDR_REV(MIDR_THUNDERX_83XX, 0, 0),
  557. },
  558. #endif
  559. {
  560. .desc = "Mismatched cache line size",
  561. .capability = ARM64_MISMATCHED_CACHE_LINE_SIZE,
  562. .matches = has_mismatched_cache_type,
  563. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  564. .cpu_enable = cpu_enable_trap_ctr_access,
  565. },
  566. {
  567. .desc = "Mismatched cache type",
  568. .capability = ARM64_MISMATCHED_CACHE_TYPE,
  569. .matches = has_mismatched_cache_type,
  570. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  571. .cpu_enable = cpu_enable_trap_ctr_access,
  572. },
  573. #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
  574. {
  575. .desc = "Qualcomm Technologies Falkor erratum 1003",
  576. .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003,
  577. ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0),
  578. },
  579. {
  580. .desc = "Qualcomm Technologies Kryo erratum 1003",
  581. .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003,
  582. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  583. .midr_range.model = MIDR_QCOM_KRYO,
  584. .matches = is_kryo_midr,
  585. },
  586. #endif
  587. #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009
  588. {
  589. .desc = "Qualcomm Technologies Falkor erratum 1009",
  590. .capability = ARM64_WORKAROUND_REPEAT_TLBI,
  591. ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0),
  592. },
  593. #endif
  594. #ifdef CONFIG_ARM64_ERRATUM_858921
  595. {
  596. /* Cortex-A73 all versions */
  597. .desc = "ARM erratum 858921",
  598. .capability = ARM64_WORKAROUND_858921,
  599. ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
  600. },
  601. #endif
  602. {
  603. .capability = ARM64_HARDEN_BRANCH_PREDICTOR,
  604. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  605. .matches = check_branch_predictor,
  606. },
  607. {
  608. .desc = "Speculative Store Bypass Disable",
  609. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  610. .capability = ARM64_SSBD,
  611. .matches = has_ssbd_mitigation,
  612. .midr_range_list = arm64_ssb_cpus,
  613. },
  614. {
  615. }
  616. };
  617. ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
  618. char *buf)
  619. {
  620. return sprintf(buf, "Mitigation: __user pointer sanitization\n");
  621. }
  622. ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
  623. char *buf)
  624. {
  625. if (__spectrev2_safe)
  626. return sprintf(buf, "Not affected\n");
  627. if (__hardenbp_enab)
  628. return sprintf(buf, "Mitigation: Branch predictor hardening\n");
  629. return sprintf(buf, "Vulnerable\n");
  630. }
  631. ssize_t cpu_show_spec_store_bypass(struct device *dev,
  632. struct device_attribute *attr, char *buf)
  633. {
  634. if (__ssb_safe)
  635. return sprintf(buf, "Not affected\n");
  636. switch (ssbd_state) {
  637. case ARM64_SSBD_KERNEL:
  638. case ARM64_SSBD_FORCE_ENABLE:
  639. if (IS_ENABLED(CONFIG_ARM64_SSBD))
  640. return sprintf(buf,
  641. "Mitigation: Speculative Store Bypass disabled via prctl\n");
  642. }
  643. return sprintf(buf, "Vulnerable\n");
  644. }