blob: cd7972ede1d6f9b80f5a1e9b2e1c8296062a3422 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * File: mca_drv.c
4 * Purpose: Generic MCA handling layer
5 *
6 * Copyright (C) 2004 FUJITSU LIMITED
Hidetoshi Setofe77efb2008-01-07 10:11:57 +09007 * Copyright (C) 2004 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Keith Owens7f613c72005-09-11 17:22:53 +10008 * Copyright (C) 2005 Silicon Graphics, Inc
9 * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
Russ Andersond2a28ad2006-03-24 09:49:52 -080010 * Copyright (C) 2006 Russ Anderson <rja@sgi.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/types.h>
13#include <linux/init.h>
14#include <linux/sched.h>
15#include <linux/interrupt.h>
16#include <linux/irq.h>
17#include <linux/kallsyms.h>
Mike Rapoport57c8a662018-10-30 15:09:49 -070018#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/acpi.h>
20#include <linux/timer.h>
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/smp.h>
24#include <linux/workqueue.h>
25#include <linux/mm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <asm/delay.h>
29#include <asm/machvec.h>
30#include <asm/page.h>
31#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/sal.h>
33#include <asm/mca.h>
34
35#include <asm/irq.h>
36#include <asm/hw_irq.h>
37
38#include "mca_drv.h"
39
40/* max size of SAL error record (default) */
41static int sal_rec_max = 10000;
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/* from mca_drv_asm.S */
44extern void *mca_handler_bhhook(void);
45
46static DEFINE_SPINLOCK(mca_bh_lock);
47
48typedef enum {
49 MCA_IS_LOCAL = 0,
50 MCA_IS_GLOBAL = 1
51} mca_type_t;
52
53#define MAX_PAGE_ISOLATE 1024
54
55static struct page *page_isolate[MAX_PAGE_ISOLATE];
56static int num_page_isolate = 0;
57
58typedef enum {
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +090059 ISOLATE_NG,
60 ISOLATE_OK,
61 ISOLATE_NONE
Linus Torvalds1da177e2005-04-16 15:20:36 -070062} isolate_status_t;
63
Russ Anderson18997962006-04-27 10:07:08 -050064typedef enum {
65 MCA_NOT_RECOVERED = 0,
66 MCA_RECOVERED = 1
67} recovery_status_t;
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/*
70 * This pool keeps pointers to the section part of SAL error record
71 */
72static struct {
73 slidx_list_t *buffer; /* section pointer list pool */
74 int cur_idx; /* Current index of section pointer list pool */
75 int max_idx; /* Maximum index of section pointer list pool */
76} slidx_pool;
77
Russ Anderson18997962006-04-27 10:07:08 -050078static int
79fatal_mca(const char *fmt, ...)
80{
81 va_list args;
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070082 char buf[256];
Russ Anderson18997962006-04-27 10:07:08 -050083
84 va_start(args, fmt);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070085 vsnprintf(buf, sizeof(buf), fmt, args);
Russ Anderson18997962006-04-27 10:07:08 -050086 va_end(args);
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070087 ia64_mca_printk(KERN_ALERT "MCA: %s\n", buf);
Russ Anderson18997962006-04-27 10:07:08 -050088
89 return MCA_NOT_RECOVERED;
90}
91
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -070092static int
93mca_recovered(const char *fmt, ...)
94{
95 va_list args;
96 char buf[256];
97
98 va_start(args, fmt);
99 vsnprintf(buf, sizeof(buf), fmt, args);
100 va_end(args);
101 ia64_mca_printk(KERN_INFO "MCA: %s\n", buf);
102
103 return MCA_RECOVERED;
104}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/**
107 * mca_page_isolate - isolate a poisoned page in order not to use it later
108 * @paddr: poisoned memory location
109 *
110 * Return value:
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900111 * one of isolate_status_t, ISOLATE_OK/NG/NONE.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 */
113
114static isolate_status_t
115mca_page_isolate(unsigned long paddr)
116{
117 int i;
118 struct page *p;
119
120 /* whether physical address is valid or not */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900121 if (!ia64_phys_addr_valid(paddr))
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900122 return ISOLATE_NONE;
123
Russ Anderson56f87b82005-11-04 13:57:00 -0600124 if (!pfn_valid(paddr >> PAGE_SHIFT))
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900125 return ISOLATE_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /* convert physical address to physical page number */
128 p = pfn_to_page(paddr>>PAGE_SHIFT);
129
130 /* check whether a page number have been already registered or not */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900131 for (i = 0; i < num_page_isolate; i++)
132 if (page_isolate[i] == p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return ISOLATE_OK; /* already listed */
134
135 /* limitation check */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900136 if (num_page_isolate == MAX_PAGE_ISOLATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return ISOLATE_NG;
138
139 /* kick pages having attribute 'SLAB' or 'Reserved' */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900140 if (PageSlab(p) || PageReserved(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return ISOLATE_NG;
142
143 /* add attribute 'Reserved' and register the page */
Russ Andersoncbb92142005-11-04 16:58:28 -0600144 get_page(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 SetPageReserved(p);
146 page_isolate[num_page_isolate++] = p;
147
148 return ISOLATE_OK;
149}
150
151/**
152 * mca_hanlder_bh - Kill the process which occurred memory read error
153 * @paddr: poisoned address received from MCA Handler
154 */
155
156void
Russ Andersond2a28ad2006-03-24 09:49:52 -0800157mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700159 ia64_mlogbuf_dump();
Russ Andersond2a28ad2006-03-24 09:49:52 -0800160 printk(KERN_ERR "OS_MCA: process [cpu %d, pid: %d, uid: %d, "
161 "iip: %p, psr: 0x%lx,paddr: 0x%lx](%s) encounters MCA.\n",
Eric W. Biederman6c1ee032012-08-07 04:02:41 -0700162 raw_smp_processor_id(), current->pid,
163 from_kuid(&init_user_ns, current_uid()),
Russ Andersond2a28ad2006-03-24 09:49:52 -0800164 iip, ipsr, paddr, current->comm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 spin_lock(&mca_bh_lock);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900167 switch (mca_page_isolate(paddr)) {
168 case ISOLATE_OK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900170 break;
171 case ISOLATE_NG:
Russ Andersonea0e92a2006-03-07 15:23:25 -0800172 printk(KERN_CRIT "Page isolation: ( %lx ) failure.\n", paddr);
Hidetoshi Seto4881e2c2005-09-20 16:34:41 +0900173 break;
174 default:
175 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177 spin_unlock(&mca_bh_lock);
178
179 /* This process is about to be killed itself */
Russ Andersonb1b901c2005-04-06 00:07:00 -0700180 do_exit(SIGKILL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
183/**
184 * mca_make_peidx - Make index of processor error section
185 * @slpi: pointer to record of processor error section
186 * @peidx: pointer to index of processor error section
187 */
188
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900189static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx)
191{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900192 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 * calculate the start address of
194 * "struct cpuid_info" and "sal_processor_static_info_t".
195 */
196 u64 total_check_num = slpi->valid.num_cache_check
197 + slpi->valid.num_tlb_check
198 + slpi->valid.num_bus_check
199 + slpi->valid.num_reg_file_check
200 + slpi->valid.num_ms_check;
201 u64 head_size = sizeof(sal_log_mod_error_info_t) * total_check_num
202 + sizeof(sal_log_processor_info_t);
203 u64 mid_size = slpi->valid.cpuid_info * sizeof(struct sal_cpuid_info);
204
205 peidx_head(peidx) = slpi;
206 peidx_mid(peidx) = (struct sal_cpuid_info *)
207 (slpi->valid.cpuid_info ? ((char*)slpi + head_size) : NULL);
208 peidx_bottom(peidx) = (sal_processor_static_info_t *)
209 (slpi->valid.psi_static_struct ?
210 ((char*)slpi + head_size + mid_size) : NULL);
211}
212
213/**
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900214 * mca_make_slidx - Make index of SAL error record
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 * @buffer: pointer to SAL error record
216 * @slidx: pointer to index of SAL error record
217 *
218 * Return value:
219 * 1 if record has platform error / 0 if not
220 */
221#define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900222 {slidx_list_t *hl = &slidx_pool.buffer[slidx_pool.cur_idx]; \
223 hl->hdr = ptr; \
224 list_add(&hl->list, &(sect)); \
225 slidx_pool.cur_idx = (slidx_pool.cur_idx + 1)%slidx_pool.max_idx; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900227static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228mca_make_slidx(void *buffer, slidx_table_t *slidx)
229{
230 int platform_err = 0;
231 int record_len = ((sal_log_record_header_t*)buffer)->len;
232 u32 ercd_pos;
233 int sects;
234 sal_log_section_hdr_t *sp;
235
236 /*
237 * Initialize index referring current record
238 */
239 INIT_LIST_HEAD(&(slidx->proc_err));
240 INIT_LIST_HEAD(&(slidx->mem_dev_err));
241 INIT_LIST_HEAD(&(slidx->sel_dev_err));
242 INIT_LIST_HEAD(&(slidx->pci_bus_err));
243 INIT_LIST_HEAD(&(slidx->smbios_dev_err));
244 INIT_LIST_HEAD(&(slidx->pci_comp_err));
245 INIT_LIST_HEAD(&(slidx->plat_specific_err));
246 INIT_LIST_HEAD(&(slidx->host_ctlr_err));
247 INIT_LIST_HEAD(&(slidx->plat_bus_err));
248 INIT_LIST_HEAD(&(slidx->unsupported));
249
250 /*
251 * Extract a Record Header
252 */
253 slidx->header = buffer;
254
255 /*
256 * Extract each section records
257 * (arranged from "int ia64_log_platform_info_print()")
258 */
259 for (ercd_pos = sizeof(sal_log_record_header_t), sects = 0;
260 ercd_pos < record_len; ercd_pos += sp->len, sects++) {
261 sp = (sal_log_section_hdr_t *)((char*)buffer + ercd_pos);
262 if (!efi_guidcmp(sp->guid, SAL_PROC_DEV_ERR_SECT_GUID)) {
263 LOG_INDEX_ADD_SECT_PTR(slidx->proc_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900264 } else if (!efi_guidcmp(sp->guid,
265 SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 platform_err = 1;
267 LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900268 } else if (!efi_guidcmp(sp->guid,
269 SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 platform_err = 1;
271 LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900272 } else if (!efi_guidcmp(sp->guid,
273 SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 platform_err = 1;
275 LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900276 } else if (!efi_guidcmp(sp->guid,
277 SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 platform_err = 1;
279 LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900280 } else if (!efi_guidcmp(sp->guid,
281 SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 platform_err = 1;
283 LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900284 } else if (!efi_guidcmp(sp->guid,
285 SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 platform_err = 1;
287 LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900288 } else if (!efi_guidcmp(sp->guid,
289 SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 platform_err = 1;
291 LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp);
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900292 } else if (!efi_guidcmp(sp->guid,
293 SAL_PLAT_BUS_ERR_SECT_GUID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 platform_err = 1;
295 LOG_INDEX_ADD_SECT_PTR(slidx->plat_bus_err, sp);
296 } else {
297 LOG_INDEX_ADD_SECT_PTR(slidx->unsupported, sp);
298 }
299 }
300 slidx->n_sections = sects;
301
302 return platform_err;
303}
304
305/**
306 * init_record_index_pools - Initialize pool of lists for SAL record index
307 *
308 * Return value:
309 * 0 on Success / -ENOMEM on Failure
310 */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900311static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312init_record_index_pools(void)
313{
314 int i;
315 int rec_max_size; /* Maximum size of SAL error records */
316 int sect_min_size; /* Minimum size of SAL error sections */
317 /* minimum size table of each section */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900318 static int sal_log_sect_min_sizes[] = {
319 sizeof(sal_log_processor_info_t)
320 + sizeof(sal_processor_static_info_t),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 sizeof(sal_log_mem_dev_err_info_t),
322 sizeof(sal_log_sel_dev_err_info_t),
323 sizeof(sal_log_pci_bus_err_info_t),
324 sizeof(sal_log_smbios_dev_err_info_t),
325 sizeof(sal_log_pci_comp_err_info_t),
326 sizeof(sal_log_plat_specific_err_info_t),
327 sizeof(sal_log_host_ctlr_err_info_t),
328 sizeof(sal_log_plat_bus_err_info_t),
329 };
330
331 /*
332 * MCA handler cannot allocate new memory on flight,
333 * so we preallocate enough memory to handle a SAL record.
334 *
335 * Initialize a handling set of slidx_pool:
336 * 1. Pick up the max size of SAL error records
337 * 2. Pick up the min size of SAL error sections
338 * 3. Allocate the pool as enough to 2 SAL records
339 * (now we can estimate the maxinum of section in a record.)
340 */
341
342 /* - 1 - */
343 rec_max_size = sal_rec_max;
344
345 /* - 2 - */
346 sect_min_size = sal_log_sect_min_sizes[0];
347 for (i = 1; i < sizeof sal_log_sect_min_sizes/sizeof(size_t); i++)
348 if (sect_min_size > sal_log_sect_min_sizes[i])
349 sect_min_size = sal_log_sect_min_sizes[i];
350
351 /* - 3 - */
352 slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
Zhang Yanfei7c13e0d2013-03-12 12:47:08 +0800353 slidx_pool.buffer =
Kees Cook6da2ec52018-06-12 13:55:00 -0700354 kmalloc_array(slidx_pool.max_idx, sizeof(slidx_list_t),
355 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 return slidx_pool.buffer ? 0 : -ENOMEM;
358}
359
360
361/*****************************************************************************
362 * Recovery functions *
363 *****************************************************************************/
364
365/**
366 * is_mca_global - Check whether this MCA is global or not
367 * @peidx: pointer of index of processor error section
368 * @pbci: pointer to pal_bus_check_info_t
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900369 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 *
371 * Return value:
372 * MCA_IS_LOCAL / MCA_IS_GLOBAL
373 */
374
375static mca_type_t
Keith Owens7f613c72005-09-11 17:22:53 +1000376is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
377 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900379 pal_processor_state_info_t *psp =
380 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900382 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 * PAL can request a rendezvous, if the MCA has a global scope.
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900384 * If "rz_always" flag is set, SAL requests MCA rendezvous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 * in spite of global MCA.
386 * Therefore it is local MCA when rendezvous has not been requested.
387 * Failed to rendezvous, the system must be down.
388 */
Keith Owens7f613c72005-09-11 17:22:53 +1000389 switch (sos->rv_rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 case -1: /* SAL rendezvous unsuccessful */
391 return MCA_IS_GLOBAL;
392 case 0: /* SAL rendezvous not required */
393 return MCA_IS_LOCAL;
394 case 1: /* SAL rendezvous successful int */
395 case 2: /* SAL rendezvous successful int with init */
396 default:
397 break;
398 }
399
400 /*
401 * If One or more Cache/TLB/Reg_File/Uarch_Check is here,
402 * it would be a local MCA. (i.e. processor internal error)
403 */
404 if (psp->tc || psp->cc || psp->rc || psp->uc)
405 return MCA_IS_LOCAL;
406
407 /*
408 * Bus_Check structure with Bus_Check.ib (internal bus error) flag set
409 * would be a global MCA. (e.g. a system bus address parity error)
410 */
411 if (!pbci || pbci->ib)
412 return MCA_IS_GLOBAL;
413
414 /*
415 * Bus_Check structure with Bus_Check.eb (external bus error) flag set
416 * could be either a local MCA or a global MCA.
417 *
418 * Referring Bus_Check.bsi:
419 * 0: Unknown/unclassified
420 * 1: BERR#
421 * 2: BINIT#
422 * 3: Hard Fail
423 * (FIXME: Are these SGI specific or generic bsi values?)
424 */
425 if (pbci->eb)
426 switch (pbci->bsi) {
427 case 0:
428 /* e.g. a load from poisoned memory */
429 return MCA_IS_LOCAL;
430 case 1:
431 case 2:
432 case 3:
433 return MCA_IS_GLOBAL;
434 }
435
436 return MCA_IS_GLOBAL;
437}
438
439/**
Russ Anderson264b0f992006-10-25 17:59:47 -0500440 * get_target_identifier - Get the valid Cache or Bus check target identifier.
441 * @peidx: pointer of index of processor error section
442 *
443 * Return value:
Simon Arlott72fdbdc2007-05-11 14:55:43 -0700444 * target address on Success / 0 on Failure
Russ Anderson264b0f992006-10-25 17:59:47 -0500445 */
446static u64
447get_target_identifier(peidx_table_t *peidx)
448{
449 u64 target_address = 0;
450 sal_log_mod_error_info_t *smei;
451 pal_cache_check_info_t *pcci;
452 int i, level = 9;
453
454 /*
455 * Look through the cache checks for a valid target identifier
456 * If more than one valid target identifier, return the one
457 * with the lowest cache level.
458 */
459 for (i = 0; i < peidx_cache_check_num(peidx); i++) {
460 smei = (sal_log_mod_error_info_t *)peidx_cache_check(peidx, i);
461 if (smei->valid.target_identifier && smei->target_identifier) {
462 pcci = (pal_cache_check_info_t *)&(smei->check_info);
463 if (!target_address || (pcci->level < level)) {
464 target_address = smei->target_identifier;
465 level = pcci->level;
466 continue;
467 }
468 }
469 }
470 if (target_address)
471 return target_address;
472
473 /*
474 * Look at the bus check for a valid target identifier
475 */
476 smei = peidx_bus_check(peidx, 0);
477 if (smei && smei->valid.target_identifier)
478 return smei->target_identifier;
479
480 return 0;
481}
482
483/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 * recover_from_read_error - Try to recover the errors which type are "read"s.
485 * @slidx: pointer of index of SAL error record
486 * @peidx: pointer of index of processor error section
487 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900488 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 *
490 * Return value:
491 * 1 on Success / 0 on Failure
492 */
493
494static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900495recover_from_read_error(slidx_table_t *slidx,
496 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000497 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Russ Anderson264b0f992006-10-25 17:59:47 -0500499 u64 target_identifier;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 pal_min_state_area_t *pmsa;
501 struct ia64_psr *psr1, *psr2;
502 ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
503
504 /* Is target address valid? */
Russ Anderson264b0f992006-10-25 17:59:47 -0500505 target_identifier = get_target_identifier(peidx);
506 if (!target_identifier)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700507 return fatal_mca("target address not valid");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 /*
510 * cpu read or memory-mapped io read
511 *
512 * offending process affected process OS MCA do
513 * kernel mode kernel mode down system
514 * kernel mode user mode kill the process
515 * user mode kernel mode down system (*)
516 * user mode user mode kill the process
517 *
518 * (*) You could terminate offending user-mode process
519 * if (pbci->pv && pbci->pl != 0) *and* if you sure
520 * the process not have any locks of kernel.
521 */
522
Hidetoshi Setoa9474642006-02-09 14:42:55 -0800523 /* Is minstate valid? */
524 if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700525 return fatal_mca("minstate not valid");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
Russ Andersond2a28ad2006-03-24 09:49:52 -0800527 psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 /*
530 * Check the privilege level of interrupted context.
531 * If it is user-mode, then terminate affected process.
532 */
Russ Andersond2a28ad2006-03-24 09:49:52 -0800533
534 pmsa = sos->pal_min_state;
535 if (psr1->cpl != 0 ||
536 ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
Russ Anderson264b0f992006-10-25 17:59:47 -0500537 /*
538 * setup for resume to bottom half of MCA,
539 * "mca_handler_bhhook"
540 */
541 /* pass to bhhook as argument (gr8, ...) */
542 pmsa->pmsa_gr[8-1] = target_identifier;
543 pmsa->pmsa_gr[9-1] = pmsa->pmsa_iip;
544 pmsa->pmsa_gr[10-1] = pmsa->pmsa_ipsr;
545 /* set interrupted return address (but no use) */
546 pmsa->pmsa_br0 = pmsa->pmsa_iip;
547 /* change resume address to bottom half */
548 pmsa->pmsa_iip = mca_hdlr_bh->fp;
549 pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
550 /* set cpl with kernel mode */
551 psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
552 psr2->cpl = 0;
553 psr2->ri = 0;
554 psr2->bn = 1;
555 psr2->i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Russ Anderson264b0f992006-10-25 17:59:47 -0500557 return mca_recovered("user memory corruption. "
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700558 "kill affected process - recovered.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700561 return fatal_mca("kernel context not recovered, iip 0x%lx\n",
562 pmsa->pmsa_iip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
565/**
566 * recover_from_platform_error - Recover from platform error.
567 * @slidx: pointer of index of SAL error record
568 * @peidx: pointer of index of processor error section
569 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900570 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 *
572 * Return value:
573 * 1 on Success / 0 on Failure
574 */
575
576static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900577recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx,
578 pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000579 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
581 int status = 0;
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900582 pal_processor_state_info_t *psp =
583 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 if (psp->bc && pbci->eb && pbci->bsi == 0) {
586 switch(pbci->type) {
587 case 1: /* partial read */
588 case 3: /* full line(cpu) read */
589 case 9: /* I/O space read */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900590 status = recover_from_read_error(slidx, peidx, pbci,
591 sos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 break;
593 case 0: /* unknown */
594 case 2: /* partial write */
595 case 4: /* full line write */
596 case 5: /* implicit or explicit write-back operation */
597 case 6: /* snoop probe */
598 case 7: /* incoming or outgoing ptc.g */
599 case 8: /* write coalescing transactions */
600 case 10: /* I/O space write */
601 case 11: /* inter-processor interrupt message(IPI) */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900602 case 12: /* interrupt acknowledge or
603 external task priority cycle */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 default:
605 break;
606 }
Russ Anderson396e8e72006-12-20 11:32:27 -0600607 } else if (psp->cc && !psp->bc) { /* Cache error */
608 status = recover_from_read_error(slidx, peidx, pbci, sos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
610
611 return status;
612}
613
Russ Anderson618b2062006-12-14 16:01:41 -0600614/*
615 * recover_from_tlb_check
616 * @peidx: pointer of index of processor error section
617 *
618 * Return value:
619 * 1 on Success / 0 on Failure
620 */
621static int
622recover_from_tlb_check(peidx_table_t *peidx)
623{
624 sal_log_mod_error_info_t *smei;
625 pal_tlb_check_info_t *ptci;
626
627 smei = (sal_log_mod_error_info_t *)peidx_tlb_check(peidx, 0);
628 ptci = (pal_tlb_check_info_t *)&(smei->check_info);
629
630 /*
631 * Look for signature of a duplicate TLB DTC entry, which is
632 * a SW bug and always fatal.
633 */
634 if (ptci->op == PAL_TLB_CHECK_OP_PURGE
635 && !(ptci->itr || ptci->dtc || ptci->itc))
636 return fatal_mca("Duplicate TLB entry");
637
638 return mca_recovered("TLB check recovered");
639}
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641/**
642 * recover_from_processor_error
643 * @platform: whether there are some platform error section or not
644 * @slidx: pointer of index of SAL error record
645 * @peidx: pointer of index of processor error section
646 * @pbci: pointer of pal_bus_check_info
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900647 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 *
649 * Return value:
650 * 1 on Success / 0 on Failure
651 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900654recover_from_processor_error(int platform, slidx_table_t *slidx,
655 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
Keith Owens7f613c72005-09-11 17:22:53 +1000656 struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900658 pal_processor_state_info_t *psp =
659 (pal_processor_state_info_t*)peidx_psp(peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900661 /*
Russ Andersona14f25a2005-11-04 13:39:38 -0600662 * Processor recovery status must key off of the PAL recovery
663 * status in the Processor State Parameter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 */
Russ Andersona14f25a2005-11-04 13:39:38 -0600665
666 /*
667 * The machine check is corrected.
668 */
669 if (psp->cm == 1)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700670 return mca_recovered("machine check is already corrected.");
Russ Andersona14f25a2005-11-04 13:39:38 -0600671
672 /*
673 * The error was not contained. Software must be reset.
674 */
675 if (psp->us || psp->ci == 0)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700676 return fatal_mca("error not contained");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 /*
Russ Anderson618b2062006-12-14 16:01:41 -0600679 * Look for recoverable TLB check
680 */
681 if (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
682 return recover_from_tlb_check(peidx);
683
684 /*
Russ Andersone1c485542006-03-03 16:42:26 -0600685 * The cache check and bus check bits have four possible states
686 * cc bc
Russ Andersone1c485542006-03-03 16:42:26 -0600687 * 1 1 Memory error, attempt recovery
Russ Anderson396e8e72006-12-20 11:32:27 -0600688 * 1 0 Cache error, attempt recovery
689 * 0 1 I/O error, attempt recovery
690 * 0 0 Other error type, not recovered
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 */
Russ Anderson396e8e72006-12-20 11:32:27 -0600692 if (psp->cc == 0 && (psp->bc == 0 || pbci == NULL))
693 return fatal_mca("No cache or bus check");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 /*
Russ Anderson396e8e72006-12-20 11:32:27 -0600696 * Cannot handle more than one bus check.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 */
698 if (peidx_bus_check_num(peidx) > 1)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700699 return fatal_mca("Too many bus checks");
Russ Anderson396e8e72006-12-20 11:32:27 -0600700
Russ Anderson18997962006-04-27 10:07:08 -0500701 if (pbci->ib)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700702 return fatal_mca("Internal Bus error");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (pbci->eb && pbci->bsi > 0)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700704 return fatal_mca("External bus check fatal status");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 /*
Simon Arlott72fdbdc2007-05-11 14:55:43 -0700707 * This is a local MCA and estimated as a recoverable error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900709 if (platform)
Keith Owens7f613c72005-09-11 17:22:53 +1000710 return recover_from_platform_error(slidx, peidx, pbci, sos);
Russ Anderson396e8e72006-12-20 11:32:27 -0600711
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900712 /*
713 * On account of strange SAL error record, we cannot recover.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 */
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700715 return fatal_mca("Strange SAL record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
718/**
719 * mca_try_to_recover - Try to recover from MCA
720 * @rec: pointer to a SAL error record
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900721 * @sos: pointer to hand off struct between SAL and OS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 *
723 * Return value:
724 * 1 on Success / 0 on Failure
725 */
726
727static int
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900728mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
730 int platform_err;
731 int n_proc_err;
732 slidx_table_t slidx;
733 peidx_table_t peidx;
734 pal_bus_check_info_t pbci;
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 /* Make index of SAL error record */
737 platform_err = mca_make_slidx(rec, &slidx);
738
739 /* Count processor error sections */
740 n_proc_err = slidx_count(&slidx, proc_err);
741
742 /* Now, OS can recover when there is one processor error section */
743 if (n_proc_err > 1)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700744 return fatal_mca("Too Many Errors");
Russ Anderson18997962006-04-27 10:07:08 -0500745 else if (n_proc_err == 0)
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700746 /* Weird SAL record ... We can't do anything */
747 return fatal_mca("Weird SAL record");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 /* Make index of processor error section */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900750 mca_make_peidx((sal_log_processor_info_t*)
751 slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /* Extract Processor BUS_CHECK[0] */
754 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
755
756 /* Check whether MCA is global or not */
Keith Owens7f613c72005-09-11 17:22:53 +1000757 if (is_mca_global(&peidx, &pbci, sos))
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700758 return fatal_mca("global MCA");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760 /* Try to recover a processor error */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900761 return recover_from_processor_error(platform_err, &slidx, &peidx,
762 &pbci, sos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
765/*
766 * =============================================================================
767 */
768
769int __init mca_external_handler_init(void)
770{
771 if (init_record_index_pools())
772 return -ENOMEM;
773
774 /* register external mca handlers */
Hidetoshi Seto20305e52005-09-16 13:44:56 +0900775 if (ia64_reg_MCA_extension(mca_try_to_recover)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 printk(KERN_ERR "ia64_reg_MCA_extension failed.\n");
777 kfree(slidx_pool.buffer);
778 return -EFAULT;
779 }
780 return 0;
781}
782
783void __exit mca_external_handler_exit(void)
784{
785 /* unregister external mca handlers */
786 ia64_unreg_MCA_extension();
787 kfree(slidx_pool.buffer);
788}
789
790module_init(mca_external_handler_init);
791module_exit(mca_external_handler_exit);
792
793module_param(sal_rec_max, int, 0644);
794MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record");
795
796MODULE_DESCRIPTION("ia64 platform dependent mca handler driver");
797MODULE_LICENSE("GPL");