3 * Purpose: Generic MCA handling layer
5 * Copyright (C) 2004 FUJITSU LIMITED
6 * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
8 #include <linux/config.h>
9 #include <linux/types.h>
10 #include <linux/init.h>
11 #include <linux/sched.h>
12 #include <linux/interrupt.h>
13 #include <linux/irq.h>
14 #include <linux/kallsyms.h>
15 #include <linux/smp_lock.h>
16 #include <linux/bootmem.h>
17 #include <linux/acpi.h>
18 #include <linux/timer.h>
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/smp.h>
22 #include <linux/workqueue.h>
25 #include <asm/delay.h>
26 #include <asm/machvec.h>
28 #include <asm/ptrace.h>
29 #include <asm/system.h>
34 #include <asm/hw_irq.h>
38 /* max size of SAL error record (default) */
39 static int sal_rec_max = 10000;
42 static ia64_mca_sal_to_os_state_t *sal_to_os_handoff_state;
43 static ia64_mca_os_to_sal_state_t *os_to_sal_handoff_state;
45 /* from mca_drv_asm.S */
46 extern void *mca_handler_bhhook(void);
48 static DEFINE_SPINLOCK(mca_bh_lock);
55 #define MAX_PAGE_ISOLATE 1024
57 static struct page *page_isolate[MAX_PAGE_ISOLATE];
58 static int num_page_isolate = 0;
66 * This pool keeps pointers to the section part of SAL error record
69 slidx_list_t *buffer; /* section pointer list pool */
70 int cur_idx; /* Current index of section pointer list pool */
71 int max_idx; /* Maximum index of section pointer list pool */
75 * mca_page_isolate - isolate a poisoned page in order not to use it later
76 * @paddr: poisoned memory location
79 * ISOLATE_OK / ISOLATE_NG
82 static isolate_status_t
83 mca_page_isolate(unsigned long paddr)
88 /* whether physical address is valid or not */
89 if ( !ia64_phys_addr_valid(paddr) )
92 /* convert physical address to physical page number */
93 p = pfn_to_page(paddr>>PAGE_SHIFT);
95 /* check whether a page number have been already registered or not */
96 for( i = 0; i < num_page_isolate; i++ )
97 if( page_isolate[i] == p )
98 return ISOLATE_OK; /* already listed */
100 /* limitation check */
101 if( num_page_isolate == MAX_PAGE_ISOLATE )
104 /* kick pages having attribute 'SLAB' or 'Reserved' */
105 if( PageSlab(p) || PageReserved(p) )
108 /* add attribute 'Reserved' and register the page */
110 page_isolate[num_page_isolate++] = p;
116 * mca_hanlder_bh - Kill the process which occurred memory read error
117 * @paddr: poisoned address received from MCA Handler
121 mca_handler_bh(unsigned long paddr)
123 printk(KERN_DEBUG "OS_MCA: process [pid: %d](%s) encounters MCA.\n",
124 current->pid, current->comm);
126 spin_lock(&mca_bh_lock);
127 if (mca_page_isolate(paddr) == ISOLATE_OK) {
128 printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr);
130 printk(KERN_DEBUG "Page isolation: ( %lx ) failure.\n", paddr);
132 spin_unlock(&mca_bh_lock);
134 /* This process is about to be killed itself */
139 * mca_make_peidx - Make index of processor error section
140 * @slpi: pointer to record of processor error section
141 * @peidx: pointer to index of processor error section
145 mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx)
148 * calculate the start address of
149 * "struct cpuid_info" and "sal_processor_static_info_t".
151 u64 total_check_num = slpi->valid.num_cache_check
152 + slpi->valid.num_tlb_check
153 + slpi->valid.num_bus_check
154 + slpi->valid.num_reg_file_check
155 + slpi->valid.num_ms_check;
156 u64 head_size = sizeof(sal_log_mod_error_info_t) * total_check_num
157 + sizeof(sal_log_processor_info_t);
158 u64 mid_size = slpi->valid.cpuid_info * sizeof(struct sal_cpuid_info);
160 peidx_head(peidx) = slpi;
161 peidx_mid(peidx) = (struct sal_cpuid_info *)
162 (slpi->valid.cpuid_info ? ((char*)slpi + head_size) : NULL);
163 peidx_bottom(peidx) = (sal_processor_static_info_t *)
164 (slpi->valid.psi_static_struct ?
165 ((char*)slpi + head_size + mid_size) : NULL);
169 * mca_make_slidx - Make index of SAL error record
170 * @buffer: pointer to SAL error record
171 * @slidx: pointer to index of SAL error record
174 * 1 if record has platform error / 0 if not
176 #define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \
177 { slidx_list_t *hl = &slidx_pool.buffer[slidx_pool.cur_idx]; \
179 list_add(&hl->list, &(sect)); \
180 slidx_pool.cur_idx = (slidx_pool.cur_idx + 1)%slidx_pool.max_idx; }
183 mca_make_slidx(void *buffer, slidx_table_t *slidx)
185 int platform_err = 0;
186 int record_len = ((sal_log_record_header_t*)buffer)->len;
189 sal_log_section_hdr_t *sp;
192 * Initialize index referring current record
194 INIT_LIST_HEAD(&(slidx->proc_err));
195 INIT_LIST_HEAD(&(slidx->mem_dev_err));
196 INIT_LIST_HEAD(&(slidx->sel_dev_err));
197 INIT_LIST_HEAD(&(slidx->pci_bus_err));
198 INIT_LIST_HEAD(&(slidx->smbios_dev_err));
199 INIT_LIST_HEAD(&(slidx->pci_comp_err));
200 INIT_LIST_HEAD(&(slidx->plat_specific_err));
201 INIT_LIST_HEAD(&(slidx->host_ctlr_err));
202 INIT_LIST_HEAD(&(slidx->plat_bus_err));
203 INIT_LIST_HEAD(&(slidx->unsupported));
206 * Extract a Record Header
208 slidx->header = buffer;
211 * Extract each section records
212 * (arranged from "int ia64_log_platform_info_print()")
214 for (ercd_pos = sizeof(sal_log_record_header_t), sects = 0;
215 ercd_pos < record_len; ercd_pos += sp->len, sects++) {
216 sp = (sal_log_section_hdr_t *)((char*)buffer + ercd_pos);
217 if (!efi_guidcmp(sp->guid, SAL_PROC_DEV_ERR_SECT_GUID)) {
218 LOG_INDEX_ADD_SECT_PTR(slidx->proc_err, sp);
219 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) {
221 LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp);
222 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) {
224 LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp);
225 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) {
227 LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp);
228 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) {
230 LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp);
231 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) {
233 LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp);
234 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) {
236 LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp);
237 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) {
239 LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp);
240 } else if (!efi_guidcmp(sp->guid, SAL_PLAT_BUS_ERR_SECT_GUID)) {
242 LOG_INDEX_ADD_SECT_PTR(slidx->plat_bus_err, sp);
244 LOG_INDEX_ADD_SECT_PTR(slidx->unsupported, sp);
247 slidx->n_sections = sects;
253 * init_record_index_pools - Initialize pool of lists for SAL record index
256 * 0 on Success / -ENOMEM on Failure
259 init_record_index_pools(void)
262 int rec_max_size; /* Maximum size of SAL error records */
263 int sect_min_size; /* Minimum size of SAL error sections */
264 /* minimum size table of each section */
265 static int sal_log_sect_min_sizes[] = {
266 sizeof(sal_log_processor_info_t) + sizeof(sal_processor_static_info_t),
267 sizeof(sal_log_mem_dev_err_info_t),
268 sizeof(sal_log_sel_dev_err_info_t),
269 sizeof(sal_log_pci_bus_err_info_t),
270 sizeof(sal_log_smbios_dev_err_info_t),
271 sizeof(sal_log_pci_comp_err_info_t),
272 sizeof(sal_log_plat_specific_err_info_t),
273 sizeof(sal_log_host_ctlr_err_info_t),
274 sizeof(sal_log_plat_bus_err_info_t),
278 * MCA handler cannot allocate new memory on flight,
279 * so we preallocate enough memory to handle a SAL record.
281 * Initialize a handling set of slidx_pool:
282 * 1. Pick up the max size of SAL error records
283 * 2. Pick up the min size of SAL error sections
284 * 3. Allocate the pool as enough to 2 SAL records
285 * (now we can estimate the maxinum of section in a record.)
289 rec_max_size = sal_rec_max;
292 sect_min_size = sal_log_sect_min_sizes[0];
293 for (i = 1; i < sizeof sal_log_sect_min_sizes/sizeof(size_t); i++)
294 if (sect_min_size > sal_log_sect_min_sizes[i])
295 sect_min_size = sal_log_sect_min_sizes[i];
298 slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
299 slidx_pool.buffer = (slidx_list_t *) kmalloc(slidx_pool.max_idx * sizeof(slidx_list_t), GFP_KERNEL);
301 return slidx_pool.buffer ? 0 : -ENOMEM;
305 /*****************************************************************************
306 * Recovery functions *
307 *****************************************************************************/
310 * is_mca_global - Check whether this MCA is global or not
311 * @peidx: pointer of index of processor error section
312 * @pbci: pointer to pal_bus_check_info_t
315 * MCA_IS_LOCAL / MCA_IS_GLOBAL
319 is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci)
321 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx);
324 * PAL can request a rendezvous, if the MCA has a global scope.
325 * If "rz_always" flag is set, SAL requests MCA rendezvous
326 * in spite of global MCA.
327 * Therefore it is local MCA when rendezvous has not been requested.
328 * Failed to rendezvous, the system must be down.
330 switch (sal_to_os_handoff_state->imsto_rendez_state) {
331 case -1: /* SAL rendezvous unsuccessful */
332 return MCA_IS_GLOBAL;
333 case 0: /* SAL rendezvous not required */
335 case 1: /* SAL rendezvous successful int */
336 case 2: /* SAL rendezvous successful int with init */
342 * If One or more Cache/TLB/Reg_File/Uarch_Check is here,
343 * it would be a local MCA. (i.e. processor internal error)
345 if (psp->tc || psp->cc || psp->rc || psp->uc)
349 * Bus_Check structure with Bus_Check.ib (internal bus error) flag set
350 * would be a global MCA. (e.g. a system bus address parity error)
352 if (!pbci || pbci->ib)
353 return MCA_IS_GLOBAL;
356 * Bus_Check structure with Bus_Check.eb (external bus error) flag set
357 * could be either a local MCA or a global MCA.
359 * Referring Bus_Check.bsi:
360 * 0: Unknown/unclassified
364 * (FIXME: Are these SGI specific or generic bsi values?)
369 /* e.g. a load from poisoned memory */
374 return MCA_IS_GLOBAL;
377 return MCA_IS_GLOBAL;
381 * recover_from_read_error - Try to recover the errors which type are "read"s.
382 * @slidx: pointer of index of SAL error record
383 * @peidx: pointer of index of processor error section
384 * @pbci: pointer of pal_bus_check_info
387 * 1 on Success / 0 on Failure
391 recover_from_read_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci)
393 sal_log_mod_error_info_t *smei;
394 pal_min_state_area_t *pmsa;
395 struct ia64_psr *psr1, *psr2;
396 ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
398 /* Is target address valid? */
403 * cpu read or memory-mapped io read
405 * offending process affected process OS MCA do
406 * kernel mode kernel mode down system
407 * kernel mode user mode kill the process
408 * user mode kernel mode down system (*)
409 * user mode user mode kill the process
411 * (*) You could terminate offending user-mode process
412 * if (pbci->pv && pbci->pl != 0) *and* if you sure
413 * the process not have any locks of kernel.
416 psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
419 * Check the privilege level of interrupted context.
420 * If it is user-mode, then terminate affected process.
422 if (psr1->cpl != 0) {
423 smei = peidx_bus_check(peidx, 0);
424 if (smei->valid.target_identifier) {
426 * setup for resume to bottom half of MCA,
427 * "mca_handler_bhhook"
429 pmsa = (pal_min_state_area_t *)(sal_to_os_handoff_state->pal_min_state | (6ul<<61));
430 /* pass to bhhook as 1st argument (gr8) */
431 pmsa->pmsa_gr[8-1] = smei->target_identifier;
432 /* set interrupted return address (but no use) */
433 pmsa->pmsa_br0 = pmsa->pmsa_iip;
434 /* change resume address to bottom half */
435 pmsa->pmsa_iip = mca_hdlr_bh->fp;
436 pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
437 /* set cpl with kernel mode */
438 psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
452 * recover_from_platform_error - Recover from platform error.
453 * @slidx: pointer of index of SAL error record
454 * @peidx: pointer of index of processor error section
455 * @pbci: pointer of pal_bus_check_info
458 * 1 on Success / 0 on Failure
462 recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci)
465 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx);
467 if (psp->bc && pbci->eb && pbci->bsi == 0) {
469 case 1: /* partial read */
470 case 3: /* full line(cpu) read */
471 case 9: /* I/O space read */
472 status = recover_from_read_error(slidx, peidx, pbci);
474 case 0: /* unknown */
475 case 2: /* partial write */
476 case 4: /* full line write */
477 case 5: /* implicit or explicit write-back operation */
478 case 6: /* snoop probe */
479 case 7: /* incoming or outgoing ptc.g */
480 case 8: /* write coalescing transactions */
481 case 10: /* I/O space write */
482 case 11: /* inter-processor interrupt message(IPI) */
483 case 12: /* interrupt acknowledge or external task priority cycle */
493 * recover_from_processor_error
494 * @platform: whether there are some platform error section or not
495 * @slidx: pointer of index of SAL error record
496 * @peidx: pointer of index of processor error section
497 * @pbci: pointer of pal_bus_check_info
500 * 1 on Success / 0 on Failure
503 * Later we try to recover when below all conditions are satisfied.
504 * 1. Only one processor error section is exist.
505 * 2. BUS_CHECK is exist and the others are not exist.(Except TLB_CHECK)
506 * 3. The entry of BUS_CHECK_INFO is 1.
507 * 4. "External bus error" flag is set and the others are not set.
511 recover_from_processor_error(int platform, slidx_table_t *slidx, peidx_table_t *peidx, pal_bus_check_info_t *pbci)
513 pal_processor_state_info_t *psp = (pal_processor_state_info_t*)peidx_psp(peidx);
516 * We cannot recover errors with other than bus_check.
518 if (psp->cc || psp->rc || psp->uc)
522 * If there is no bus error, record is weird but we need not to recover.
524 if (psp->bc == 0 || pbci == NULL)
528 * Sorry, we cannot handle so many.
530 if (peidx_bus_check_num(peidx) > 1)
533 * Well, here is only one bus error.
535 if (pbci->ib || pbci->cc)
537 if (pbci->eb && pbci->bsi > 0)
543 * This is a local MCA and estimated as recoverble external bus error.
544 * (e.g. a load from poisoned memory)
545 * This means "there are some platform errors".
548 return recover_from_platform_error(slidx, peidx, pbci);
550 * On account of strange SAL error record, we cannot recover.
556 * mca_try_to_recover - Try to recover from MCA
557 * @rec: pointer to a SAL error record
560 * 1 on Success / 0 on Failure
564 mca_try_to_recover(void *rec,
565 ia64_mca_sal_to_os_state_t *sal_to_os_state,
566 ia64_mca_os_to_sal_state_t *os_to_sal_state)
572 pal_bus_check_info_t pbci;
574 /* handoff state from/to mca.c */
575 sal_to_os_handoff_state = sal_to_os_state;
576 os_to_sal_handoff_state = os_to_sal_state;
578 /* Make index of SAL error record */
579 platform_err = mca_make_slidx(rec, &slidx);
581 /* Count processor error sections */
582 n_proc_err = slidx_count(&slidx, proc_err);
584 /* Now, OS can recover when there is one processor error section */
587 else if (n_proc_err == 0) {
588 /* Weird SAL record ... We need not to recover */
593 /* Make index of processor error section */
594 mca_make_peidx((sal_log_processor_info_t*)slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
596 /* Extract Processor BUS_CHECK[0] */
597 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
599 /* Check whether MCA is global or not */
600 if (is_mca_global(&peidx, &pbci))
603 /* Try to recover a processor error */
604 return recover_from_processor_error(platform_err, &slidx, &peidx, &pbci);
608 * =============================================================================
611 int __init mca_external_handler_init(void)
613 if (init_record_index_pools())
616 /* register external mca handlers */
617 if (ia64_reg_MCA_extension(mca_try_to_recover)){
618 printk(KERN_ERR "ia64_reg_MCA_extension failed.\n");
619 kfree(slidx_pool.buffer);
625 void __exit mca_external_handler_exit(void)
627 /* unregister external mca handlers */
628 ia64_unreg_MCA_extension();
629 kfree(slidx_pool.buffer);
632 module_init(mca_external_handler_init);
633 module_exit(mca_external_handler_exit);
635 module_param(sal_rec_max, int, 0644);
636 MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record");
638 MODULE_DESCRIPTION("ia64 platform dependent mca handler driver");
639 MODULE_LICENSE("GPL");