1
2
3
4
5
6
7
8
9
10
11
12#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>
18#include <linux/memblock.h>
19#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>
26#include <linux/slab.h>
27
28#include <asm/delay.h>
29#include <asm/machvec.h>
30#include <asm/page.h>
31#include <asm/ptrace.h>
32#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
41static int sal_rec_max = 10000;
42
43
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 {
59 ISOLATE_NG,
60 ISOLATE_OK,
61 ISOLATE_NONE
62} isolate_status_t;
63
64typedef enum {
65 MCA_NOT_RECOVERED = 0,
66 MCA_RECOVERED = 1
67} recovery_status_t;
68
69
70
71
72static struct {
73 slidx_list_t *buffer;
74 int cur_idx;
75 int max_idx;
76} slidx_pool;
77
78static int
79fatal_mca(const char *fmt, ...)
80{
81 va_list args;
82 char buf[256];
83
84 va_start(args, fmt);
85 vsnprintf(buf, sizeof(buf), fmt, args);
86 va_end(args);
87 ia64_mca_printk(KERN_ALERT "MCA: %s\n", buf);
88
89 return MCA_NOT_RECOVERED;
90}
91
92static 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
106
107
108
109
110
111
112
113
114static isolate_status_t
115mca_page_isolate(unsigned long paddr)
116{
117 int i;
118 struct page *p;
119
120
121 if (!ia64_phys_addr_valid(paddr))
122 return ISOLATE_NONE;
123
124 if (!pfn_valid(paddr >> PAGE_SHIFT))
125 return ISOLATE_NONE;
126
127
128 p = pfn_to_page(paddr>>PAGE_SHIFT);
129
130
131 for (i = 0; i < num_page_isolate; i++)
132 if (page_isolate[i] == p)
133 return ISOLATE_OK;
134
135
136 if (num_page_isolate == MAX_PAGE_ISOLATE)
137 return ISOLATE_NG;
138
139
140 if (PageSlab(p) || PageReserved(p))
141 return ISOLATE_NG;
142
143
144 get_page(p);
145 SetPageReserved(p);
146 page_isolate[num_page_isolate++] = p;
147
148 return ISOLATE_OK;
149}
150
151
152
153
154
155
156void
157mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
158{
159 ia64_mlogbuf_dump();
160 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",
162 raw_smp_processor_id(), current->pid,
163 from_kuid(&init_user_ns, current_uid()),
164 iip, ipsr, paddr, current->comm);
165
166 spin_lock(&mca_bh_lock);
167 switch (mca_page_isolate(paddr)) {
168 case ISOLATE_OK:
169 printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr);
170 break;
171 case ISOLATE_NG:
172 printk(KERN_CRIT "Page isolation: ( %lx ) failure.\n", paddr);
173 break;
174 default:
175 break;
176 }
177 spin_unlock(&mca_bh_lock);
178
179
180 do_exit(SIGKILL);
181}
182
183
184
185
186
187
188
189static void
190mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx)
191{
192
193
194
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
214
215
216
217
218
219
220
221#define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \
222 {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; }
226
227static int
228mca_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
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
252
253 slidx->header = buffer;
254
255
256
257
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);
264 } else if (!efi_guidcmp(sp->guid,
265 SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) {
266 platform_err = 1;
267 LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp);
268 } else if (!efi_guidcmp(sp->guid,
269 SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) {
270 platform_err = 1;
271 LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp);
272 } else if (!efi_guidcmp(sp->guid,
273 SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) {
274 platform_err = 1;
275 LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp);
276 } else if (!efi_guidcmp(sp->guid,
277 SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) {
278 platform_err = 1;
279 LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp);
280 } else if (!efi_guidcmp(sp->guid,
281 SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) {
282 platform_err = 1;
283 LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp);
284 } else if (!efi_guidcmp(sp->guid,
285 SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) {
286 platform_err = 1;
287 LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp);
288 } else if (!efi_guidcmp(sp->guid,
289 SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) {
290 platform_err = 1;
291 LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp);
292 } else if (!efi_guidcmp(sp->guid,
293 SAL_PLAT_BUS_ERR_SECT_GUID)) {
294 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
307
308
309
310
311static int
312init_record_index_pools(void)
313{
314 int i;
315 int rec_max_size;
316 int sect_min_size;
317
318 static int sal_log_sect_min_sizes[] = {
319 sizeof(sal_log_processor_info_t)
320 + sizeof(sal_processor_static_info_t),
321 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
333
334
335
336
337
338
339
340
341
342
343 rec_max_size = sal_rec_max;
344
345
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
352 slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
353 slidx_pool.buffer =
354 kmalloc_array(slidx_pool.max_idx, sizeof(slidx_list_t),
355 GFP_KERNEL);
356
357 return slidx_pool.buffer ? 0 : -ENOMEM;
358}
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375static mca_type_t
376is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
377 struct ia64_sal_os_state *sos)
378{
379 pal_processor_state_info_t *psp =
380 (pal_processor_state_info_t*)peidx_psp(peidx);
381
382
383
384
385
386
387
388
389 switch (sos->rv_rc) {
390 case -1:
391 return MCA_IS_GLOBAL;
392 case 0:
393 return MCA_IS_LOCAL;
394 case 1:
395 case 2:
396 default:
397 break;
398 }
399
400
401
402
403
404 if (psp->tc || psp->cc || psp->rc || psp->uc)
405 return MCA_IS_LOCAL;
406
407
408
409
410
411 if (!pbci || pbci->ib)
412 return MCA_IS_GLOBAL;
413
414
415
416
417
418
419
420
421
422
423
424
425 if (pbci->eb)
426 switch (pbci->bsi) {
427 case 0:
428
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
440
441
442
443
444
445
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
456
457
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
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
484
485
486
487
488
489
490
491
492
493
494static int
495recover_from_read_error(slidx_table_t *slidx,
496 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
497 struct ia64_sal_os_state *sos)
498{
499 u64 target_identifier;
500 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
505 target_identifier = get_target_identifier(peidx);
506 if (!target_identifier)
507 return fatal_mca("target address not valid");
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524 if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
525 return fatal_mca("minstate not valid");
526 psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
527 psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
528
529
530
531
532
533
534 pmsa = sos->pal_min_state;
535 if (psr1->cpl != 0 ||
536 ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
537
538
539
540
541
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
546 pmsa->pmsa_br0 = pmsa->pmsa_iip;
547
548 pmsa->pmsa_iip = mca_hdlr_bh->fp;
549 pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
550
551 psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
552 psr2->cpl = 0;
553 psr2->ri = 0;
554 psr2->bn = 1;
555 psr2->i = 0;
556
557 return mca_recovered("user memory corruption. "
558 "kill affected process - recovered.");
559 }
560
561 return fatal_mca("kernel context not recovered, iip 0x%lx\n",
562 pmsa->pmsa_iip);
563}
564
565
566
567
568
569
570
571
572
573
574
575
576static int
577recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx,
578 pal_bus_check_info_t *pbci,
579 struct ia64_sal_os_state *sos)
580{
581 int status = 0;
582 pal_processor_state_info_t *psp =
583 (pal_processor_state_info_t*)peidx_psp(peidx);
584
585 if (psp->bc && pbci->eb && pbci->bsi == 0) {
586 switch(pbci->type) {
587 case 1:
588 case 3:
589 case 9:
590 status = recover_from_read_error(slidx, peidx, pbci,
591 sos);
592 break;
593 case 0:
594 case 2:
595 case 4:
596 case 5:
597 case 6:
598 case 7:
599 case 8:
600 case 10:
601 case 11:
602 case 12:
603
604 default:
605 break;
606 }
607 } else if (psp->cc && !psp->bc) {
608 status = recover_from_read_error(slidx, peidx, pbci, sos);
609 }
610
611 return status;
612}
613
614
615
616
617
618
619
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
632
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
641
642
643
644
645
646
647
648
649
650
651
652
653static int
654recover_from_processor_error(int platform, slidx_table_t *slidx,
655 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
656 struct ia64_sal_os_state *sos)
657{
658 pal_processor_state_info_t *psp =
659 (pal_processor_state_info_t*)peidx_psp(peidx);
660
661
662
663
664
665
666
667
668
669 if (psp->cm == 1)
670 return mca_recovered("machine check is already corrected.");
671
672
673
674
675 if (psp->us || psp->ci == 0)
676 return fatal_mca("error not contained");
677
678
679
680
681 if (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
682 return recover_from_tlb_check(peidx);
683
684
685
686
687
688
689
690
691
692 if (psp->cc == 0 && (psp->bc == 0 || pbci == NULL))
693 return fatal_mca("No cache or bus check");
694
695
696
697
698 if (peidx_bus_check_num(peidx) > 1)
699 return fatal_mca("Too many bus checks");
700
701 if (pbci->ib)
702 return fatal_mca("Internal Bus error");
703 if (pbci->eb && pbci->bsi > 0)
704 return fatal_mca("External bus check fatal status");
705
706
707
708
709 if (platform)
710 return recover_from_platform_error(slidx, peidx, pbci, sos);
711
712
713
714
715 return fatal_mca("Strange SAL record");
716}
717
718
719
720
721
722
723
724
725
726
727static int
728mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
729{
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
736
737 platform_err = mca_make_slidx(rec, &slidx);
738
739
740 n_proc_err = slidx_count(&slidx, proc_err);
741
742
743 if (n_proc_err > 1)
744 return fatal_mca("Too Many Errors");
745 else if (n_proc_err == 0)
746
747 return fatal_mca("Weird SAL record");
748
749
750 mca_make_peidx((sal_log_processor_info_t*)
751 slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
752
753
754 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
755
756
757 if (is_mca_global(&peidx, &pbci, sos))
758 return fatal_mca("global MCA");
759
760
761 return recover_from_processor_error(platform_err, &slidx, &peidx,
762 &pbci, sos);
763}
764
765
766
767
768
769int __init mca_external_handler_init(void)
770{
771 if (init_record_index_pools())
772 return -ENOMEM;
773
774
775 if (ia64_reg_MCA_extension(mca_try_to_recover)) {
776 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
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");
798