mce_power.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * Machine check exception handling CPU-side for power7 and power8
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright 2013 IBM Corporation
  19. * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
  20. */
  21. #undef DEBUG
  22. #define pr_fmt(fmt) "mce_power: " fmt
  23. #include <linux/types.h>
  24. #include <linux/ptrace.h>
  25. #include <asm/mmu.h>
  26. #include <asm/mce.h>
  27. #include <asm/machdep.h>
  28. static void flush_tlb_206(unsigned int num_sets, unsigned int action)
  29. {
  30. unsigned long rb;
  31. unsigned int i;
  32. switch (action) {
  33. case TLB_INVAL_SCOPE_GLOBAL:
  34. rb = TLBIEL_INVAL_SET;
  35. break;
  36. case TLB_INVAL_SCOPE_LPID:
  37. rb = TLBIEL_INVAL_SET_LPID;
  38. break;
  39. default:
  40. BUG();
  41. break;
  42. }
  43. asm volatile("ptesync" : : : "memory");
  44. for (i = 0; i < num_sets; i++) {
  45. asm volatile("tlbiel %0" : : "r" (rb));
  46. rb += 1 << TLBIEL_INVAL_SET_SHIFT;
  47. }
  48. asm volatile("ptesync" : : : "memory");
  49. }
  50. /*
  51. * Generic routine to flush TLB on power7. This routine is used as
  52. * flush_tlb hook in cpu_spec for Power7 processor.
  53. *
  54. * action => TLB_INVAL_SCOPE_GLOBAL: Invalidate all TLBs.
  55. * TLB_INVAL_SCOPE_LPID: Invalidate TLB for current LPID.
  56. */
  57. void __flush_tlb_power7(unsigned int action)
  58. {
  59. flush_tlb_206(POWER7_TLB_SETS, action);
  60. }
  61. /*
  62. * Generic routine to flush TLB on power8. This routine is used as
  63. * flush_tlb hook in cpu_spec for power8 processor.
  64. *
  65. * action => TLB_INVAL_SCOPE_GLOBAL: Invalidate all TLBs.
  66. * TLB_INVAL_SCOPE_LPID: Invalidate TLB for current LPID.
  67. */
  68. void __flush_tlb_power8(unsigned int action)
  69. {
  70. flush_tlb_206(POWER8_TLB_SETS, action);
  71. }
  72. /* flush SLBs and reload */
  73. static void flush_and_reload_slb(void)
  74. {
  75. struct slb_shadow *slb;
  76. unsigned long i, n;
  77. /* Invalidate all SLBs */
  78. asm volatile("slbmte %0,%0; slbia" : : "r" (0));
  79. #ifdef CONFIG_KVM_BOOK3S_HANDLER
  80. /*
  81. * If machine check is hit when in guest or in transition, we will
  82. * only flush the SLBs and continue.
  83. */
  84. if (get_paca()->kvm_hstate.in_guest)
  85. return;
  86. #endif
  87. /* For host kernel, reload the SLBs from shadow SLB buffer. */
  88. slb = get_slb_shadow();
  89. if (!slb)
  90. return;
  91. n = min_t(u32, be32_to_cpu(slb->persistent), SLB_MIN_SIZE);
  92. /* Load up the SLB entries from shadow SLB */
  93. for (i = 0; i < n; i++) {
  94. unsigned long rb = be64_to_cpu(slb->save_area[i].esid);
  95. unsigned long rs = be64_to_cpu(slb->save_area[i].vsid);
  96. rb = (rb & ~0xFFFul) | i;
  97. asm volatile("slbmte %0,%1" : : "r" (rs), "r" (rb));
  98. }
  99. }
  100. static long mce_handle_derror(uint64_t dsisr, uint64_t slb_error_bits)
  101. {
  102. long handled = 1;
  103. /*
  104. * flush and reload SLBs for SLB errors and flush TLBs for TLB errors.
  105. * reset the error bits whenever we handle them so that at the end
  106. * we can check whether we handled all of them or not.
  107. * */
  108. if (dsisr & slb_error_bits) {
  109. flush_and_reload_slb();
  110. /* reset error bits */
  111. dsisr &= ~(slb_error_bits);
  112. }
  113. if (dsisr & P7_DSISR_MC_TLB_MULTIHIT_MFTLB) {
  114. if (cur_cpu_spec && cur_cpu_spec->flush_tlb)
  115. cur_cpu_spec->flush_tlb(TLB_INVAL_SCOPE_GLOBAL);
  116. /* reset error bits */
  117. dsisr &= ~P7_DSISR_MC_TLB_MULTIHIT_MFTLB;
  118. }
  119. /* Any other errors we don't understand? */
  120. if (dsisr & 0xffffffffUL)
  121. handled = 0;
  122. return handled;
  123. }
  124. static long mce_handle_derror_p7(uint64_t dsisr)
  125. {
  126. return mce_handle_derror(dsisr, P7_DSISR_MC_SLB_ERRORS);
  127. }
  128. static long mce_handle_common_ierror(uint64_t srr1)
  129. {
  130. long handled = 0;
  131. switch (P7_SRR1_MC_IFETCH(srr1)) {
  132. case 0:
  133. break;
  134. case P7_SRR1_MC_IFETCH_SLB_PARITY:
  135. case P7_SRR1_MC_IFETCH_SLB_MULTIHIT:
  136. /* flush and reload SLBs for SLB errors. */
  137. flush_and_reload_slb();
  138. handled = 1;
  139. break;
  140. case P7_SRR1_MC_IFETCH_TLB_MULTIHIT:
  141. if (cur_cpu_spec && cur_cpu_spec->flush_tlb) {
  142. cur_cpu_spec->flush_tlb(TLB_INVAL_SCOPE_GLOBAL);
  143. handled = 1;
  144. }
  145. break;
  146. default:
  147. break;
  148. }
  149. return handled;
  150. }
  151. static long mce_handle_ierror_p7(uint64_t srr1)
  152. {
  153. long handled = 0;
  154. handled = mce_handle_common_ierror(srr1);
  155. if (P7_SRR1_MC_IFETCH(srr1) == P7_SRR1_MC_IFETCH_SLB_BOTH) {
  156. flush_and_reload_slb();
  157. handled = 1;
  158. }
  159. return handled;
  160. }
  161. static void mce_get_common_ierror(struct mce_error_info *mce_err, uint64_t srr1)
  162. {
  163. switch (P7_SRR1_MC_IFETCH(srr1)) {
  164. case P7_SRR1_MC_IFETCH_SLB_PARITY:
  165. mce_err->error_type = MCE_ERROR_TYPE_SLB;
  166. mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY;
  167. break;
  168. case P7_SRR1_MC_IFETCH_SLB_MULTIHIT:
  169. mce_err->error_type = MCE_ERROR_TYPE_SLB;
  170. mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT;
  171. break;
  172. case P7_SRR1_MC_IFETCH_TLB_MULTIHIT:
  173. mce_err->error_type = MCE_ERROR_TYPE_TLB;
  174. mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT;
  175. break;
  176. case P7_SRR1_MC_IFETCH_UE:
  177. case P7_SRR1_MC_IFETCH_UE_IFU_INTERNAL:
  178. mce_err->error_type = MCE_ERROR_TYPE_UE;
  179. mce_err->u.ue_error_type = MCE_UE_ERROR_IFETCH;
  180. break;
  181. case P7_SRR1_MC_IFETCH_UE_TLB_RELOAD:
  182. mce_err->error_type = MCE_ERROR_TYPE_UE;
  183. mce_err->u.ue_error_type =
  184. MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH;
  185. break;
  186. }
  187. }
  188. static void mce_get_ierror_p7(struct mce_error_info *mce_err, uint64_t srr1)
  189. {
  190. mce_get_common_ierror(mce_err, srr1);
  191. if (P7_SRR1_MC_IFETCH(srr1) == P7_SRR1_MC_IFETCH_SLB_BOTH) {
  192. mce_err->error_type = MCE_ERROR_TYPE_SLB;
  193. mce_err->u.slb_error_type = MCE_SLB_ERROR_INDETERMINATE;
  194. }
  195. }
  196. static void mce_get_derror_p7(struct mce_error_info *mce_err, uint64_t dsisr)
  197. {
  198. if (dsisr & P7_DSISR_MC_UE) {
  199. mce_err->error_type = MCE_ERROR_TYPE_UE;
  200. mce_err->u.ue_error_type = MCE_UE_ERROR_LOAD_STORE;
  201. } else if (dsisr & P7_DSISR_MC_UE_TABLEWALK) {
  202. mce_err->error_type = MCE_ERROR_TYPE_UE;
  203. mce_err->u.ue_error_type =
  204. MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE;
  205. } else if (dsisr & P7_DSISR_MC_ERAT_MULTIHIT) {
  206. mce_err->error_type = MCE_ERROR_TYPE_ERAT;
  207. mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
  208. } else if (dsisr & P7_DSISR_MC_SLB_MULTIHIT) {
  209. mce_err->error_type = MCE_ERROR_TYPE_SLB;
  210. mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT;
  211. } else if (dsisr & P7_DSISR_MC_SLB_PARITY_MFSLB) {
  212. mce_err->error_type = MCE_ERROR_TYPE_SLB;
  213. mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY;
  214. } else if (dsisr & P7_DSISR_MC_TLB_MULTIHIT_MFTLB) {
  215. mce_err->error_type = MCE_ERROR_TYPE_TLB;
  216. mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT;
  217. } else if (dsisr & P7_DSISR_MC_SLB_MULTIHIT_PARITY) {
  218. mce_err->error_type = MCE_ERROR_TYPE_SLB;
  219. mce_err->u.slb_error_type = MCE_SLB_ERROR_INDETERMINATE;
  220. }
  221. }
  222. static long mce_handle_ue_error(struct pt_regs *regs)
  223. {
  224. long handled = 0;
  225. /*
  226. * On specific SCOM read via MMIO we may get a machine check
  227. * exception with SRR0 pointing inside opal. If that is the
  228. * case OPAL may have recovery address to re-read SCOM data in
  229. * different way and hence we can recover from this MC.
  230. */
  231. if (ppc_md.mce_check_early_recovery) {
  232. if (ppc_md.mce_check_early_recovery(regs))
  233. handled = 1;
  234. }
  235. return handled;
  236. }
  237. long __machine_check_early_realmode_p7(struct pt_regs *regs)
  238. {
  239. uint64_t srr1, nip, addr;
  240. long handled = 1;
  241. struct mce_error_info mce_error_info = { 0 };
  242. srr1 = regs->msr;
  243. nip = regs->nip;
  244. /*
  245. * Handle memory errors depending whether this was a load/store or
  246. * ifetch exception. Also, populate the mce error_type and
  247. * type-specific error_type from either SRR1 or DSISR, depending
  248. * whether this was a load/store or ifetch exception
  249. */
  250. if (P7_SRR1_MC_LOADSTORE(srr1)) {
  251. handled = mce_handle_derror_p7(regs->dsisr);
  252. mce_get_derror_p7(&mce_error_info, regs->dsisr);
  253. addr = regs->dar;
  254. } else {
  255. handled = mce_handle_ierror_p7(srr1);
  256. mce_get_ierror_p7(&mce_error_info, srr1);
  257. addr = regs->nip;
  258. }
  259. /* Handle UE error. */
  260. if (mce_error_info.error_type == MCE_ERROR_TYPE_UE)
  261. handled = mce_handle_ue_error(regs);
  262. save_mce_event(regs, handled, &mce_error_info, nip, addr);
  263. return handled;
  264. }
  265. static void mce_get_ierror_p8(struct mce_error_info *mce_err, uint64_t srr1)
  266. {
  267. mce_get_common_ierror(mce_err, srr1);
  268. if (P7_SRR1_MC_IFETCH(srr1) == P8_SRR1_MC_IFETCH_ERAT_MULTIHIT) {
  269. mce_err->error_type = MCE_ERROR_TYPE_ERAT;
  270. mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
  271. }
  272. }
  273. static void mce_get_derror_p8(struct mce_error_info *mce_err, uint64_t dsisr)
  274. {
  275. mce_get_derror_p7(mce_err, dsisr);
  276. if (dsisr & P8_DSISR_MC_ERAT_MULTIHIT_SEC) {
  277. mce_err->error_type = MCE_ERROR_TYPE_ERAT;
  278. mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
  279. }
  280. }
  281. static long mce_handle_ierror_p8(uint64_t srr1)
  282. {
  283. long handled = 0;
  284. handled = mce_handle_common_ierror(srr1);
  285. if (P7_SRR1_MC_IFETCH(srr1) == P8_SRR1_MC_IFETCH_ERAT_MULTIHIT) {
  286. flush_and_reload_slb();
  287. handled = 1;
  288. }
  289. return handled;
  290. }
  291. static long mce_handle_derror_p8(uint64_t dsisr)
  292. {
  293. return mce_handle_derror(dsisr, P8_DSISR_MC_SLB_ERRORS);
  294. }
  295. long __machine_check_early_realmode_p8(struct pt_regs *regs)
  296. {
  297. uint64_t srr1, nip, addr;
  298. long handled = 1;
  299. struct mce_error_info mce_error_info = { 0 };
  300. srr1 = regs->msr;
  301. nip = regs->nip;
  302. if (P7_SRR1_MC_LOADSTORE(srr1)) {
  303. handled = mce_handle_derror_p8(regs->dsisr);
  304. mce_get_derror_p8(&mce_error_info, regs->dsisr);
  305. addr = regs->dar;
  306. } else {
  307. handled = mce_handle_ierror_p8(srr1);
  308. mce_get_ierror_p8(&mce_error_info, srr1);
  309. addr = regs->nip;
  310. }
  311. /* Handle UE error. */
  312. if (mce_error_info.error_type == MCE_ERROR_TYPE_UE)
  313. handled = mce_handle_ue_error(regs);
  314. save_mce_event(regs, handled, &mce_error_info, nip, addr);
  315. return handled;
  316. }