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>
31 static void flush_tlb_206(unsigned int num_sets, unsigned int action)
37 case TLB_INVAL_SCOPE_GLOBAL:
38 rb = TLBIEL_INVAL_SET;
40 case TLB_INVAL_SCOPE_LPID:
41 rb = TLBIEL_INVAL_SET_LPID;
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;
53 asm volatile("ptesync" : : : "memory");
57 * Generic routines to flush TLB on POWER processors. These routines
58 * are used as flush_tlb hook in the cpu_spec.
60 * action => TLB_INVAL_SCOPE_GLOBAL: Invalidate all TLBs.
61 * TLB_INVAL_SCOPE_LPID: Invalidate TLB for current LPID.
63 void __flush_tlb_power7(unsigned int action)
65 flush_tlb_206(POWER7_TLB_SETS, action);
68 void __flush_tlb_power8(unsigned int action)
70 flush_tlb_206(POWER8_TLB_SETS, action);
73 void __flush_tlb_power9(unsigned int action)
76 flush_tlb_206(POWER9_TLB_SETS_RADIX, action);
78 flush_tlb_206(POWER9_TLB_SETS_HASH, action);
82 /* flush SLBs and reload */
83 static void flush_and_reload_slb(void)
85 struct slb_shadow *slb;
88 /* Invalidate all SLBs */
89 asm volatile("slbmte %0,%0; slbia" : : "r" (0));
91 #ifdef CONFIG_KVM_BOOK3S_HANDLER
93 * If machine check is hit when in guest or in transition, we will
94 * only flush the SLBs and continue.
96 if (get_paca()->kvm_hstate.in_guest)
100 /* For host kernel, reload the SLBs from shadow SLB buffer. */
101 slb = get_slb_shadow();
105 n = min_t(u32, be32_to_cpu(slb->persistent), SLB_MIN_SIZE);
107 /* Load up the SLB entries from shadow SLB */
108 for (i = 0; i < n; i++) {
109 unsigned long rb = be64_to_cpu(slb->save_area[i].esid);
110 unsigned long rs = be64_to_cpu(slb->save_area[i].vsid);
112 rb = (rb & ~0xFFFul) | i;
113 asm volatile("slbmte %0,%1" : : "r" (rs), "r" (rb));
117 static long mce_handle_derror(uint64_t dsisr, uint64_t slb_error_bits)
122 * flush and reload SLBs for SLB errors and flush TLBs for TLB errors.
123 * reset the error bits whenever we handle them so that at the end
124 * we can check whether we handled all of them or not.
126 if (dsisr & slb_error_bits) {
127 flush_and_reload_slb();
128 /* reset error bits */
129 dsisr &= ~(slb_error_bits);
131 if (dsisr & P7_DSISR_MC_TLB_MULTIHIT_MFTLB) {
132 if (cur_cpu_spec && cur_cpu_spec->flush_tlb)
133 cur_cpu_spec->flush_tlb(TLB_INVAL_SCOPE_GLOBAL);
134 /* reset error bits */
135 dsisr &= ~P7_DSISR_MC_TLB_MULTIHIT_MFTLB;
137 /* Any other errors we don't understand? */
138 if (dsisr & 0xffffffffUL)
144 static long mce_handle_derror_p7(uint64_t dsisr)
146 return mce_handle_derror(dsisr, P7_DSISR_MC_SLB_ERRORS);
149 static long mce_handle_common_ierror(uint64_t srr1)
153 switch (P7_SRR1_MC_IFETCH(srr1)) {
156 case P7_SRR1_MC_IFETCH_SLB_PARITY:
157 case P7_SRR1_MC_IFETCH_SLB_MULTIHIT:
158 /* flush and reload SLBs for SLB errors. */
159 flush_and_reload_slb();
162 case P7_SRR1_MC_IFETCH_TLB_MULTIHIT:
163 if (cur_cpu_spec && cur_cpu_spec->flush_tlb) {
164 cur_cpu_spec->flush_tlb(TLB_INVAL_SCOPE_GLOBAL);
175 static long mce_handle_ierror_p7(uint64_t srr1)
179 handled = mce_handle_common_ierror(srr1);
181 if (P7_SRR1_MC_IFETCH(srr1) == P7_SRR1_MC_IFETCH_SLB_BOTH) {
182 flush_and_reload_slb();
188 static void mce_get_common_ierror(struct mce_error_info *mce_err, uint64_t srr1)
190 switch (P7_SRR1_MC_IFETCH(srr1)) {
191 case P7_SRR1_MC_IFETCH_SLB_PARITY:
192 mce_err->error_type = MCE_ERROR_TYPE_SLB;
193 mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY;
195 case P7_SRR1_MC_IFETCH_SLB_MULTIHIT:
196 mce_err->error_type = MCE_ERROR_TYPE_SLB;
197 mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT;
199 case P7_SRR1_MC_IFETCH_TLB_MULTIHIT:
200 mce_err->error_type = MCE_ERROR_TYPE_TLB;
201 mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT;
203 case P7_SRR1_MC_IFETCH_UE:
204 case P7_SRR1_MC_IFETCH_UE_IFU_INTERNAL:
205 mce_err->error_type = MCE_ERROR_TYPE_UE;
206 mce_err->u.ue_error_type = MCE_UE_ERROR_IFETCH;
208 case P7_SRR1_MC_IFETCH_UE_TLB_RELOAD:
209 mce_err->error_type = MCE_ERROR_TYPE_UE;
210 mce_err->u.ue_error_type =
211 MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH;
216 static void mce_get_ierror_p7(struct mce_error_info *mce_err, uint64_t srr1)
218 mce_get_common_ierror(mce_err, srr1);
219 if (P7_SRR1_MC_IFETCH(srr1) == P7_SRR1_MC_IFETCH_SLB_BOTH) {
220 mce_err->error_type = MCE_ERROR_TYPE_SLB;
221 mce_err->u.slb_error_type = MCE_SLB_ERROR_INDETERMINATE;
225 static void mce_get_derror_p7(struct mce_error_info *mce_err, uint64_t dsisr)
227 if (dsisr & P7_DSISR_MC_UE) {
228 mce_err->error_type = MCE_ERROR_TYPE_UE;
229 mce_err->u.ue_error_type = MCE_UE_ERROR_LOAD_STORE;
230 } else if (dsisr & P7_DSISR_MC_UE_TABLEWALK) {
231 mce_err->error_type = MCE_ERROR_TYPE_UE;
232 mce_err->u.ue_error_type =
233 MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE;
234 } else if (dsisr & P7_DSISR_MC_ERAT_MULTIHIT) {
235 mce_err->error_type = MCE_ERROR_TYPE_ERAT;
236 mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
237 } else if (dsisr & P7_DSISR_MC_SLB_MULTIHIT) {
238 mce_err->error_type = MCE_ERROR_TYPE_SLB;
239 mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT;
240 } else if (dsisr & P7_DSISR_MC_SLB_PARITY_MFSLB) {
241 mce_err->error_type = MCE_ERROR_TYPE_SLB;
242 mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY;
243 } else if (dsisr & P7_DSISR_MC_TLB_MULTIHIT_MFTLB) {
244 mce_err->error_type = MCE_ERROR_TYPE_TLB;
245 mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT;
246 } else if (dsisr & P7_DSISR_MC_SLB_MULTIHIT_PARITY) {
247 mce_err->error_type = MCE_ERROR_TYPE_SLB;
248 mce_err->u.slb_error_type = MCE_SLB_ERROR_INDETERMINATE;
252 static long mce_handle_ue_error(struct pt_regs *regs)
257 * On specific SCOM read via MMIO we may get a machine check
258 * exception with SRR0 pointing inside opal. If that is the
259 * case OPAL may have recovery address to re-read SCOM data in
260 * different way and hence we can recover from this MC.
263 if (ppc_md.mce_check_early_recovery) {
264 if (ppc_md.mce_check_early_recovery(regs))
270 long __machine_check_early_realmode_p7(struct pt_regs *regs)
272 uint64_t srr1, nip, addr;
274 struct mce_error_info mce_error_info = { 0 };
280 * Handle memory errors depending whether this was a load/store or
281 * ifetch exception. Also, populate the mce error_type and
282 * type-specific error_type from either SRR1 or DSISR, depending
283 * whether this was a load/store or ifetch exception
285 if (P7_SRR1_MC_LOADSTORE(srr1)) {
286 handled = mce_handle_derror_p7(regs->dsisr);
287 mce_get_derror_p7(&mce_error_info, regs->dsisr);
290 handled = mce_handle_ierror_p7(srr1);
291 mce_get_ierror_p7(&mce_error_info, srr1);
295 /* Handle UE error. */
296 if (mce_error_info.error_type == MCE_ERROR_TYPE_UE)
297 handled = mce_handle_ue_error(regs);
299 save_mce_event(regs, handled, &mce_error_info, nip, addr);
303 static void mce_get_ierror_p8(struct mce_error_info *mce_err, uint64_t srr1)
305 mce_get_common_ierror(mce_err, srr1);
306 if (P7_SRR1_MC_IFETCH(srr1) == P8_SRR1_MC_IFETCH_ERAT_MULTIHIT) {
307 mce_err->error_type = MCE_ERROR_TYPE_ERAT;
308 mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
312 static void mce_get_derror_p8(struct mce_error_info *mce_err, uint64_t dsisr)
314 mce_get_derror_p7(mce_err, dsisr);
315 if (dsisr & P8_DSISR_MC_ERAT_MULTIHIT_SEC) {
316 mce_err->error_type = MCE_ERROR_TYPE_ERAT;
317 mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
321 static long mce_handle_ierror_p8(uint64_t srr1)
325 handled = mce_handle_common_ierror(srr1);
327 if (P7_SRR1_MC_IFETCH(srr1) == P8_SRR1_MC_IFETCH_ERAT_MULTIHIT) {
328 flush_and_reload_slb();
334 static long mce_handle_derror_p8(uint64_t dsisr)
336 return mce_handle_derror(dsisr, P8_DSISR_MC_SLB_ERRORS);
339 long __machine_check_early_realmode_p8(struct pt_regs *regs)
341 uint64_t srr1, nip, addr;
343 struct mce_error_info mce_error_info = { 0 };
348 if (P7_SRR1_MC_LOADSTORE(srr1)) {
349 handled = mce_handle_derror_p8(regs->dsisr);
350 mce_get_derror_p8(&mce_error_info, regs->dsisr);
353 handled = mce_handle_ierror_p8(srr1);
354 mce_get_ierror_p8(&mce_error_info, srr1);
358 /* Handle UE error. */
359 if (mce_error_info.error_type == MCE_ERROR_TYPE_UE)
360 handled = mce_handle_ue_error(regs);
362 save_mce_event(regs, handled, &mce_error_info, nip, addr);