2 * Machine check exception handling CPU-side for power7 and power8
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.
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.
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.
18 * Copyright 2013 IBM Corporation
19 * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
23 #define pr_fmt(fmt) "mce_power: " fmt
25 #include <linux/types.h>
26 #include <linux/ptrace.h>
29 #include <asm/machdep.h>
30 #include <asm/pgtable.h>
31 #include <asm/pte-walk.h>
32 #include <asm/sstep.h>
33 #include <asm/exception-64s.h>
36 * Convert an address related to an mm to a PFN. NOTE: we are in real
37 * mode, we could potentially race with page table updates.
39 static unsigned long addr_to_pfn(struct pt_regs
*regs
, unsigned long addr
)
50 local_irq_save(flags
);
51 if (mm
== current
->mm
)
52 ptep
= find_current_mm_pte(mm
->pgd
, addr
, NULL
, NULL
);
54 ptep
= find_init_mm_pte(addr
, NULL
);
55 local_irq_restore(flags
);
56 if (!ptep
|| pte_special(*ptep
))
58 return pte_pfn(*ptep
);
61 static void flush_tlb_206(unsigned int num_sets
, unsigned int action
)
67 case TLB_INVAL_SCOPE_GLOBAL
:
68 rb
= TLBIEL_INVAL_SET
;
70 case TLB_INVAL_SCOPE_LPID
:
71 rb
= TLBIEL_INVAL_SET_LPID
;
78 asm volatile("ptesync" : : : "memory");
79 for (i
= 0; i
< num_sets
; i
++) {
80 asm volatile("tlbiel %0" : : "r" (rb
));
81 rb
+= 1 << TLBIEL_INVAL_SET_SHIFT
;
83 asm volatile("ptesync" : : : "memory");
86 static void flush_tlb_300(unsigned int num_sets
, unsigned int action
)
93 case TLB_INVAL_SCOPE_GLOBAL
:
94 rb
= TLBIEL_INVAL_SET
;
96 case TLB_INVAL_SCOPE_LPID
:
97 rb
= TLBIEL_INVAL_SET_LPID
;
104 asm volatile("ptesync" : : : "memory");
106 if (early_radix_enabled())
112 * First flush table/PWC caches with set 0, then flush the
113 * rest of the sets, partition scope. Radix must then do it
114 * all again with process scope. Hash just has to flush
117 asm volatile(PPC_TLBIEL(%0, %1, %2, %3, %4) : :
118 "r"(rb
), "r"(0), "i"(2), "i"(0), "r"(r
));
119 for (i
= 1; i
< num_sets
; i
++) {
120 unsigned long set
= i
* (1<<TLBIEL_INVAL_SET_SHIFT
);
122 asm volatile(PPC_TLBIEL(%0, %1, %2, %3, %4) : :
123 "r"(rb
+set
), "r"(0), "i"(2), "i"(0), "r"(r
));
126 asm volatile(PPC_TLBIEL(%0, %1, %2, %3, %4) : :
127 "r"(rb
), "r"(0), "i"(2), "i"(1), "r"(r
));
128 if (early_radix_enabled()) {
129 for (i
= 1; i
< num_sets
; i
++) {
130 unsigned long set
= i
* (1<<TLBIEL_INVAL_SET_SHIFT
);
132 asm volatile(PPC_TLBIEL(%0, %1, %2, %3, %4) : :
133 "r"(rb
+set
), "r"(0), "i"(2), "i"(1), "r"(r
));
137 asm volatile("ptesync" : : : "memory");
141 * Generic routines to flush TLB on POWER processors. These routines
142 * are used as flush_tlb hook in the cpu_spec.
144 * action => TLB_INVAL_SCOPE_GLOBAL: Invalidate all TLBs.
145 * TLB_INVAL_SCOPE_LPID: Invalidate TLB for current LPID.
147 void __flush_tlb_power7(unsigned int action
)
149 flush_tlb_206(POWER7_TLB_SETS
, action
);
152 void __flush_tlb_power8(unsigned int action
)
154 flush_tlb_206(POWER8_TLB_SETS
, action
);
157 void __flush_tlb_power9(unsigned int action
)
159 unsigned int num_sets
;
161 if (early_radix_enabled())
162 num_sets
= POWER9_TLB_SETS_RADIX
;
164 num_sets
= POWER9_TLB_SETS_HASH
;
166 flush_tlb_300(num_sets
, action
);
170 /* flush SLBs and reload */
171 #ifdef CONFIG_PPC_BOOK3S_64
172 static void flush_and_reload_slb(void)
174 struct slb_shadow
*slb
;
177 /* Invalidate all SLBs */
178 asm volatile("slbmte %0,%0; slbia" : : "r" (0));
180 #ifdef CONFIG_KVM_BOOK3S_HANDLER
182 * If machine check is hit when in guest or in transition, we will
183 * only flush the SLBs and continue.
185 if (get_paca()->kvm_hstate
.in_guest
)
189 /* For host kernel, reload the SLBs from shadow SLB buffer. */
190 slb
= get_slb_shadow();
194 n
= min_t(u32
, be32_to_cpu(slb
->persistent
), SLB_MIN_SIZE
);
196 /* Load up the SLB entries from shadow SLB */
197 for (i
= 0; i
< n
; i
++) {
198 unsigned long rb
= be64_to_cpu(slb
->save_area
[i
].esid
);
199 unsigned long rs
= be64_to_cpu(slb
->save_area
[i
].vsid
);
201 rb
= (rb
& ~0xFFFul
) | i
;
202 asm volatile("slbmte %0,%1" : : "r" (rs
), "r" (rb
));
207 static void flush_erat(void)
209 asm volatile(PPC_INVALIDATE_ERAT
: : :"memory");
212 #define MCE_FLUSH_SLB 1
213 #define MCE_FLUSH_TLB 2
214 #define MCE_FLUSH_ERAT 3
216 static int mce_flush(int what
)
218 #ifdef CONFIG_PPC_BOOK3S_64
219 if (what
== MCE_FLUSH_SLB
) {
220 flush_and_reload_slb();
224 if (what
== MCE_FLUSH_ERAT
) {
228 if (what
== MCE_FLUSH_TLB
) {
229 if (cur_cpu_spec
&& cur_cpu_spec
->flush_tlb
) {
230 cur_cpu_spec
->flush_tlb(TLB_INVAL_SCOPE_GLOBAL
);
238 #define SRR1_MC_LOADSTORE(srr1) ((srr1) & PPC_BIT(42))
240 struct mce_ierror_table
{
241 unsigned long srr1_mask
;
242 unsigned long srr1_value
;
243 bool nip_valid
; /* nip is a valid indicator of faulting address */
244 unsigned int error_type
;
245 unsigned int error_subtype
;
246 unsigned int initiator
;
247 unsigned int severity
;
250 static const struct mce_ierror_table mce_p7_ierror_table
[] = {
251 { 0x00000000001c0000, 0x0000000000040000, true,
252 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_IFETCH
,
253 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
254 { 0x00000000001c0000, 0x0000000000080000, true,
255 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_PARITY
,
256 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
257 { 0x00000000001c0000, 0x00000000000c0000, true,
258 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_MULTIHIT
,
259 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
260 { 0x00000000001c0000, 0x0000000000100000, true,
261 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_INDETERMINATE
, /* BOTH */
262 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
263 { 0x00000000001c0000, 0x0000000000140000, true,
264 MCE_ERROR_TYPE_TLB
, MCE_TLB_ERROR_MULTIHIT
,
265 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
266 { 0x00000000001c0000, 0x0000000000180000, true,
267 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH
,
268 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
269 { 0x00000000001c0000, 0x00000000001c0000, true,
270 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_IFETCH
,
271 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
272 { 0, 0, 0, 0, 0, 0 } };
274 static const struct mce_ierror_table mce_p8_ierror_table
[] = {
275 { 0x00000000081c0000, 0x0000000000040000, true,
276 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_IFETCH
,
277 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
278 { 0x00000000081c0000, 0x0000000000080000, true,
279 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_PARITY
,
280 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
281 { 0x00000000081c0000, 0x00000000000c0000, true,
282 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_MULTIHIT
,
283 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
284 { 0x00000000081c0000, 0x0000000000100000, true,
285 MCE_ERROR_TYPE_ERAT
,MCE_ERAT_ERROR_MULTIHIT
,
286 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
287 { 0x00000000081c0000, 0x0000000000140000, true,
288 MCE_ERROR_TYPE_TLB
, MCE_TLB_ERROR_MULTIHIT
,
289 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
290 { 0x00000000081c0000, 0x0000000000180000, true,
291 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH
,
292 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
293 { 0x00000000081c0000, 0x00000000001c0000, true,
294 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_IFETCH
,
295 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
296 { 0x00000000081c0000, 0x0000000008000000, true,
297 MCE_ERROR_TYPE_LINK
,MCE_LINK_ERROR_IFETCH_TIMEOUT
,
298 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
299 { 0x00000000081c0000, 0x0000000008040000, true,
300 MCE_ERROR_TYPE_LINK
,MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT
,
301 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
302 { 0, 0, 0, 0, 0, 0 } };
304 static const struct mce_ierror_table mce_p9_ierror_table
[] = {
305 { 0x00000000081c0000, 0x0000000000040000, true,
306 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_IFETCH
,
307 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
308 { 0x00000000081c0000, 0x0000000000080000, true,
309 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_PARITY
,
310 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
311 { 0x00000000081c0000, 0x00000000000c0000, true,
312 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_MULTIHIT
,
313 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
314 { 0x00000000081c0000, 0x0000000000100000, true,
315 MCE_ERROR_TYPE_ERAT
,MCE_ERAT_ERROR_MULTIHIT
,
316 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
317 { 0x00000000081c0000, 0x0000000000140000, true,
318 MCE_ERROR_TYPE_TLB
, MCE_TLB_ERROR_MULTIHIT
,
319 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
320 { 0x00000000081c0000, 0x0000000000180000, true,
321 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH
,
322 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
323 { 0x00000000081c0000, 0x00000000001c0000, true,
324 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_IFETCH_FOREIGN
,
325 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
326 { 0x00000000081c0000, 0x0000000008000000, true,
327 MCE_ERROR_TYPE_LINK
,MCE_LINK_ERROR_IFETCH_TIMEOUT
,
328 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
329 { 0x00000000081c0000, 0x0000000008040000, true,
330 MCE_ERROR_TYPE_LINK
,MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT
,
331 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
332 { 0x00000000081c0000, 0x00000000080c0000, true,
333 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_IFETCH
,
334 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
335 { 0x00000000081c0000, 0x0000000008100000, true,
336 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH
,
337 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
338 { 0x00000000081c0000, 0x0000000008140000, false,
339 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_STORE
,
340 MCE_INITIATOR_CPU
, MCE_SEV_FATAL
, }, /* ASYNC is fatal */
341 { 0x00000000081c0000, 0x0000000008180000, false,
342 MCE_ERROR_TYPE_LINK
,MCE_LINK_ERROR_STORE_TIMEOUT
,
343 MCE_INITIATOR_CPU
, MCE_SEV_FATAL
, }, /* ASYNC is fatal */
344 { 0x00000000081c0000, 0x00000000081c0000, true,
345 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH_FOREIGN
,
346 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
347 { 0, 0, 0, 0, 0, 0 } };
349 struct mce_derror_table
{
350 unsigned long dsisr_value
;
351 bool dar_valid
; /* dar is a valid indicator of faulting address */
352 unsigned int error_type
;
353 unsigned int error_subtype
;
354 unsigned int initiator
;
355 unsigned int severity
;
358 static const struct mce_derror_table mce_p7_derror_table
[] = {
360 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_LOAD_STORE
,
361 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
363 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE
,
364 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
366 MCE_ERROR_TYPE_ERAT
, MCE_ERAT_ERROR_MULTIHIT
,
367 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
369 MCE_ERROR_TYPE_TLB
, MCE_TLB_ERROR_MULTIHIT
,
370 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
372 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_PARITY
,
373 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
375 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_MULTIHIT
,
376 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
378 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_INDETERMINATE
, /* BOTH */
379 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
380 { 0, false, 0, 0, 0, 0 } };
382 static const struct mce_derror_table mce_p8_derror_table
[] = {
384 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_LOAD_STORE
,
385 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
387 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE
,
388 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
390 MCE_ERROR_TYPE_LINK
, MCE_LINK_ERROR_LOAD_TIMEOUT
,
391 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
393 MCE_ERROR_TYPE_LINK
, MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT
,
394 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
396 MCE_ERROR_TYPE_ERAT
, MCE_ERAT_ERROR_MULTIHIT
,
397 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
399 MCE_ERROR_TYPE_TLB
, MCE_TLB_ERROR_MULTIHIT
,
400 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
402 MCE_ERROR_TYPE_ERAT
, MCE_ERAT_ERROR_MULTIHIT
, /* SECONDARY ERAT */
403 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
405 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_PARITY
,
406 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
408 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_MULTIHIT
,
409 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
410 { 0, false, 0, 0, 0, 0 } };
412 static const struct mce_derror_table mce_p9_derror_table
[] = {
414 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_LOAD_STORE
,
415 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
417 MCE_ERROR_TYPE_UE
, MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE
,
418 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
420 MCE_ERROR_TYPE_LINK
, MCE_LINK_ERROR_LOAD_TIMEOUT
,
421 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
423 MCE_ERROR_TYPE_LINK
, MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT
,
424 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
426 MCE_ERROR_TYPE_ERAT
, MCE_ERAT_ERROR_MULTIHIT
,
427 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
429 MCE_ERROR_TYPE_TLB
, MCE_TLB_ERROR_MULTIHIT
,
430 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
432 MCE_ERROR_TYPE_USER
, MCE_USER_ERROR_TLBIE
,
433 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
435 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_PARITY
,
436 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
438 MCE_ERROR_TYPE_SLB
, MCE_SLB_ERROR_MULTIHIT
,
439 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
441 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_LOAD
,
442 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
444 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE
,
445 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
447 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE_FOREIGN
,
448 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
450 MCE_ERROR_TYPE_RA
, MCE_RA_ERROR_LOAD_STORE_FOREIGN
,
451 MCE_INITIATOR_CPU
, MCE_SEV_ERROR_SYNC
, },
452 { 0, false, 0, 0, 0, 0 } };
454 static int mce_find_instr_ea_and_pfn(struct pt_regs
*regs
, uint64_t *addr
,
458 * Carefully look at the NIP to determine
459 * the instruction to analyse. Reading the NIP
460 * in real-mode is tricky and can lead to recursive
464 unsigned long pfn
, instr_addr
;
465 struct instruction_op op
;
466 struct pt_regs tmp
= *regs
;
468 pfn
= addr_to_pfn(regs
, regs
->nip
);
469 if (pfn
!= ULONG_MAX
) {
470 instr_addr
= (pfn
<< PAGE_SHIFT
) + (regs
->nip
& ~PAGE_MASK
);
471 instr
= *(unsigned int *)(instr_addr
);
472 if (!analyse_instr(&op
, &tmp
, instr
)) {
473 pfn
= addr_to_pfn(regs
, op
.ea
);
475 *phys_addr
= (pfn
<< PAGE_SHIFT
);
479 * analyse_instr() might fail if the instruction
480 * is not a load/store, although this is unexpected
481 * for load/store errors or if we got the NIP
489 static int mce_handle_ierror(struct pt_regs
*regs
,
490 const struct mce_ierror_table table
[],
491 struct mce_error_info
*mce_err
, uint64_t *addr
,
494 uint64_t srr1
= regs
->msr
;
500 for (i
= 0; table
[i
].srr1_mask
; i
++) {
501 if ((srr1
& table
[i
].srr1_mask
) != table
[i
].srr1_value
)
504 /* attempt to correct the error */
505 switch (table
[i
].error_type
) {
506 case MCE_ERROR_TYPE_SLB
:
507 handled
= mce_flush(MCE_FLUSH_SLB
);
509 case MCE_ERROR_TYPE_ERAT
:
510 handled
= mce_flush(MCE_FLUSH_ERAT
);
512 case MCE_ERROR_TYPE_TLB
:
513 handled
= mce_flush(MCE_FLUSH_TLB
);
517 /* now fill in mce_error_info */
518 mce_err
->error_type
= table
[i
].error_type
;
519 switch (table
[i
].error_type
) {
520 case MCE_ERROR_TYPE_UE
:
521 mce_err
->u
.ue_error_type
= table
[i
].error_subtype
;
523 case MCE_ERROR_TYPE_SLB
:
524 mce_err
->u
.slb_error_type
= table
[i
].error_subtype
;
526 case MCE_ERROR_TYPE_ERAT
:
527 mce_err
->u
.erat_error_type
= table
[i
].error_subtype
;
529 case MCE_ERROR_TYPE_TLB
:
530 mce_err
->u
.tlb_error_type
= table
[i
].error_subtype
;
532 case MCE_ERROR_TYPE_USER
:
533 mce_err
->u
.user_error_type
= table
[i
].error_subtype
;
535 case MCE_ERROR_TYPE_RA
:
536 mce_err
->u
.ra_error_type
= table
[i
].error_subtype
;
538 case MCE_ERROR_TYPE_LINK
:
539 mce_err
->u
.link_error_type
= table
[i
].error_subtype
;
542 mce_err
->severity
= table
[i
].severity
;
543 mce_err
->initiator
= table
[i
].initiator
;
544 if (table
[i
].nip_valid
) {
546 if (mce_err
->severity
== MCE_SEV_ERROR_SYNC
&&
547 table
[i
].error_type
== MCE_ERROR_TYPE_UE
) {
550 if (get_paca()->in_mce
< MAX_MCE_DEPTH
) {
551 pfn
= addr_to_pfn(regs
, regs
->nip
);
552 if (pfn
!= ULONG_MAX
) {
563 mce_err
->error_type
= MCE_ERROR_TYPE_UNKNOWN
;
564 mce_err
->severity
= MCE_SEV_ERROR_SYNC
;
565 mce_err
->initiator
= MCE_INITIATOR_CPU
;
570 static int mce_handle_derror(struct pt_regs
*regs
,
571 const struct mce_derror_table table
[],
572 struct mce_error_info
*mce_err
, uint64_t *addr
,
575 uint64_t dsisr
= regs
->dsisr
;
582 for (i
= 0; table
[i
].dsisr_value
; i
++) {
583 if (!(dsisr
& table
[i
].dsisr_value
))
586 /* attempt to correct the error */
587 switch (table
[i
].error_type
) {
588 case MCE_ERROR_TYPE_SLB
:
589 if (mce_flush(MCE_FLUSH_SLB
))
592 case MCE_ERROR_TYPE_ERAT
:
593 if (mce_flush(MCE_FLUSH_ERAT
))
596 case MCE_ERROR_TYPE_TLB
:
597 if (mce_flush(MCE_FLUSH_TLB
))
603 * Attempt to handle multiple conditions, but only return
604 * one. Ensure uncorrectable errors are first in the table
610 /* now fill in mce_error_info */
611 mce_err
->error_type
= table
[i
].error_type
;
612 switch (table
[i
].error_type
) {
613 case MCE_ERROR_TYPE_UE
:
614 mce_err
->u
.ue_error_type
= table
[i
].error_subtype
;
616 case MCE_ERROR_TYPE_SLB
:
617 mce_err
->u
.slb_error_type
= table
[i
].error_subtype
;
619 case MCE_ERROR_TYPE_ERAT
:
620 mce_err
->u
.erat_error_type
= table
[i
].error_subtype
;
622 case MCE_ERROR_TYPE_TLB
:
623 mce_err
->u
.tlb_error_type
= table
[i
].error_subtype
;
625 case MCE_ERROR_TYPE_USER
:
626 mce_err
->u
.user_error_type
= table
[i
].error_subtype
;
628 case MCE_ERROR_TYPE_RA
:
629 mce_err
->u
.ra_error_type
= table
[i
].error_subtype
;
631 case MCE_ERROR_TYPE_LINK
:
632 mce_err
->u
.link_error_type
= table
[i
].error_subtype
;
635 mce_err
->severity
= table
[i
].severity
;
636 mce_err
->initiator
= table
[i
].initiator
;
637 if (table
[i
].dar_valid
)
639 else if (mce_err
->severity
== MCE_SEV_ERROR_SYNC
&&
640 table
[i
].error_type
== MCE_ERROR_TYPE_UE
) {
642 * We do a maximum of 4 nested MCE calls, see
643 * kernel/exception-64s.h
645 if (get_paca()->in_mce
< MAX_MCE_DEPTH
)
646 if (!mce_find_instr_ea_and_pfn(regs
, addr
,
656 mce_err
->error_type
= MCE_ERROR_TYPE_UNKNOWN
;
657 mce_err
->severity
= MCE_SEV_ERROR_SYNC
;
658 mce_err
->initiator
= MCE_INITIATOR_CPU
;
663 static long mce_handle_ue_error(struct pt_regs
*regs
)
668 * On specific SCOM read via MMIO we may get a machine check
669 * exception with SRR0 pointing inside opal. If that is the
670 * case OPAL may have recovery address to re-read SCOM data in
671 * different way and hence we can recover from this MC.
674 if (ppc_md
.mce_check_early_recovery
) {
675 if (ppc_md
.mce_check_early_recovery(regs
))
681 static long mce_handle_error(struct pt_regs
*regs
,
682 const struct mce_derror_table dtable
[],
683 const struct mce_ierror_table itable
[])
685 struct mce_error_info mce_err
= { 0 };
686 uint64_t addr
, phys_addr
;
687 uint64_t srr1
= regs
->msr
;
690 if (SRR1_MC_LOADSTORE(srr1
))
691 handled
= mce_handle_derror(regs
, dtable
, &mce_err
, &addr
,
694 handled
= mce_handle_ierror(regs
, itable
, &mce_err
, &addr
,
697 if (!handled
&& mce_err
.error_type
== MCE_ERROR_TYPE_UE
)
698 handled
= mce_handle_ue_error(regs
);
700 save_mce_event(regs
, handled
, &mce_err
, regs
->nip
, addr
, phys_addr
);
705 long __machine_check_early_realmode_p7(struct pt_regs
*regs
)
707 /* P7 DD1 leaves top bits of DSISR undefined */
708 regs
->dsisr
&= 0x0000ffff;
710 return mce_handle_error(regs
, mce_p7_derror_table
, mce_p7_ierror_table
);
713 long __machine_check_early_realmode_p8(struct pt_regs
*regs
)
715 return mce_handle_error(regs
, mce_p8_derror_table
, mce_p8_ierror_table
);
718 long __machine_check_early_realmode_p9(struct pt_regs
*regs
)
721 * On POWER9 DD2.1 and below, it's possible to get a machine check
722 * caused by a paste instruction where only DSISR bit 25 is set. This
723 * will result in the MCE handler seeing an unknown event and the kernel
724 * crashing. An MCE that occurs like this is spurious, so we don't need
725 * to do anything in terms of servicing it. If there is something that
726 * needs to be serviced, the CPU will raise the MCE again with the
727 * correct DSISR so that it can be serviced properly. So detect this
728 * case and mark it as handled.
730 if (SRR1_MC_LOADSTORE(regs
->msr
) && regs
->dsisr
== 0x02000000)
733 return mce_handle_error(regs
, mce_p9_derror_table
, mce_p9_ierror_table
);