Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 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 | |
| 22 | #undef DEBUG |
| 23 | #define pr_fmt(fmt) "mce_power: " fmt |
| 24 | |
| 25 | #include <linux/types.h> |
| 26 | #include <linux/ptrace.h> |
| 27 | #include <asm/mmu.h> |
| 28 | #include <asm/mce.h> |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 29 | #include <asm/machdep.h> |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 30 | |
Mahesh Salgaonkar | 45706bb | 2014-12-19 08:41:05 +0530 | [diff] [blame] | 31 | static void flush_tlb_206(unsigned int num_sets, unsigned int action) |
| 32 | { |
| 33 | unsigned long rb; |
| 34 | unsigned int i; |
| 35 | |
| 36 | switch (action) { |
| 37 | case TLB_INVAL_SCOPE_GLOBAL: |
| 38 | rb = TLBIEL_INVAL_SET; |
| 39 | break; |
| 40 | case TLB_INVAL_SCOPE_LPID: |
| 41 | rb = TLBIEL_INVAL_SET_LPID; |
| 42 | break; |
| 43 | default: |
| 44 | BUG(); |
| 45 | break; |
| 46 | } |
| 47 | |
| 48 | asm volatile("ptesync" : : : "memory"); |
| 49 | for (i = 0; i < num_sets; i++) { |
| 50 | asm volatile("tlbiel %0" : : "r" (rb)); |
| 51 | rb += 1 << TLBIEL_INVAL_SET_SHIFT; |
| 52 | } |
| 53 | asm volatile("ptesync" : : : "memory"); |
| 54 | } |
| 55 | |
| 56 | /* |
Michael Neuling | c3ab300 | 2016-02-19 11:16:24 +1100 | [diff] [blame] | 57 | * Generic routines to flush TLB on POWER processors. These routines |
| 58 | * are used as flush_tlb hook in the cpu_spec. |
Mahesh Salgaonkar | 45706bb | 2014-12-19 08:41:05 +0530 | [diff] [blame] | 59 | * |
| 60 | * action => TLB_INVAL_SCOPE_GLOBAL: Invalidate all TLBs. |
| 61 | * TLB_INVAL_SCOPE_LPID: Invalidate TLB for current LPID. |
| 62 | */ |
| 63 | void __flush_tlb_power7(unsigned int action) |
| 64 | { |
| 65 | flush_tlb_206(POWER7_TLB_SETS, action); |
| 66 | } |
| 67 | |
Mahesh Salgaonkar | 45706bb | 2014-12-19 08:41:05 +0530 | [diff] [blame] | 68 | void __flush_tlb_power8(unsigned int action) |
| 69 | { |
| 70 | flush_tlb_206(POWER8_TLB_SETS, action); |
| 71 | } |
| 72 | |
Michael Neuling | c3ab300 | 2016-02-19 11:16:24 +1100 | [diff] [blame] | 73 | void __flush_tlb_power9(unsigned int action) |
| 74 | { |
Aneesh Kumar K.V | 1a472c9 | 2016-04-29 23:26:05 +1000 | [diff] [blame] | 75 | if (radix_enabled()) |
| 76 | flush_tlb_206(POWER9_TLB_SETS_RADIX, action); |
| 77 | |
Michael Neuling | c3ab300 | 2016-02-19 11:16:24 +1100 | [diff] [blame] | 78 | flush_tlb_206(POWER9_TLB_SETS_HASH, action); |
| 79 | } |
| 80 | |
| 81 | |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 82 | /* flush SLBs and reload */ |
Valentin Rothberg | bb03efe | 2016-05-03 08:59:27 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_PPC_STD_MMU_64 |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 84 | static void flush_and_reload_slb(void) |
| 85 | { |
| 86 | struct slb_shadow *slb; |
| 87 | unsigned long i, n; |
| 88 | |
| 89 | /* Invalidate all SLBs */ |
| 90 | asm volatile("slbmte %0,%0; slbia" : : "r" (0)); |
| 91 | |
| 92 | #ifdef CONFIG_KVM_BOOK3S_HANDLER |
| 93 | /* |
| 94 | * If machine check is hit when in guest or in transition, we will |
| 95 | * only flush the SLBs and continue. |
| 96 | */ |
| 97 | if (get_paca()->kvm_hstate.in_guest) |
| 98 | return; |
| 99 | #endif |
| 100 | |
| 101 | /* For host kernel, reload the SLBs from shadow SLB buffer. */ |
| 102 | slb = get_slb_shadow(); |
| 103 | if (!slb) |
| 104 | return; |
| 105 | |
Anton Blanchard | a68c33f | 2013-12-16 10:47:54 +1100 | [diff] [blame] | 106 | n = min_t(u32, be32_to_cpu(slb->persistent), SLB_MIN_SIZE); |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 107 | |
| 108 | /* Load up the SLB entries from shadow SLB */ |
| 109 | for (i = 0; i < n; i++) { |
Anton Blanchard | a68c33f | 2013-12-16 10:47:54 +1100 | [diff] [blame] | 110 | unsigned long rb = be64_to_cpu(slb->save_area[i].esid); |
| 111 | unsigned long rs = be64_to_cpu(slb->save_area[i].vsid); |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 112 | |
| 113 | rb = (rb & ~0xFFFul) | i; |
| 114 | asm volatile("slbmte %0,%1" : : "r" (rs), "r" (rb)); |
| 115 | } |
| 116 | } |
Aneesh Kumar K.V | caca285 | 2016-04-29 23:26:07 +1000 | [diff] [blame] | 117 | #endif |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 118 | |
Nicholas Piggin | 7b9f71f9 | 2017-02-28 12:00:48 +1000 | [diff] [blame] | 119 | static void flush_erat(void) |
| 120 | { |
| 121 | asm volatile(PPC_INVALIDATE_ERAT : : :"memory"); |
| 122 | } |
| 123 | |
| 124 | #define MCE_FLUSH_SLB 1 |
| 125 | #define MCE_FLUSH_TLB 2 |
| 126 | #define MCE_FLUSH_ERAT 3 |
| 127 | |
| 128 | static int mce_flush(int what) |
| 129 | { |
| 130 | #ifdef CONFIG_PPC_STD_MMU_64 |
| 131 | if (what == MCE_FLUSH_SLB) { |
| 132 | flush_and_reload_slb(); |
| 133 | return 1; |
| 134 | } |
| 135 | #endif |
| 136 | if (what == MCE_FLUSH_ERAT) { |
| 137 | flush_erat(); |
| 138 | return 1; |
| 139 | } |
| 140 | if (what == MCE_FLUSH_TLB) { |
| 141 | if (cur_cpu_spec && cur_cpu_spec->flush_tlb) { |
| 142 | cur_cpu_spec->flush_tlb(TLB_INVAL_SCOPE_GLOBAL); |
| 143 | return 1; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int mce_handle_flush_derrors(uint64_t dsisr, uint64_t slb, uint64_t tlb, uint64_t erat) |
| 151 | { |
| 152 | if ((dsisr & slb) && mce_flush(MCE_FLUSH_SLB)) |
| 153 | dsisr &= ~slb; |
| 154 | if ((dsisr & erat) && mce_flush(MCE_FLUSH_ERAT)) |
| 155 | dsisr &= ~erat; |
| 156 | if ((dsisr & tlb) && mce_flush(MCE_FLUSH_TLB)) |
| 157 | dsisr &= ~tlb; |
| 158 | /* Any other errors we don't understand? */ |
| 159 | if (dsisr) |
| 160 | return 0; |
| 161 | return 1; |
| 162 | } |
| 163 | |
Nicholas Piggin | 58c8d17 | 2017-03-14 22:36:45 +1000 | [diff] [blame^] | 164 | |
| 165 | /* |
| 166 | * Machine Check bits on power7 and power8 |
| 167 | */ |
| 168 | #define P7_SRR1_MC_LOADSTORE(srr1) ((srr1) & PPC_BIT(42)) /* P8 too */ |
| 169 | |
| 170 | /* SRR1 bits for machine check (On Power7 and Power8) */ |
| 171 | #define P7_SRR1_MC_IFETCH(srr1) ((srr1) & PPC_BITMASK(43, 45)) /* P8 too */ |
| 172 | |
| 173 | #define P7_SRR1_MC_IFETCH_UE (0x1 << PPC_BITLSHIFT(45)) /* P8 too */ |
| 174 | #define P7_SRR1_MC_IFETCH_SLB_PARITY (0x2 << PPC_BITLSHIFT(45)) /* P8 too */ |
| 175 | #define P7_SRR1_MC_IFETCH_SLB_MULTIHIT (0x3 << PPC_BITLSHIFT(45)) /* P8 too */ |
| 176 | #define P7_SRR1_MC_IFETCH_SLB_BOTH (0x4 << PPC_BITLSHIFT(45)) |
| 177 | #define P7_SRR1_MC_IFETCH_TLB_MULTIHIT (0x5 << PPC_BITLSHIFT(45)) /* P8 too */ |
| 178 | #define P7_SRR1_MC_IFETCH_UE_TLB_RELOAD (0x6 << PPC_BITLSHIFT(45)) /* P8 too */ |
| 179 | #define P7_SRR1_MC_IFETCH_UE_IFU_INTERNAL (0x7 << PPC_BITLSHIFT(45)) |
| 180 | |
| 181 | /* SRR1 bits for machine check (On Power8) */ |
| 182 | #define P8_SRR1_MC_IFETCH_ERAT_MULTIHIT (0x4 << PPC_BITLSHIFT(45)) |
| 183 | |
| 184 | /* DSISR bits for machine check (On Power7 and Power8) */ |
| 185 | #define P7_DSISR_MC_UE (PPC_BIT(48)) /* P8 too */ |
| 186 | #define P7_DSISR_MC_UE_TABLEWALK (PPC_BIT(49)) /* P8 too */ |
| 187 | #define P7_DSISR_MC_ERAT_MULTIHIT (PPC_BIT(52)) /* P8 too */ |
| 188 | #define P7_DSISR_MC_TLB_MULTIHIT_MFTLB (PPC_BIT(53)) /* P8 too */ |
| 189 | #define P7_DSISR_MC_SLB_PARITY_MFSLB (PPC_BIT(55)) /* P8 too */ |
| 190 | #define P7_DSISR_MC_SLB_MULTIHIT (PPC_BIT(56)) /* P8 too */ |
| 191 | #define P7_DSISR_MC_SLB_MULTIHIT_PARITY (PPC_BIT(57)) /* P8 too */ |
| 192 | |
| 193 | /* |
| 194 | * DSISR bits for machine check (Power8) in addition to above. |
| 195 | * Secondary DERAT Multihit |
| 196 | */ |
| 197 | #define P8_DSISR_MC_ERAT_MULTIHIT_SEC (PPC_BIT(54)) |
| 198 | |
| 199 | /* SLB error bits */ |
| 200 | #define P7_DSISR_MC_SLB_ERRORS (P7_DSISR_MC_ERAT_MULTIHIT | \ |
| 201 | P7_DSISR_MC_SLB_PARITY_MFSLB | \ |
| 202 | P7_DSISR_MC_SLB_MULTIHIT | \ |
| 203 | P7_DSISR_MC_SLB_MULTIHIT_PARITY) |
| 204 | |
| 205 | #define P8_DSISR_MC_SLB_ERRORS (P7_DSISR_MC_SLB_ERRORS | \ |
| 206 | P8_DSISR_MC_ERAT_MULTIHIT_SEC) |
| 207 | |
| 208 | /* |
| 209 | * Machine Check bits on power9 |
| 210 | */ |
| 211 | #define P9_SRR1_MC_LOADSTORE(srr1) (((srr1) >> PPC_BITLSHIFT(42)) & 1) |
| 212 | |
| 213 | #define P9_SRR1_MC_IFETCH(srr1) ( \ |
| 214 | PPC_BITEXTRACT(srr1, 45, 0) | \ |
| 215 | PPC_BITEXTRACT(srr1, 44, 1) | \ |
| 216 | PPC_BITEXTRACT(srr1, 43, 2) | \ |
| 217 | PPC_BITEXTRACT(srr1, 36, 3) ) |
| 218 | |
| 219 | /* 0 is reserved */ |
| 220 | #define P9_SRR1_MC_IFETCH_UE 1 |
| 221 | #define P9_SRR1_MC_IFETCH_SLB_PARITY 2 |
| 222 | #define P9_SRR1_MC_IFETCH_SLB_MULTIHIT 3 |
| 223 | #define P9_SRR1_MC_IFETCH_ERAT_MULTIHIT 4 |
| 224 | #define P9_SRR1_MC_IFETCH_TLB_MULTIHIT 5 |
| 225 | #define P9_SRR1_MC_IFETCH_UE_TLB_RELOAD 6 |
| 226 | /* 7 is reserved */ |
| 227 | #define P9_SRR1_MC_IFETCH_LINK_TIMEOUT 8 |
| 228 | #define P9_SRR1_MC_IFETCH_LINK_TABLEWALK_TIMEOUT 9 |
| 229 | /* 10 ? */ |
| 230 | #define P9_SRR1_MC_IFETCH_RA 11 |
| 231 | #define P9_SRR1_MC_IFETCH_RA_TABLEWALK 12 |
| 232 | #define P9_SRR1_MC_IFETCH_RA_ASYNC_STORE 13 |
| 233 | #define P9_SRR1_MC_IFETCH_LINK_ASYNC_STORE_TIMEOUT 14 |
| 234 | #define P9_SRR1_MC_IFETCH_RA_TABLEWALK_FOREIGN 15 |
| 235 | |
| 236 | /* DSISR bits for machine check (On Power9) */ |
| 237 | #define P9_DSISR_MC_UE (PPC_BIT(48)) |
| 238 | #define P9_DSISR_MC_UE_TABLEWALK (PPC_BIT(49)) |
| 239 | #define P9_DSISR_MC_LINK_LOAD_TIMEOUT (PPC_BIT(50)) |
| 240 | #define P9_DSISR_MC_LINK_TABLEWALK_TIMEOUT (PPC_BIT(51)) |
| 241 | #define P9_DSISR_MC_ERAT_MULTIHIT (PPC_BIT(52)) |
| 242 | #define P9_DSISR_MC_TLB_MULTIHIT_MFTLB (PPC_BIT(53)) |
| 243 | #define P9_DSISR_MC_USER_TLBIE (PPC_BIT(54)) |
| 244 | #define P9_DSISR_MC_SLB_PARITY_MFSLB (PPC_BIT(55)) |
| 245 | #define P9_DSISR_MC_SLB_MULTIHIT_MFSLB (PPC_BIT(56)) |
| 246 | #define P9_DSISR_MC_RA_LOAD (PPC_BIT(57)) |
| 247 | #define P9_DSISR_MC_RA_TABLEWALK (PPC_BIT(58)) |
| 248 | #define P9_DSISR_MC_RA_TABLEWALK_FOREIGN (PPC_BIT(59)) |
| 249 | #define P9_DSISR_MC_RA_FOREIGN (PPC_BIT(60)) |
| 250 | |
| 251 | /* SLB error bits */ |
| 252 | #define P9_DSISR_MC_SLB_ERRORS (P9_DSISR_MC_ERAT_MULTIHIT | \ |
| 253 | P9_DSISR_MC_SLB_PARITY_MFSLB | \ |
| 254 | P9_DSISR_MC_SLB_MULTIHIT_MFSLB) |
| 255 | |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 256 | static long mce_handle_derror_p7(uint64_t dsisr) |
| 257 | { |
Nicholas Piggin | 88c6511 | 2017-03-14 22:36:44 +1000 | [diff] [blame] | 258 | return mce_handle_flush_derrors(dsisr, |
| 259 | P7_DSISR_MC_SLB_ERRORS, |
| 260 | P7_DSISR_MC_TLB_MULTIHIT_MFTLB, |
| 261 | 0); |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static long mce_handle_ierror_p7(uint64_t srr1) |
| 265 | { |
Nicholas Piggin | 88c6511 | 2017-03-14 22:36:44 +1000 | [diff] [blame] | 266 | switch (P7_SRR1_MC_IFETCH(srr1)) { |
| 267 | case P7_SRR1_MC_IFETCH_SLB_PARITY: |
| 268 | case P7_SRR1_MC_IFETCH_SLB_MULTIHIT: |
| 269 | case P7_SRR1_MC_IFETCH_SLB_BOTH: |
| 270 | return mce_flush(MCE_FLUSH_SLB); |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 271 | |
Nicholas Piggin | 88c6511 | 2017-03-14 22:36:44 +1000 | [diff] [blame] | 272 | case P7_SRR1_MC_IFETCH_TLB_MULTIHIT: |
| 273 | return mce_flush(MCE_FLUSH_TLB); |
| 274 | default: |
| 275 | return 0; |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 276 | } |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 277 | } |
| 278 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 279 | static void mce_get_common_ierror(struct mce_error_info *mce_err, uint64_t srr1) |
| 280 | { |
| 281 | switch (P7_SRR1_MC_IFETCH(srr1)) { |
| 282 | case P7_SRR1_MC_IFETCH_SLB_PARITY: |
| 283 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 284 | mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY; |
| 285 | break; |
| 286 | case P7_SRR1_MC_IFETCH_SLB_MULTIHIT: |
| 287 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 288 | mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT; |
| 289 | break; |
| 290 | case P7_SRR1_MC_IFETCH_TLB_MULTIHIT: |
| 291 | mce_err->error_type = MCE_ERROR_TYPE_TLB; |
| 292 | mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT; |
| 293 | break; |
| 294 | case P7_SRR1_MC_IFETCH_UE: |
| 295 | case P7_SRR1_MC_IFETCH_UE_IFU_INTERNAL: |
| 296 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 297 | mce_err->u.ue_error_type = MCE_UE_ERROR_IFETCH; |
| 298 | break; |
| 299 | case P7_SRR1_MC_IFETCH_UE_TLB_RELOAD: |
| 300 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 301 | mce_err->u.ue_error_type = |
| 302 | MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | static void mce_get_ierror_p7(struct mce_error_info *mce_err, uint64_t srr1) |
| 308 | { |
| 309 | mce_get_common_ierror(mce_err, srr1); |
| 310 | if (P7_SRR1_MC_IFETCH(srr1) == P7_SRR1_MC_IFETCH_SLB_BOTH) { |
| 311 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 312 | mce_err->u.slb_error_type = MCE_SLB_ERROR_INDETERMINATE; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | static void mce_get_derror_p7(struct mce_error_info *mce_err, uint64_t dsisr) |
| 317 | { |
| 318 | if (dsisr & P7_DSISR_MC_UE) { |
| 319 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 320 | mce_err->u.ue_error_type = MCE_UE_ERROR_LOAD_STORE; |
| 321 | } else if (dsisr & P7_DSISR_MC_UE_TABLEWALK) { |
| 322 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 323 | mce_err->u.ue_error_type = |
| 324 | MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE; |
| 325 | } else if (dsisr & P7_DSISR_MC_ERAT_MULTIHIT) { |
| 326 | mce_err->error_type = MCE_ERROR_TYPE_ERAT; |
| 327 | mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT; |
| 328 | } else if (dsisr & P7_DSISR_MC_SLB_MULTIHIT) { |
| 329 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 330 | mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT; |
| 331 | } else if (dsisr & P7_DSISR_MC_SLB_PARITY_MFSLB) { |
| 332 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 333 | mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY; |
| 334 | } else if (dsisr & P7_DSISR_MC_TLB_MULTIHIT_MFTLB) { |
| 335 | mce_err->error_type = MCE_ERROR_TYPE_TLB; |
| 336 | mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT; |
| 337 | } else if (dsisr & P7_DSISR_MC_SLB_MULTIHIT_PARITY) { |
| 338 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 339 | mce_err->u.slb_error_type = MCE_SLB_ERROR_INDETERMINATE; |
| 340 | } |
| 341 | } |
| 342 | |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 343 | static long mce_handle_ue_error(struct pt_regs *regs) |
| 344 | { |
| 345 | long handled = 0; |
| 346 | |
| 347 | /* |
| 348 | * On specific SCOM read via MMIO we may get a machine check |
| 349 | * exception with SRR0 pointing inside opal. If that is the |
| 350 | * case OPAL may have recovery address to re-read SCOM data in |
| 351 | * different way and hence we can recover from this MC. |
| 352 | */ |
| 353 | |
| 354 | if (ppc_md.mce_check_early_recovery) { |
| 355 | if (ppc_md.mce_check_early_recovery(regs)) |
| 356 | handled = 1; |
| 357 | } |
| 358 | return handled; |
| 359 | } |
| 360 | |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 361 | long __machine_check_early_realmode_p7(struct pt_regs *regs) |
| 362 | { |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 363 | uint64_t srr1, nip, addr; |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 364 | long handled = 1; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 365 | struct mce_error_info mce_error_info = { 0 }; |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 366 | |
Nicholas Piggin | c1bbf38 | 2017-02-28 12:00:47 +1000 | [diff] [blame] | 367 | mce_error_info.severity = MCE_SEV_ERROR_SYNC; |
| 368 | mce_error_info.initiator = MCE_INITIATOR_CPU; |
| 369 | |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 370 | srr1 = regs->msr; |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 371 | nip = regs->nip; |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 372 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 373 | /* |
| 374 | * Handle memory errors depending whether this was a load/store or |
| 375 | * ifetch exception. Also, populate the mce error_type and |
| 376 | * type-specific error_type from either SRR1 or DSISR, depending |
| 377 | * whether this was a load/store or ifetch exception |
| 378 | */ |
| 379 | if (P7_SRR1_MC_LOADSTORE(srr1)) { |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 380 | handled = mce_handle_derror_p7(regs->dsisr); |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 381 | mce_get_derror_p7(&mce_error_info, regs->dsisr); |
| 382 | addr = regs->dar; |
| 383 | } else { |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 384 | handled = mce_handle_ierror_p7(srr1); |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 385 | mce_get_ierror_p7(&mce_error_info, srr1); |
| 386 | addr = regs->nip; |
| 387 | } |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 388 | |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 389 | /* Handle UE error. */ |
| 390 | if (mce_error_info.error_type == MCE_ERROR_TYPE_UE) |
| 391 | handled = mce_handle_ue_error(regs); |
| 392 | |
| 393 | save_mce_event(regs, handled, &mce_error_info, nip, addr); |
Mahesh Salgaonkar | e22a227 | 2013-10-30 20:05:11 +0530 | [diff] [blame] | 394 | return handled; |
| 395 | } |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 396 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 397 | static void mce_get_ierror_p8(struct mce_error_info *mce_err, uint64_t srr1) |
| 398 | { |
| 399 | mce_get_common_ierror(mce_err, srr1); |
| 400 | if (P7_SRR1_MC_IFETCH(srr1) == P8_SRR1_MC_IFETCH_ERAT_MULTIHIT) { |
| 401 | mce_err->error_type = MCE_ERROR_TYPE_ERAT; |
| 402 | mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | static void mce_get_derror_p8(struct mce_error_info *mce_err, uint64_t dsisr) |
| 407 | { |
| 408 | mce_get_derror_p7(mce_err, dsisr); |
| 409 | if (dsisr & P8_DSISR_MC_ERAT_MULTIHIT_SEC) { |
| 410 | mce_err->error_type = MCE_ERROR_TYPE_ERAT; |
| 411 | mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT; |
| 412 | } |
| 413 | } |
| 414 | |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 415 | static long mce_handle_ierror_p8(uint64_t srr1) |
| 416 | { |
Nicholas Piggin | 88c6511 | 2017-03-14 22:36:44 +1000 | [diff] [blame] | 417 | switch (P7_SRR1_MC_IFETCH(srr1)) { |
| 418 | case P7_SRR1_MC_IFETCH_SLB_PARITY: |
| 419 | case P7_SRR1_MC_IFETCH_SLB_MULTIHIT: |
| 420 | case P8_SRR1_MC_IFETCH_ERAT_MULTIHIT: |
| 421 | return mce_flush(MCE_FLUSH_SLB); |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 422 | |
Nicholas Piggin | 88c6511 | 2017-03-14 22:36:44 +1000 | [diff] [blame] | 423 | case P7_SRR1_MC_IFETCH_TLB_MULTIHIT: |
| 424 | return mce_flush(MCE_FLUSH_TLB); |
| 425 | default: |
| 426 | return 0; |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 427 | } |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static long mce_handle_derror_p8(uint64_t dsisr) |
| 431 | { |
Nicholas Piggin | 88c6511 | 2017-03-14 22:36:44 +1000 | [diff] [blame] | 432 | return mce_handle_flush_derrors(dsisr, |
| 433 | P8_DSISR_MC_SLB_ERRORS, |
| 434 | P7_DSISR_MC_TLB_MULTIHIT_MFTLB, |
| 435 | 0); |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | long __machine_check_early_realmode_p8(struct pt_regs *regs) |
| 439 | { |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 440 | uint64_t srr1, nip, addr; |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 441 | long handled = 1; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 442 | struct mce_error_info mce_error_info = { 0 }; |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 443 | |
Nicholas Piggin | c1bbf38 | 2017-02-28 12:00:47 +1000 | [diff] [blame] | 444 | mce_error_info.severity = MCE_SEV_ERROR_SYNC; |
| 445 | mce_error_info.initiator = MCE_INITIATOR_CPU; |
| 446 | |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 447 | srr1 = regs->msr; |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 448 | nip = regs->nip; |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 449 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 450 | if (P7_SRR1_MC_LOADSTORE(srr1)) { |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 451 | handled = mce_handle_derror_p8(regs->dsisr); |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 452 | mce_get_derror_p8(&mce_error_info, regs->dsisr); |
| 453 | addr = regs->dar; |
| 454 | } else { |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 455 | handled = mce_handle_ierror_p8(srr1); |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 456 | mce_get_ierror_p8(&mce_error_info, srr1); |
| 457 | addr = regs->nip; |
| 458 | } |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 459 | |
Mahesh Salgaonkar | 55672ec | 2013-12-16 10:46:24 +0530 | [diff] [blame] | 460 | /* Handle UE error. */ |
| 461 | if (mce_error_info.error_type == MCE_ERROR_TYPE_UE) |
| 462 | handled = mce_handle_ue_error(regs); |
| 463 | |
| 464 | save_mce_event(regs, handled, &mce_error_info, nip, addr); |
Mahesh Salgaonkar | ae744f3 | 2013-10-30 20:05:26 +0530 | [diff] [blame] | 465 | return handled; |
| 466 | } |
Nicholas Piggin | 7b9f71f9 | 2017-02-28 12:00:48 +1000 | [diff] [blame] | 467 | |
| 468 | static int mce_handle_derror_p9(struct pt_regs *regs) |
| 469 | { |
| 470 | uint64_t dsisr = regs->dsisr; |
| 471 | |
| 472 | return mce_handle_flush_derrors(dsisr, |
| 473 | P9_DSISR_MC_SLB_PARITY_MFSLB | |
| 474 | P9_DSISR_MC_SLB_MULTIHIT_MFSLB, |
| 475 | |
| 476 | P9_DSISR_MC_TLB_MULTIHIT_MFTLB, |
| 477 | |
| 478 | P9_DSISR_MC_ERAT_MULTIHIT); |
| 479 | } |
| 480 | |
| 481 | static int mce_handle_ierror_p9(struct pt_regs *regs) |
| 482 | { |
| 483 | uint64_t srr1 = regs->msr; |
| 484 | |
| 485 | switch (P9_SRR1_MC_IFETCH(srr1)) { |
| 486 | case P9_SRR1_MC_IFETCH_SLB_PARITY: |
| 487 | case P9_SRR1_MC_IFETCH_SLB_MULTIHIT: |
| 488 | return mce_flush(MCE_FLUSH_SLB); |
| 489 | case P9_SRR1_MC_IFETCH_TLB_MULTIHIT: |
| 490 | return mce_flush(MCE_FLUSH_TLB); |
| 491 | case P9_SRR1_MC_IFETCH_ERAT_MULTIHIT: |
| 492 | return mce_flush(MCE_FLUSH_ERAT); |
| 493 | default: |
| 494 | return 0; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | static void mce_get_derror_p9(struct pt_regs *regs, |
| 499 | struct mce_error_info *mce_err, uint64_t *addr) |
| 500 | { |
| 501 | uint64_t dsisr = regs->dsisr; |
| 502 | |
| 503 | mce_err->severity = MCE_SEV_ERROR_SYNC; |
| 504 | mce_err->initiator = MCE_INITIATOR_CPU; |
| 505 | |
| 506 | if (dsisr & P9_DSISR_MC_USER_TLBIE) |
| 507 | *addr = regs->nip; |
| 508 | else |
| 509 | *addr = regs->dar; |
| 510 | |
| 511 | if (dsisr & P9_DSISR_MC_UE) { |
| 512 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 513 | mce_err->u.ue_error_type = MCE_UE_ERROR_LOAD_STORE; |
| 514 | } else if (dsisr & P9_DSISR_MC_UE_TABLEWALK) { |
| 515 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 516 | mce_err->u.ue_error_type = MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE; |
| 517 | } else if (dsisr & P9_DSISR_MC_LINK_LOAD_TIMEOUT) { |
| 518 | mce_err->error_type = MCE_ERROR_TYPE_LINK; |
| 519 | mce_err->u.link_error_type = MCE_LINK_ERROR_LOAD_TIMEOUT; |
| 520 | } else if (dsisr & P9_DSISR_MC_LINK_TABLEWALK_TIMEOUT) { |
| 521 | mce_err->error_type = MCE_ERROR_TYPE_LINK; |
| 522 | mce_err->u.link_error_type = MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT; |
| 523 | } else if (dsisr & P9_DSISR_MC_ERAT_MULTIHIT) { |
| 524 | mce_err->error_type = MCE_ERROR_TYPE_ERAT; |
| 525 | mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT; |
| 526 | } else if (dsisr & P9_DSISR_MC_TLB_MULTIHIT_MFTLB) { |
| 527 | mce_err->error_type = MCE_ERROR_TYPE_TLB; |
| 528 | mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT; |
| 529 | } else if (dsisr & P9_DSISR_MC_USER_TLBIE) { |
| 530 | mce_err->error_type = MCE_ERROR_TYPE_USER; |
| 531 | mce_err->u.user_error_type = MCE_USER_ERROR_TLBIE; |
| 532 | } else if (dsisr & P9_DSISR_MC_SLB_PARITY_MFSLB) { |
| 533 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 534 | mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY; |
| 535 | } else if (dsisr & P9_DSISR_MC_SLB_MULTIHIT_MFSLB) { |
| 536 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 537 | mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT; |
| 538 | } else if (dsisr & P9_DSISR_MC_RA_LOAD) { |
| 539 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 540 | mce_err->u.ra_error_type = MCE_RA_ERROR_LOAD; |
| 541 | } else if (dsisr & P9_DSISR_MC_RA_TABLEWALK) { |
| 542 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 543 | mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE; |
| 544 | } else if (dsisr & P9_DSISR_MC_RA_TABLEWALK_FOREIGN) { |
| 545 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 546 | mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE_FOREIGN; |
| 547 | } else if (dsisr & P9_DSISR_MC_RA_FOREIGN) { |
| 548 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 549 | mce_err->u.ra_error_type = MCE_RA_ERROR_LOAD_STORE_FOREIGN; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | static void mce_get_ierror_p9(struct pt_regs *regs, |
| 554 | struct mce_error_info *mce_err, uint64_t *addr) |
| 555 | { |
| 556 | uint64_t srr1 = regs->msr; |
| 557 | |
| 558 | switch (P9_SRR1_MC_IFETCH(srr1)) { |
| 559 | case P9_SRR1_MC_IFETCH_RA_ASYNC_STORE: |
| 560 | case P9_SRR1_MC_IFETCH_LINK_ASYNC_STORE_TIMEOUT: |
| 561 | mce_err->severity = MCE_SEV_FATAL; |
| 562 | break; |
| 563 | default: |
| 564 | mce_err->severity = MCE_SEV_ERROR_SYNC; |
| 565 | break; |
| 566 | } |
| 567 | |
| 568 | mce_err->initiator = MCE_INITIATOR_CPU; |
| 569 | |
| 570 | *addr = regs->nip; |
| 571 | |
| 572 | switch (P9_SRR1_MC_IFETCH(srr1)) { |
| 573 | case P9_SRR1_MC_IFETCH_UE: |
| 574 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 575 | mce_err->u.ue_error_type = MCE_UE_ERROR_IFETCH; |
| 576 | break; |
| 577 | case P9_SRR1_MC_IFETCH_SLB_PARITY: |
| 578 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 579 | mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY; |
| 580 | break; |
| 581 | case P9_SRR1_MC_IFETCH_SLB_MULTIHIT: |
| 582 | mce_err->error_type = MCE_ERROR_TYPE_SLB; |
| 583 | mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT; |
| 584 | break; |
| 585 | case P9_SRR1_MC_IFETCH_ERAT_MULTIHIT: |
| 586 | mce_err->error_type = MCE_ERROR_TYPE_ERAT; |
| 587 | mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT; |
| 588 | break; |
| 589 | case P9_SRR1_MC_IFETCH_TLB_MULTIHIT: |
| 590 | mce_err->error_type = MCE_ERROR_TYPE_TLB; |
| 591 | mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT; |
| 592 | break; |
| 593 | case P9_SRR1_MC_IFETCH_UE_TLB_RELOAD: |
| 594 | mce_err->error_type = MCE_ERROR_TYPE_UE; |
| 595 | mce_err->u.ue_error_type = MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH; |
| 596 | break; |
| 597 | case P9_SRR1_MC_IFETCH_LINK_TIMEOUT: |
| 598 | mce_err->error_type = MCE_ERROR_TYPE_LINK; |
| 599 | mce_err->u.link_error_type = MCE_LINK_ERROR_IFETCH_TIMEOUT; |
| 600 | break; |
| 601 | case P9_SRR1_MC_IFETCH_LINK_TABLEWALK_TIMEOUT: |
| 602 | mce_err->error_type = MCE_ERROR_TYPE_LINK; |
| 603 | mce_err->u.link_error_type = MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT; |
| 604 | break; |
| 605 | case P9_SRR1_MC_IFETCH_RA: |
| 606 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 607 | mce_err->u.ra_error_type = MCE_RA_ERROR_IFETCH; |
| 608 | break; |
| 609 | case P9_SRR1_MC_IFETCH_RA_TABLEWALK: |
| 610 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 611 | mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH; |
| 612 | break; |
| 613 | case P9_SRR1_MC_IFETCH_RA_ASYNC_STORE: |
| 614 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 615 | mce_err->u.ra_error_type = MCE_RA_ERROR_STORE; |
| 616 | break; |
| 617 | case P9_SRR1_MC_IFETCH_LINK_ASYNC_STORE_TIMEOUT: |
| 618 | mce_err->error_type = MCE_ERROR_TYPE_LINK; |
| 619 | mce_err->u.link_error_type = MCE_LINK_ERROR_STORE_TIMEOUT; |
| 620 | break; |
| 621 | case P9_SRR1_MC_IFETCH_RA_TABLEWALK_FOREIGN: |
| 622 | mce_err->error_type = MCE_ERROR_TYPE_RA; |
| 623 | mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH_FOREIGN; |
| 624 | break; |
| 625 | default: |
| 626 | break; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | long __machine_check_early_realmode_p9(struct pt_regs *regs) |
| 631 | { |
| 632 | uint64_t nip, addr; |
| 633 | long handled; |
| 634 | struct mce_error_info mce_error_info = { 0 }; |
| 635 | |
| 636 | nip = regs->nip; |
| 637 | |
| 638 | if (P9_SRR1_MC_LOADSTORE(regs->msr)) { |
| 639 | handled = mce_handle_derror_p9(regs); |
| 640 | mce_get_derror_p9(regs, &mce_error_info, &addr); |
| 641 | } else { |
| 642 | handled = mce_handle_ierror_p9(regs); |
| 643 | mce_get_ierror_p9(regs, &mce_error_info, &addr); |
| 644 | } |
| 645 | |
| 646 | /* Handle UE error. */ |
| 647 | if (mce_error_info.error_type == MCE_ERROR_TYPE_UE) |
| 648 | handled = mce_handle_ue_error(regs); |
| 649 | |
| 650 | save_mce_event(regs, handled, &mce_error_info, nip, addr); |
| 651 | return handled; |
| 652 | } |