blob: 6647a31b85b298912f2e3de2b0dd52c76efc7e93 [file] [log] [blame]
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +05301/*
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 Salgaonkar55672ec2013-12-16 10:46:24 +053029#include <asm/machdep.h>
Balbir Singhba41e1e2017-09-29 14:26:53 +100030#include <asm/pgtable.h>
31#include <asm/pte-walk.h>
32#include <asm/sstep.h>
33#include <asm/exception-64s.h>
34
35/*
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.
38 */
Ganesh Goudar7f177f92019-04-15 15:35:44 +053039unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr)
Balbir Singhba41e1e2017-09-29 14:26:53 +100040{
41 pte_t *ptep;
42 unsigned long flags;
43 struct mm_struct *mm;
44
45 if (user_mode(regs))
46 mm = current->mm;
47 else
48 mm = &init_mm;
49
50 local_irq_save(flags);
51 if (mm == current->mm)
52 ptep = find_current_mm_pte(mm->pgd, addr, NULL, NULL);
53 else
54 ptep = find_init_mm_pte(addr, NULL);
55 local_irq_restore(flags);
56 if (!ptep || pte_special(*ptep))
57 return ULONG_MAX;
58 return pte_pfn(*ptep);
59}
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053060
61/* flush SLBs and reload */
Michael Ellerman4e003742017-10-19 15:08:43 +110062#ifdef CONFIG_PPC_BOOK3S_64
Mahesh Salgaonkara43c1592018-09-11 19:57:00 +053063void flush_and_reload_slb(void)
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053064{
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053065 /* Invalidate all SLBs */
Nicholas Piggine7e81842018-08-10 16:42:48 +100066 slb_flush_all_realmode();
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053067
68#ifdef CONFIG_KVM_BOOK3S_HANDLER
69 /*
70 * If machine check is hit when in guest or in transition, we will
71 * only flush the SLBs and continue.
72 */
73 if (get_paca()->kvm_hstate.in_guest)
74 return;
75#endif
Nicholas Piggine7e81842018-08-10 16:42:48 +100076 if (early_radix_enabled())
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053077 return;
78
Nicholas Piggine7e81842018-08-10 16:42:48 +100079 /*
80 * This probably shouldn't happen, but it may be possible it's
81 * called in early boot before SLB shadows are allocated.
82 */
83 if (!get_slb_shadow())
84 return;
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053085
Nicholas Piggine7e81842018-08-10 16:42:48 +100086 slb_restore_bolted_realmode();
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053087}
Aneesh Kumar K.Vcaca2852016-04-29 23:26:07 +100088#endif
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +053089
Nicholas Piggin7b9f71f92017-02-28 12:00:48 +100090static void flush_erat(void)
91{
Nicholas Pigginbc276ec2018-08-27 13:03:01 +100092#ifdef CONFIG_PPC_BOOK3S_64
93 if (!early_cpu_has_feature(CPU_FTR_ARCH_300)) {
94 flush_and_reload_slb();
95 return;
96 }
97#endif
98 /* PPC_INVALIDATE_ERAT can only be used on ISA v3 and newer */
Nicholas Piggin7b9f71f92017-02-28 12:00:48 +100099 asm volatile(PPC_INVALIDATE_ERAT : : :"memory");
100}
101
102#define MCE_FLUSH_SLB 1
103#define MCE_FLUSH_TLB 2
104#define MCE_FLUSH_ERAT 3
105
106static int mce_flush(int what)
107{
Michael Ellerman4e003742017-10-19 15:08:43 +1100108#ifdef CONFIG_PPC_BOOK3S_64
Nicholas Piggin7b9f71f92017-02-28 12:00:48 +1000109 if (what == MCE_FLUSH_SLB) {
110 flush_and_reload_slb();
111 return 1;
112 }
113#endif
114 if (what == MCE_FLUSH_ERAT) {
115 flush_erat();
116 return 1;
117 }
118 if (what == MCE_FLUSH_TLB) {
Nicholas Piggind4748272017-12-24 01:15:50 +1000119 tlbiel_all();
120 return 1;
Nicholas Piggin7b9f71f92017-02-28 12:00:48 +1000121 }
122
123 return 0;
124}
125
Nicholas Piggin755309b2017-03-14 22:36:47 +1000126#define SRR1_MC_LOADSTORE(srr1) ((srr1) & PPC_BIT(42))
Nicholas Piggin58c8d172017-03-14 22:36:45 +1000127
Nicholas Piggin631bc462017-03-14 22:36:46 +1000128struct mce_ierror_table {
129 unsigned long srr1_mask;
130 unsigned long srr1_value;
131 bool nip_valid; /* nip is a valid indicator of faulting address */
132 unsigned int error_type;
133 unsigned int error_subtype;
134 unsigned int initiator;
135 unsigned int severity;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530136 bool sync_error;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000137};
138
139static const struct mce_ierror_table mce_p7_ierror_table[] = {
140{ 0x00000000001c0000, 0x0000000000040000, true,
141 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530142 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000143{ 0x00000000001c0000, 0x0000000000080000, true,
144 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_PARITY,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530145 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000146{ 0x00000000001c0000, 0x00000000000c0000, true,
147 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530148 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000149{ 0x00000000001c0000, 0x0000000000100000, true,
150 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_INDETERMINATE, /* BOTH */
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530151 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000152{ 0x00000000001c0000, 0x0000000000140000, true,
153 MCE_ERROR_TYPE_TLB, MCE_TLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530154 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000155{ 0x00000000001c0000, 0x0000000000180000, true,
156 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530157 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000158{ 0x00000000001c0000, 0x00000000001c0000, true,
159 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530160 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
161{ 0, 0, 0, 0, 0, 0, 0 } };
Nicholas Piggin631bc462017-03-14 22:36:46 +1000162
163static const struct mce_ierror_table mce_p8_ierror_table[] = {
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000164{ 0x00000000081c0000, 0x0000000000040000, true,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000165 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530166 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000167{ 0x00000000081c0000, 0x0000000000080000, true,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000168 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_PARITY,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530169 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000170{ 0x00000000081c0000, 0x00000000000c0000, true,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000171 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530172 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000173{ 0x00000000081c0000, 0x0000000000100000, true,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000174 MCE_ERROR_TYPE_ERAT,MCE_ERAT_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530175 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000176{ 0x00000000081c0000, 0x0000000000140000, true,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000177 MCE_ERROR_TYPE_TLB, MCE_TLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530178 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000179{ 0x00000000081c0000, 0x0000000000180000, true,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000180 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530181 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000182{ 0x00000000081c0000, 0x00000000001c0000, true,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000183 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530184 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000185{ 0x00000000081c0000, 0x0000000008000000, true,
186 MCE_ERROR_TYPE_LINK,MCE_LINK_ERROR_IFETCH_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530187 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000188{ 0x00000000081c0000, 0x0000000008040000, true,
189 MCE_ERROR_TYPE_LINK,MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530190 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
191{ 0, 0, 0, 0, 0, 0, 0 } };
Nicholas Piggin631bc462017-03-14 22:36:46 +1000192
193static const struct mce_ierror_table mce_p9_ierror_table[] = {
194{ 0x00000000081c0000, 0x0000000000040000, true,
195 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530196 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000197{ 0x00000000081c0000, 0x0000000000080000, true,
198 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_PARITY,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530199 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000200{ 0x00000000081c0000, 0x00000000000c0000, true,
201 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530202 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000203{ 0x00000000081c0000, 0x0000000000100000, true,
204 MCE_ERROR_TYPE_ERAT,MCE_ERAT_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530205 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000206{ 0x00000000081c0000, 0x0000000000140000, true,
207 MCE_ERROR_TYPE_TLB, MCE_TLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530208 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000209{ 0x00000000081c0000, 0x0000000000180000, true,
210 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530211 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin90df4bf2017-05-29 16:26:44 +1000212{ 0x00000000081c0000, 0x00000000001c0000, true,
213 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_IFETCH_FOREIGN,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530214 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000215{ 0x00000000081c0000, 0x0000000008000000, true,
216 MCE_ERROR_TYPE_LINK,MCE_LINK_ERROR_IFETCH_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530217 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000218{ 0x00000000081c0000, 0x0000000008040000, true,
219 MCE_ERROR_TYPE_LINK,MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530220 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000221{ 0x00000000081c0000, 0x00000000080c0000, true,
222 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530223 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000224{ 0x00000000081c0000, 0x0000000008100000, true,
225 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530226 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000227{ 0x00000000081c0000, 0x0000000008140000, false,
228 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530229 MCE_INITIATOR_CPU, MCE_SEV_FATAL, false }, /* ASYNC is fatal */
Nicholas Piggin631bc462017-03-14 22:36:46 +1000230{ 0x00000000081c0000, 0x0000000008180000, false,
231 MCE_ERROR_TYPE_LINK,MCE_LINK_ERROR_STORE_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530232 MCE_INITIATOR_CPU, MCE_SEV_FATAL, false }, /* ASYNC is fatal */
Nicholas Piggin631bc462017-03-14 22:36:46 +1000233{ 0x00000000081c0000, 0x00000000081c0000, true,
234 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH_FOREIGN,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530235 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
236{ 0, 0, 0, 0, 0, 0, 0 } };
Nicholas Piggin631bc462017-03-14 22:36:46 +1000237
238struct mce_derror_table {
239 unsigned long dsisr_value;
240 bool dar_valid; /* dar is a valid indicator of faulting address */
241 unsigned int error_type;
242 unsigned int error_subtype;
243 unsigned int initiator;
244 unsigned int severity;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530245 bool sync_error;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000246};
247
248static const struct mce_derror_table mce_p7_derror_table[] = {
249{ 0x00008000, false,
250 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_LOAD_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530251 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000252{ 0x00004000, true,
253 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530254 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000255{ 0x00000800, true,
256 MCE_ERROR_TYPE_ERAT, MCE_ERAT_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530257 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000258{ 0x00000400, true,
259 MCE_ERROR_TYPE_TLB, MCE_TLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530260 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Michael Ellerman54dbcfc2018-06-13 23:24:14 +1000261{ 0x00000080, true,
262 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_MULTIHIT, /* Before PARITY */
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530263 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000264{ 0x00000100, true,
265 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_PARITY,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530266 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000267{ 0x00000040, true,
268 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_INDETERMINATE, /* BOTH */
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530269 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
270{ 0, false, 0, 0, 0, 0, 0 } };
Nicholas Piggin631bc462017-03-14 22:36:46 +1000271
272static const struct mce_derror_table mce_p8_derror_table[] = {
273{ 0x00008000, false,
274 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_LOAD_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530275 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000276{ 0x00004000, true,
277 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530278 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000279{ 0x00002000, true,
280 MCE_ERROR_TYPE_LINK, MCE_LINK_ERROR_LOAD_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530281 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Pigginc7e790c2017-03-14 22:36:48 +1000282{ 0x00001000, true,
283 MCE_ERROR_TYPE_LINK, MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530284 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000285{ 0x00000800, true,
286 MCE_ERROR_TYPE_ERAT, MCE_ERAT_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530287 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000288{ 0x00000400, true,
289 MCE_ERROR_TYPE_TLB, MCE_TLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530290 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000291{ 0x00000200, true,
292 MCE_ERROR_TYPE_ERAT, MCE_ERAT_ERROR_MULTIHIT, /* SECONDARY ERAT */
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530293 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Michael Ellerman54dbcfc2018-06-13 23:24:14 +1000294{ 0x00000080, true,
295 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_MULTIHIT, /* Before PARITY */
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530296 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000297{ 0x00000100, true,
298 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_PARITY,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530299 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
300{ 0, false, 0, 0, 0, 0, 0 } };
Nicholas Piggin631bc462017-03-14 22:36:46 +1000301
302static const struct mce_derror_table mce_p9_derror_table[] = {
303{ 0x00008000, false,
304 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_LOAD_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530305 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000306{ 0x00004000, true,
307 MCE_ERROR_TYPE_UE, MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530308 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000309{ 0x00002000, true,
310 MCE_ERROR_TYPE_LINK, MCE_LINK_ERROR_LOAD_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530311 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000312{ 0x00001000, true,
313 MCE_ERROR_TYPE_LINK, MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530314 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000315{ 0x00000800, true,
316 MCE_ERROR_TYPE_ERAT, MCE_ERAT_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530317 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000318{ 0x00000400, true,
319 MCE_ERROR_TYPE_TLB, MCE_TLB_ERROR_MULTIHIT,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530320 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000321{ 0x00000200, false,
322 MCE_ERROR_TYPE_USER, MCE_USER_ERROR_TLBIE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530323 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Michael Ellerman54dbcfc2018-06-13 23:24:14 +1000324{ 0x00000080, true,
325 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_MULTIHIT, /* Before PARITY */
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530326 MCE_INITIATOR_CPU, MCE_SEV_WARNING, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000327{ 0x00000100, true,
328 MCE_ERROR_TYPE_SLB, MCE_SLB_ERROR_PARITY,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530329 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000330{ 0x00000040, true,
331 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_LOAD,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530332 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000333{ 0x00000020, false,
334 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530335 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000336{ 0x00000010, false,
337 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE_FOREIGN,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530338 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
Nicholas Piggin631bc462017-03-14 22:36:46 +1000339{ 0x00000008, false,
340 MCE_ERROR_TYPE_RA, MCE_RA_ERROR_LOAD_STORE_FOREIGN,
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530341 MCE_INITIATOR_CPU, MCE_SEV_SEVERE, true },
342{ 0, false, 0, 0, 0, 0, 0 } };
Nicholas Piggin631bc462017-03-14 22:36:46 +1000343
Balbir Singhba41e1e2017-09-29 14:26:53 +1000344static int mce_find_instr_ea_and_pfn(struct pt_regs *regs, uint64_t *addr,
345 uint64_t *phys_addr)
346{
347 /*
348 * Carefully look at the NIP to determine
349 * the instruction to analyse. Reading the NIP
350 * in real-mode is tricky and can lead to recursive
351 * faults
352 */
353 int instr;
354 unsigned long pfn, instr_addr;
355 struct instruction_op op;
356 struct pt_regs tmp = *regs;
357
358 pfn = addr_to_pfn(regs, regs->nip);
359 if (pfn != ULONG_MAX) {
360 instr_addr = (pfn << PAGE_SHIFT) + (regs->nip & ~PAGE_MASK);
361 instr = *(unsigned int *)(instr_addr);
362 if (!analyse_instr(&op, &tmp, instr)) {
363 pfn = addr_to_pfn(regs, op.ea);
364 *addr = op.ea;
365 *phys_addr = (pfn << PAGE_SHIFT);
366 return 0;
367 }
368 /*
369 * analyse_instr() might fail if the instruction
370 * is not a load/store, although this is unexpected
371 * for load/store errors or if we got the NIP
372 * wrong
373 */
374 }
375 *addr = 0;
376 return -1;
377}
378
Nicholas Piggin755309b2017-03-14 22:36:47 +1000379static int mce_handle_ierror(struct pt_regs *regs,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000380 const struct mce_ierror_table table[],
Balbir Singh01eaac22017-09-29 14:26:54 +1000381 struct mce_error_info *mce_err, uint64_t *addr,
382 uint64_t *phys_addr)
Nicholas Piggin631bc462017-03-14 22:36:46 +1000383{
384 uint64_t srr1 = regs->msr;
Nicholas Piggin755309b2017-03-14 22:36:47 +1000385 int handled = 0;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000386 int i;
387
388 *addr = 0;
389
390 for (i = 0; table[i].srr1_mask; i++) {
391 if ((srr1 & table[i].srr1_mask) != table[i].srr1_value)
392 continue;
393
Nicholas Piggin755309b2017-03-14 22:36:47 +1000394 /* attempt to correct the error */
395 switch (table[i].error_type) {
396 case MCE_ERROR_TYPE_SLB:
397 handled = mce_flush(MCE_FLUSH_SLB);
398 break;
399 case MCE_ERROR_TYPE_ERAT:
400 handled = mce_flush(MCE_FLUSH_ERAT);
401 break;
402 case MCE_ERROR_TYPE_TLB:
403 handled = mce_flush(MCE_FLUSH_TLB);
404 break;
405 }
406
407 /* now fill in mce_error_info */
Nicholas Piggin631bc462017-03-14 22:36:46 +1000408 mce_err->error_type = table[i].error_type;
409 switch (table[i].error_type) {
410 case MCE_ERROR_TYPE_UE:
411 mce_err->u.ue_error_type = table[i].error_subtype;
412 break;
413 case MCE_ERROR_TYPE_SLB:
414 mce_err->u.slb_error_type = table[i].error_subtype;
415 break;
416 case MCE_ERROR_TYPE_ERAT:
417 mce_err->u.erat_error_type = table[i].error_subtype;
418 break;
419 case MCE_ERROR_TYPE_TLB:
420 mce_err->u.tlb_error_type = table[i].error_subtype;
421 break;
422 case MCE_ERROR_TYPE_USER:
423 mce_err->u.user_error_type = table[i].error_subtype;
424 break;
425 case MCE_ERROR_TYPE_RA:
426 mce_err->u.ra_error_type = table[i].error_subtype;
427 break;
428 case MCE_ERROR_TYPE_LINK:
429 mce_err->u.link_error_type = table[i].error_subtype;
430 break;
431 }
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530432 mce_err->sync_error = table[i].sync_error;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000433 mce_err->severity = table[i].severity;
434 mce_err->initiator = table[i].initiator;
Balbir Singh01eaac22017-09-29 14:26:54 +1000435 if (table[i].nip_valid) {
Nicholas Piggin631bc462017-03-14 22:36:46 +1000436 *addr = regs->nip;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530437 if (mce_err->sync_error &&
Balbir Singh01eaac22017-09-29 14:26:54 +1000438 table[i].error_type == MCE_ERROR_TYPE_UE) {
439 unsigned long pfn;
440
441 if (get_paca()->in_mce < MAX_MCE_DEPTH) {
442 pfn = addr_to_pfn(regs, regs->nip);
443 if (pfn != ULONG_MAX) {
444 *phys_addr =
445 (pfn << PAGE_SHIFT);
Balbir Singh01eaac22017-09-29 14:26:54 +1000446 }
447 }
448 }
449 }
Nicholas Piggin755309b2017-03-14 22:36:47 +1000450 return handled;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000451 }
452
453 mce_err->error_type = MCE_ERROR_TYPE_UNKNOWN;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530454 mce_err->severity = MCE_SEV_SEVERE;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000455 mce_err->initiator = MCE_INITIATOR_CPU;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530456 mce_err->sync_error = true;
Nicholas Piggin755309b2017-03-14 22:36:47 +1000457
458 return 0;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000459}
460
Nicholas Piggin755309b2017-03-14 22:36:47 +1000461static int mce_handle_derror(struct pt_regs *regs,
Nicholas Piggin631bc462017-03-14 22:36:46 +1000462 const struct mce_derror_table table[],
Balbir Singhba41e1e2017-09-29 14:26:53 +1000463 struct mce_error_info *mce_err, uint64_t *addr,
464 uint64_t *phys_addr)
Nicholas Piggin631bc462017-03-14 22:36:46 +1000465{
466 uint64_t dsisr = regs->dsisr;
Nicholas Piggin755309b2017-03-14 22:36:47 +1000467 int handled = 0;
468 int found = 0;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000469 int i;
470
471 *addr = 0;
472
473 for (i = 0; table[i].dsisr_value; i++) {
474 if (!(dsisr & table[i].dsisr_value))
475 continue;
476
Nicholas Piggin755309b2017-03-14 22:36:47 +1000477 /* attempt to correct the error */
478 switch (table[i].error_type) {
479 case MCE_ERROR_TYPE_SLB:
480 if (mce_flush(MCE_FLUSH_SLB))
481 handled = 1;
482 break;
483 case MCE_ERROR_TYPE_ERAT:
484 if (mce_flush(MCE_FLUSH_ERAT))
485 handled = 1;
486 break;
487 case MCE_ERROR_TYPE_TLB:
488 if (mce_flush(MCE_FLUSH_TLB))
489 handled = 1;
490 break;
491 }
492
493 /*
494 * Attempt to handle multiple conditions, but only return
495 * one. Ensure uncorrectable errors are first in the table
496 * to match.
497 */
498 if (found)
499 continue;
500
501 /* now fill in mce_error_info */
Nicholas Piggin631bc462017-03-14 22:36:46 +1000502 mce_err->error_type = table[i].error_type;
503 switch (table[i].error_type) {
504 case MCE_ERROR_TYPE_UE:
505 mce_err->u.ue_error_type = table[i].error_subtype;
506 break;
507 case MCE_ERROR_TYPE_SLB:
508 mce_err->u.slb_error_type = table[i].error_subtype;
509 break;
510 case MCE_ERROR_TYPE_ERAT:
511 mce_err->u.erat_error_type = table[i].error_subtype;
512 break;
513 case MCE_ERROR_TYPE_TLB:
514 mce_err->u.tlb_error_type = table[i].error_subtype;
515 break;
516 case MCE_ERROR_TYPE_USER:
517 mce_err->u.user_error_type = table[i].error_subtype;
518 break;
519 case MCE_ERROR_TYPE_RA:
520 mce_err->u.ra_error_type = table[i].error_subtype;
521 break;
522 case MCE_ERROR_TYPE_LINK:
523 mce_err->u.link_error_type = table[i].error_subtype;
524 break;
525 }
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530526 mce_err->sync_error = table[i].sync_error;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000527 mce_err->severity = table[i].severity;
528 mce_err->initiator = table[i].initiator;
529 if (table[i].dar_valid)
530 *addr = regs->dar;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530531 else if (mce_err->sync_error &&
Balbir Singhba41e1e2017-09-29 14:26:53 +1000532 table[i].error_type == MCE_ERROR_TYPE_UE) {
533 /*
534 * We do a maximum of 4 nested MCE calls, see
535 * kernel/exception-64s.h
536 */
537 if (get_paca()->in_mce < MAX_MCE_DEPTH)
Mahesh Salgaonkar75ecfb42018-04-23 10:29:27 +0530538 mce_find_instr_ea_and_pfn(regs, addr, phys_addr);
Balbir Singhba41e1e2017-09-29 14:26:53 +1000539 }
Nicholas Piggin755309b2017-03-14 22:36:47 +1000540 found = 1;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000541 }
542
Nicholas Piggin755309b2017-03-14 22:36:47 +1000543 if (found)
544 return handled;
545
Nicholas Piggin631bc462017-03-14 22:36:46 +1000546 mce_err->error_type = MCE_ERROR_TYPE_UNKNOWN;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530547 mce_err->severity = MCE_SEV_SEVERE;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000548 mce_err->initiator = MCE_INITIATOR_CPU;
Mahesh Salgaonkarcda66182019-04-29 23:45:55 +0530549 mce_err->sync_error = true;
Nicholas Piggin755309b2017-03-14 22:36:47 +1000550
551 return 0;
Nicholas Piggin631bc462017-03-14 22:36:46 +1000552}
553
554static long mce_handle_ue_error(struct pt_regs *regs)
555{
556 long handled = 0;
557
558 /*
559 * On specific SCOM read via MMIO we may get a machine check
560 * exception with SRR0 pointing inside opal. If that is the
561 * case OPAL may have recovery address to re-read SCOM data in
562 * different way and hence we can recover from this MC.
563 */
564
565 if (ppc_md.mce_check_early_recovery) {
566 if (ppc_md.mce_check_early_recovery(regs))
567 handled = 1;
568 }
569 return handled;
570}
571
Nicholas Piggin755309b2017-03-14 22:36:47 +1000572static long mce_handle_error(struct pt_regs *regs,
573 const struct mce_derror_table dtable[],
574 const struct mce_ierror_table itable[])
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +0530575{
Nicholas Piggin755309b2017-03-14 22:36:47 +1000576 struct mce_error_info mce_err = { 0 };
Mahesh Salgaonkar75ecfb42018-04-23 10:29:27 +0530577 uint64_t addr, phys_addr = ULONG_MAX;
Nicholas Piggin755309b2017-03-14 22:36:47 +1000578 uint64_t srr1 = regs->msr;
579 long handled;
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +0530580
Nicholas Piggin755309b2017-03-14 22:36:47 +1000581 if (SRR1_MC_LOADSTORE(srr1))
Balbir Singhba41e1e2017-09-29 14:26:53 +1000582 handled = mce_handle_derror(regs, dtable, &mce_err, &addr,
583 &phys_addr);
Nicholas Piggin755309b2017-03-14 22:36:47 +1000584 else
Balbir Singh01eaac22017-09-29 14:26:54 +1000585 handled = mce_handle_ierror(regs, itable, &mce_err, &addr,
586 &phys_addr);
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +0530587
Nicholas Piggin755309b2017-03-14 22:36:47 +1000588 if (!handled && mce_err.error_type == MCE_ERROR_TYPE_UE)
589 handled = mce_handle_ue_error(regs);
590
Balbir Singhba41e1e2017-09-29 14:26:53 +1000591 save_mce_event(regs, handled, &mce_err, regs->nip, addr, phys_addr);
Nicholas Piggin755309b2017-03-14 22:36:47 +1000592
593 return handled;
Mahesh Salgaonkare22a2272013-10-30 20:05:11 +0530594}
595
596long __machine_check_early_realmode_p7(struct pt_regs *regs)
597{
Nicholas Piggin631bc462017-03-14 22:36:46 +1000598 /* P7 DD1 leaves top bits of DSISR undefined */
599 regs->dsisr &= 0x0000ffff;
600
Nicholas Piggin755309b2017-03-14 22:36:47 +1000601 return mce_handle_error(regs, mce_p7_derror_table, mce_p7_ierror_table);
Mahesh Salgaonkarae744f32013-10-30 20:05:26 +0530602}
603
604long __machine_check_early_realmode_p8(struct pt_regs *regs)
605{
Nicholas Piggin755309b2017-03-14 22:36:47 +1000606 return mce_handle_error(regs, mce_p8_derror_table, mce_p8_ierror_table);
Nicholas Piggin7b9f71f92017-02-28 12:00:48 +1000607}
608
Nicholas Piggin7b9f71f92017-02-28 12:00:48 +1000609long __machine_check_early_realmode_p9(struct pt_regs *regs)
610{
Michael Neulingd8bd9f32017-09-22 13:32:21 +1000611 /*
612 * On POWER9 DD2.1 and below, it's possible to get a machine check
Michael Neulingbca73f52017-09-28 22:37:35 -0500613 * caused by a paste instruction where only DSISR bit 25 is set. This
Michael Neulingd8bd9f32017-09-22 13:32:21 +1000614 * will result in the MCE handler seeing an unknown event and the kernel
615 * crashing. An MCE that occurs like this is spurious, so we don't need
616 * to do anything in terms of servicing it. If there is something that
617 * needs to be serviced, the CPU will raise the MCE again with the
618 * correct DSISR so that it can be serviced properly. So detect this
619 * case and mark it as handled.
620 */
Michael Neulingbca73f52017-09-28 22:37:35 -0500621 if (SRR1_MC_LOADSTORE(regs->msr) && regs->dsisr == 0x02000000)
Michael Neulingd8bd9f32017-09-22 13:32:21 +1000622 return 1;
623
Nicholas Piggin755309b2017-03-14 22:36:47 +1000624 return mce_handle_error(regs, mce_p9_derror_table, mce_p9_ierror_table);
Nicholas Piggin7b9f71f92017-02-28 12:00:48 +1000625}