This source file includes following definitions.
- fatal_mca
- mca_recovered
- mca_page_isolate
- mca_handler_bh
- mca_make_peidx
- mca_make_slidx
- init_record_index_pools
- is_mca_global
- get_target_identifier
- recover_from_read_error
- recover_from_platform_error
- recover_from_tlb_check
- recover_from_processor_error
- mca_try_to_recover
- mca_external_handler_init
- mca_external_handler_exit
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/page.h>
30 #include <asm/ptrace.h>
31 #include <asm/sal.h>
32 #include <asm/mca.h>
33
34 #include <asm/irq.h>
35 #include <asm/hw_irq.h>
36
37 #include "mca_drv.h"
38
39
40 static int sal_rec_max = 10000;
41
42
43 extern void *mca_handler_bhhook(void);
44
45 static DEFINE_SPINLOCK(mca_bh_lock);
46
47 typedef enum {
48 MCA_IS_LOCAL = 0,
49 MCA_IS_GLOBAL = 1
50 } mca_type_t;
51
52 #define MAX_PAGE_ISOLATE 1024
53
54 static struct page *page_isolate[MAX_PAGE_ISOLATE];
55 static int num_page_isolate = 0;
56
57 typedef enum {
58 ISOLATE_NG,
59 ISOLATE_OK,
60 ISOLATE_NONE
61 } isolate_status_t;
62
63 typedef enum {
64 MCA_NOT_RECOVERED = 0,
65 MCA_RECOVERED = 1
66 } recovery_status_t;
67
68
69
70
71 static struct {
72 slidx_list_t *buffer;
73 int cur_idx;
74 int max_idx;
75 } slidx_pool;
76
77 static int
78 fatal_mca(const char *fmt, ...)
79 {
80 va_list args;
81 char buf[256];
82
83 va_start(args, fmt);
84 vsnprintf(buf, sizeof(buf), fmt, args);
85 va_end(args);
86 ia64_mca_printk(KERN_ALERT "MCA: %s\n", buf);
87
88 return MCA_NOT_RECOVERED;
89 }
90
91 static int
92 mca_recovered(const char *fmt, ...)
93 {
94 va_list args;
95 char buf[256];
96
97 va_start(args, fmt);
98 vsnprintf(buf, sizeof(buf), fmt, args);
99 va_end(args);
100 ia64_mca_printk(KERN_INFO "MCA: %s\n", buf);
101
102 return MCA_RECOVERED;
103 }
104
105
106
107
108
109
110
111
112
113 static isolate_status_t
114 mca_page_isolate(unsigned long paddr)
115 {
116 int i;
117 struct page *p;
118
119
120 if (!ia64_phys_addr_valid(paddr))
121 return ISOLATE_NONE;
122
123 if (!pfn_valid(paddr >> PAGE_SHIFT))
124 return ISOLATE_NONE;
125
126
127 p = pfn_to_page(paddr>>PAGE_SHIFT);
128
129
130 for (i = 0; i < num_page_isolate; i++)
131 if (page_isolate[i] == p)
132 return ISOLATE_OK;
133
134
135 if (num_page_isolate == MAX_PAGE_ISOLATE)
136 return ISOLATE_NG;
137
138
139 if (PageSlab(p) || PageReserved(p))
140 return ISOLATE_NG;
141
142
143 get_page(p);
144 SetPageReserved(p);
145 page_isolate[num_page_isolate++] = p;
146
147 return ISOLATE_OK;
148 }
149
150
151
152
153
154
155 void
156 mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
157 {
158 ia64_mlogbuf_dump();
159 printk(KERN_ERR "OS_MCA: process [cpu %d, pid: %d, uid: %d, "
160 "iip: %p, psr: 0x%lx,paddr: 0x%lx](%s) encounters MCA.\n",
161 raw_smp_processor_id(), current->pid,
162 from_kuid(&init_user_ns, current_uid()),
163 iip, ipsr, paddr, current->comm);
164
165 spin_lock(&mca_bh_lock);
166 switch (mca_page_isolate(paddr)) {
167 case ISOLATE_OK:
168 printk(KERN_DEBUG "Page isolation: ( %lx ) success.\n", paddr);
169 break;
170 case ISOLATE_NG:
171 printk(KERN_CRIT "Page isolation: ( %lx ) failure.\n", paddr);
172 break;
173 default:
174 break;
175 }
176 spin_unlock(&mca_bh_lock);
177
178
179 do_exit(SIGKILL);
180 }
181
182
183
184
185
186
187
188 static void
189 mca_make_peidx(sal_log_processor_info_t *slpi, peidx_table_t *peidx)
190 {
191
192
193
194
195 u64 total_check_num = slpi->valid.num_cache_check
196 + slpi->valid.num_tlb_check
197 + slpi->valid.num_bus_check
198 + slpi->valid.num_reg_file_check
199 + slpi->valid.num_ms_check;
200 u64 head_size = sizeof(sal_log_mod_error_info_t) * total_check_num
201 + sizeof(sal_log_processor_info_t);
202 u64 mid_size = slpi->valid.cpuid_info * sizeof(struct sal_cpuid_info);
203
204 peidx_head(peidx) = slpi;
205 peidx_mid(peidx) = (struct sal_cpuid_info *)
206 (slpi->valid.cpuid_info ? ((char*)slpi + head_size) : NULL);
207 peidx_bottom(peidx) = (sal_processor_static_info_t *)
208 (slpi->valid.psi_static_struct ?
209 ((char*)slpi + head_size + mid_size) : NULL);
210 }
211
212
213
214
215
216
217
218
219
220 #define LOG_INDEX_ADD_SECT_PTR(sect, ptr) \
221 {slidx_list_t *hl = &slidx_pool.buffer[slidx_pool.cur_idx]; \
222 hl->hdr = ptr; \
223 list_add(&hl->list, &(sect)); \
224 slidx_pool.cur_idx = (slidx_pool.cur_idx + 1)%slidx_pool.max_idx; }
225
226 static int
227 mca_make_slidx(void *buffer, slidx_table_t *slidx)
228 {
229 int platform_err = 0;
230 int record_len = ((sal_log_record_header_t*)buffer)->len;
231 u32 ercd_pos;
232 int sects;
233 sal_log_section_hdr_t *sp;
234
235
236
237
238 INIT_LIST_HEAD(&(slidx->proc_err));
239 INIT_LIST_HEAD(&(slidx->mem_dev_err));
240 INIT_LIST_HEAD(&(slidx->sel_dev_err));
241 INIT_LIST_HEAD(&(slidx->pci_bus_err));
242 INIT_LIST_HEAD(&(slidx->smbios_dev_err));
243 INIT_LIST_HEAD(&(slidx->pci_comp_err));
244 INIT_LIST_HEAD(&(slidx->plat_specific_err));
245 INIT_LIST_HEAD(&(slidx->host_ctlr_err));
246 INIT_LIST_HEAD(&(slidx->plat_bus_err));
247 INIT_LIST_HEAD(&(slidx->unsupported));
248
249
250
251
252 slidx->header = buffer;
253
254
255
256
257
258 for (ercd_pos = sizeof(sal_log_record_header_t), sects = 0;
259 ercd_pos < record_len; ercd_pos += sp->len, sects++) {
260 sp = (sal_log_section_hdr_t *)((char*)buffer + ercd_pos);
261 if (!efi_guidcmp(sp->guid, SAL_PROC_DEV_ERR_SECT_GUID)) {
262 LOG_INDEX_ADD_SECT_PTR(slidx->proc_err, sp);
263 } else if (!efi_guidcmp(sp->guid,
264 SAL_PLAT_MEM_DEV_ERR_SECT_GUID)) {
265 platform_err = 1;
266 LOG_INDEX_ADD_SECT_PTR(slidx->mem_dev_err, sp);
267 } else if (!efi_guidcmp(sp->guid,
268 SAL_PLAT_SEL_DEV_ERR_SECT_GUID)) {
269 platform_err = 1;
270 LOG_INDEX_ADD_SECT_PTR(slidx->sel_dev_err, sp);
271 } else if (!efi_guidcmp(sp->guid,
272 SAL_PLAT_PCI_BUS_ERR_SECT_GUID)) {
273 platform_err = 1;
274 LOG_INDEX_ADD_SECT_PTR(slidx->pci_bus_err, sp);
275 } else if (!efi_guidcmp(sp->guid,
276 SAL_PLAT_SMBIOS_DEV_ERR_SECT_GUID)) {
277 platform_err = 1;
278 LOG_INDEX_ADD_SECT_PTR(slidx->smbios_dev_err, sp);
279 } else if (!efi_guidcmp(sp->guid,
280 SAL_PLAT_PCI_COMP_ERR_SECT_GUID)) {
281 platform_err = 1;
282 LOG_INDEX_ADD_SECT_PTR(slidx->pci_comp_err, sp);
283 } else if (!efi_guidcmp(sp->guid,
284 SAL_PLAT_SPECIFIC_ERR_SECT_GUID)) {
285 platform_err = 1;
286 LOG_INDEX_ADD_SECT_PTR(slidx->plat_specific_err, sp);
287 } else if (!efi_guidcmp(sp->guid,
288 SAL_PLAT_HOST_CTLR_ERR_SECT_GUID)) {
289 platform_err = 1;
290 LOG_INDEX_ADD_SECT_PTR(slidx->host_ctlr_err, sp);
291 } else if (!efi_guidcmp(sp->guid,
292 SAL_PLAT_BUS_ERR_SECT_GUID)) {
293 platform_err = 1;
294 LOG_INDEX_ADD_SECT_PTR(slidx->plat_bus_err, sp);
295 } else {
296 LOG_INDEX_ADD_SECT_PTR(slidx->unsupported, sp);
297 }
298 }
299 slidx->n_sections = sects;
300
301 return platform_err;
302 }
303
304
305
306
307
308
309
310 static int
311 init_record_index_pools(void)
312 {
313 int i;
314 int rec_max_size;
315 int sect_min_size;
316
317 static int sal_log_sect_min_sizes[] = {
318 sizeof(sal_log_processor_info_t)
319 + sizeof(sal_processor_static_info_t),
320 sizeof(sal_log_mem_dev_err_info_t),
321 sizeof(sal_log_sel_dev_err_info_t),
322 sizeof(sal_log_pci_bus_err_info_t),
323 sizeof(sal_log_smbios_dev_err_info_t),
324 sizeof(sal_log_pci_comp_err_info_t),
325 sizeof(sal_log_plat_specific_err_info_t),
326 sizeof(sal_log_host_ctlr_err_info_t),
327 sizeof(sal_log_plat_bus_err_info_t),
328 };
329
330
331
332
333
334
335
336
337
338
339
340
341
342 rec_max_size = sal_rec_max;
343
344
345 sect_min_size = sal_log_sect_min_sizes[0];
346 for (i = 1; i < sizeof sal_log_sect_min_sizes/sizeof(size_t); i++)
347 if (sect_min_size > sal_log_sect_min_sizes[i])
348 sect_min_size = sal_log_sect_min_sizes[i];
349
350
351 slidx_pool.max_idx = (rec_max_size/sect_min_size) * 2 + 1;
352 slidx_pool.buffer =
353 kmalloc_array(slidx_pool.max_idx, sizeof(slidx_list_t),
354 GFP_KERNEL);
355
356 return slidx_pool.buffer ? 0 : -ENOMEM;
357 }
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374 static mca_type_t
375 is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
376 struct ia64_sal_os_state *sos)
377 {
378 pal_processor_state_info_t *psp =
379 (pal_processor_state_info_t*)peidx_psp(peidx);
380
381
382
383
384
385
386
387
388 switch (sos->rv_rc) {
389 case -1:
390 return MCA_IS_GLOBAL;
391 case 0:
392 return MCA_IS_LOCAL;
393 case 1:
394 case 2:
395 default:
396 break;
397 }
398
399
400
401
402
403 if (psp->tc || psp->cc || psp->rc || psp->uc)
404 return MCA_IS_LOCAL;
405
406
407
408
409
410 if (!pbci || pbci->ib)
411 return MCA_IS_GLOBAL;
412
413
414
415
416
417
418
419
420
421
422
423
424 if (pbci->eb)
425 switch (pbci->bsi) {
426 case 0:
427
428 return MCA_IS_LOCAL;
429 case 1:
430 case 2:
431 case 3:
432 return MCA_IS_GLOBAL;
433 }
434
435 return MCA_IS_GLOBAL;
436 }
437
438
439
440
441
442
443
444
445 static u64
446 get_target_identifier(peidx_table_t *peidx)
447 {
448 u64 target_address = 0;
449 sal_log_mod_error_info_t *smei;
450 pal_cache_check_info_t *pcci;
451 int i, level = 9;
452
453
454
455
456
457
458 for (i = 0; i < peidx_cache_check_num(peidx); i++) {
459 smei = (sal_log_mod_error_info_t *)peidx_cache_check(peidx, i);
460 if (smei->valid.target_identifier && smei->target_identifier) {
461 pcci = (pal_cache_check_info_t *)&(smei->check_info);
462 if (!target_address || (pcci->level < level)) {
463 target_address = smei->target_identifier;
464 level = pcci->level;
465 continue;
466 }
467 }
468 }
469 if (target_address)
470 return target_address;
471
472
473
474
475 smei = peidx_bus_check(peidx, 0);
476 if (smei && smei->valid.target_identifier)
477 return smei->target_identifier;
478
479 return 0;
480 }
481
482
483
484
485
486
487
488
489
490
491
492
493 static int
494 recover_from_read_error(slidx_table_t *slidx,
495 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
496 struct ia64_sal_os_state *sos)
497 {
498 u64 target_identifier;
499 pal_min_state_area_t *pmsa;
500 struct ia64_psr *psr1, *psr2;
501 ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
502
503
504 target_identifier = get_target_identifier(peidx);
505 if (!target_identifier)
506 return fatal_mca("target address not valid");
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523 if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
524 return fatal_mca("minstate not valid");
525 psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
526 psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
527
528
529
530
531
532
533 pmsa = sos->pal_min_state;
534 if (psr1->cpl != 0 ||
535 ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
536
537
538
539
540
541 pmsa->pmsa_gr[8-1] = target_identifier;
542 pmsa->pmsa_gr[9-1] = pmsa->pmsa_iip;
543 pmsa->pmsa_gr[10-1] = pmsa->pmsa_ipsr;
544
545 pmsa->pmsa_br0 = pmsa->pmsa_iip;
546
547 pmsa->pmsa_iip = mca_hdlr_bh->fp;
548 pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
549
550 psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
551 psr2->cpl = 0;
552 psr2->ri = 0;
553 psr2->bn = 1;
554 psr2->i = 0;
555
556 return mca_recovered("user memory corruption. "
557 "kill affected process - recovered.");
558 }
559
560 return fatal_mca("kernel context not recovered, iip 0x%lx\n",
561 pmsa->pmsa_iip);
562 }
563
564
565
566
567
568
569
570
571
572
573
574
575 static int
576 recover_from_platform_error(slidx_table_t *slidx, peidx_table_t *peidx,
577 pal_bus_check_info_t *pbci,
578 struct ia64_sal_os_state *sos)
579 {
580 int status = 0;
581 pal_processor_state_info_t *psp =
582 (pal_processor_state_info_t*)peidx_psp(peidx);
583
584 if (psp->bc && pbci->eb && pbci->bsi == 0) {
585 switch(pbci->type) {
586 case 1:
587 case 3:
588 case 9:
589 status = recover_from_read_error(slidx, peidx, pbci,
590 sos);
591 break;
592 case 0:
593 case 2:
594 case 4:
595 case 5:
596 case 6:
597 case 7:
598 case 8:
599 case 10:
600 case 11:
601 case 12:
602
603 default:
604 break;
605 }
606 } else if (psp->cc && !psp->bc) {
607 status = recover_from_read_error(slidx, peidx, pbci, sos);
608 }
609
610 return status;
611 }
612
613
614
615
616
617
618
619
620 static int
621 recover_from_tlb_check(peidx_table_t *peidx)
622 {
623 sal_log_mod_error_info_t *smei;
624 pal_tlb_check_info_t *ptci;
625
626 smei = (sal_log_mod_error_info_t *)peidx_tlb_check(peidx, 0);
627 ptci = (pal_tlb_check_info_t *)&(smei->check_info);
628
629
630
631
632
633 if (ptci->op == PAL_TLB_CHECK_OP_PURGE
634 && !(ptci->itr || ptci->dtc || ptci->itc))
635 return fatal_mca("Duplicate TLB entry");
636
637 return mca_recovered("TLB check recovered");
638 }
639
640
641
642
643
644
645
646
647
648
649
650
651
652 static int
653 recover_from_processor_error(int platform, slidx_table_t *slidx,
654 peidx_table_t *peidx, pal_bus_check_info_t *pbci,
655 struct ia64_sal_os_state *sos)
656 {
657 pal_processor_state_info_t *psp =
658 (pal_processor_state_info_t*)peidx_psp(peidx);
659
660
661
662
663
664
665
666
667
668 if (psp->cm == 1)
669 return mca_recovered("machine check is already corrected.");
670
671
672
673
674 if (psp->us || psp->ci == 0)
675 return fatal_mca("error not contained");
676
677
678
679
680 if (psp->tc && !(psp->cc || psp->bc || psp->rc || psp->uc))
681 return recover_from_tlb_check(peidx);
682
683
684
685
686
687
688
689
690
691 if (psp->cc == 0 && (psp->bc == 0 || pbci == NULL))
692 return fatal_mca("No cache or bus check");
693
694
695
696
697 if (peidx_bus_check_num(peidx) > 1)
698 return fatal_mca("Too many bus checks");
699
700 if (pbci->ib)
701 return fatal_mca("Internal Bus error");
702 if (pbci->eb && pbci->bsi > 0)
703 return fatal_mca("External bus check fatal status");
704
705
706
707
708 if (platform)
709 return recover_from_platform_error(slidx, peidx, pbci, sos);
710
711
712
713
714 return fatal_mca("Strange SAL record");
715 }
716
717
718
719
720
721
722
723
724
725
726 static int
727 mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
728 {
729 int platform_err;
730 int n_proc_err;
731 slidx_table_t slidx;
732 peidx_table_t peidx;
733 pal_bus_check_info_t pbci;
734
735
736 platform_err = mca_make_slidx(rec, &slidx);
737
738
739 n_proc_err = slidx_count(&slidx, proc_err);
740
741
742 if (n_proc_err > 1)
743 return fatal_mca("Too Many Errors");
744 else if (n_proc_err == 0)
745
746 return fatal_mca("Weird SAL record");
747
748
749 mca_make_peidx((sal_log_processor_info_t*)
750 slidx_first_entry(&slidx.proc_err)->hdr, &peidx);
751
752
753 *((u64*)&pbci) = peidx_check_info(&peidx, bus_check, 0);
754
755
756 if (is_mca_global(&peidx, &pbci, sos))
757 return fatal_mca("global MCA");
758
759
760 return recover_from_processor_error(platform_err, &slidx, &peidx,
761 &pbci, sos);
762 }
763
764
765
766
767
768 int __init mca_external_handler_init(void)
769 {
770 if (init_record_index_pools())
771 return -ENOMEM;
772
773
774 if (ia64_reg_MCA_extension(mca_try_to_recover)) {
775 printk(KERN_ERR "ia64_reg_MCA_extension failed.\n");
776 kfree(slidx_pool.buffer);
777 return -EFAULT;
778 }
779 return 0;
780 }
781
782 void __exit mca_external_handler_exit(void)
783 {
784
785 ia64_unreg_MCA_extension();
786 kfree(slidx_pool.buffer);
787 }
788
789 module_init(mca_external_handler_init);
790 module_exit(mca_external_handler_exit);
791
792 module_param(sal_rec_max, int, 0644);
793 MODULE_PARM_DESC(sal_rec_max, "Max size of SAL error record");
794
795 MODULE_DESCRIPTION("ia64 platform dependent mca handler driver");
796 MODULE_LICENSE("GPL");