1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/kernel.h> 3 #include <linux/stdarg.h> 4 #include <linux/string.h> 5 #include <linux/ctype.h> 6 #include <asm/pgmcheck-defs.h> 7 #include <asm/stacktrace.h> 8 #include <asm/boot_data.h> 9 #include <asm/lowcore.h> 10 #include <asm/processor.h> 11 #include <asm/setup.h> 12 #include <asm/sclp.h> 13 #include <asm/uv.h> 14 #include "boot.h" 15 16 void print_stacktrace(unsigned long sp) 17 { 18 struct stack_info boot_stack = { STACK_TYPE_TASK, (unsigned long)_stack_start, 19 (unsigned long)_stack_end }; 20 bool first = true; 21 22 boot_emerg("Call Trace:\n"); 23 while (!(sp & 0x7) && on_stack(&boot_stack, sp, sizeof(struct stack_frame))) { 24 struct stack_frame *sf = (struct stack_frame *)sp; 25 26 if (first) 27 boot_emerg("(sp:%016lx [<%016lx>] %pS)\n", sp, sf->gprs[8], (void *)sf->gprs[8]); 28 else 29 boot_emerg(" sp:%016lx [<%016lx>] %pS\n", sp, sf->gprs[8], (void *)sf->gprs[8]); 30 if (sf->back_chain <= sp) 31 break; 32 sp = sf->back_chain; 33 first = false; 34 } 35 } 36 37 extern struct exception_table_entry __start___ex_table[]; 38 extern struct exception_table_entry __stop___ex_table[]; 39 40 static inline unsigned long extable_insn(const struct exception_table_entry *x) 41 { 42 return (unsigned long)&x->insn + x->insn; 43 } 44 45 static unsigned long boot_get_trap_ip(struct pt_regs *regs) 46 { 47 static const unsigned long nullified[2] = { PGM_CHECKS_NULLIFIED }; 48 49 if (test_bit(regs->int_code & PGM_INT_CODE_MASK, nullified)) 50 return regs->psw.addr; 51 return __rewind_psw(regs->psw, regs->int_code >> 16); 52 } 53 54 static bool ex_handler(struct pt_regs *regs) 55 { 56 const struct exception_table_entry *ex; 57 unsigned long ip = boot_get_trap_ip(regs); 58 59 for (ex = __start___ex_table; ex < __stop___ex_table; ex++) { 60 if (extable_insn(ex) != ip) 61 continue; 62 if (ex->type != EX_TYPE_FIXUP) 63 return false; 64 regs->psw.addr = extable_fixup(ex); 65 return true; 66 } 67 return false; 68 } 69 70 void do_pgm_check(struct pt_regs *regs) 71 { 72 struct psw_bits *psw = &psw_bits(regs->psw); 73 unsigned long *gpregs = regs->gprs; 74 75 if (ex_handler(regs)) 76 return; 77 if (bootdebug) 78 boot_rb_dump(); 79 boot_emerg("Linux version %s\n", kernel_version); 80 if (!is_prot_virt_guest() && early_command_line[0]) 81 boot_emerg("Kernel command line: %s\n", early_command_line); 82 boot_emerg("Kernel fault: interruption code %04x ilc:%d\n", 83 regs->int_code & 0xffff, regs->int_code >> 17); 84 if (kaslr_enabled()) { 85 boot_emerg("Kernel random base: %lx\n", __kaslr_offset); 86 boot_emerg("Kernel random base phys: %lx\n", __kaslr_offset_phys); 87 } 88 boot_emerg("PSW : %016lx %016lx (%pS)\n", 89 regs->psw.mask, regs->psw.addr, (void *)regs->psw.addr); 90 boot_emerg(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x P:%x AS:%x CC:%x PM:%x RI:%x EA:%x\n", 91 psw->per, psw->dat, psw->io, psw->ext, psw->key, psw->mcheck, 92 psw->wait, psw->pstate, psw->as, psw->cc, psw->pm, psw->ri, psw->eaba); 93 boot_emerg("GPRS: %016lx %016lx %016lx %016lx\n", gpregs[0], gpregs[1], gpregs[2], gpregs[3]); 94 boot_emerg(" %016lx %016lx %016lx %016lx\n", gpregs[4], gpregs[5], gpregs[6], gpregs[7]); 95 boot_emerg(" %016lx %016lx %016lx %016lx\n", gpregs[8], gpregs[9], gpregs[10], gpregs[11]); 96 boot_emerg(" %016lx %016lx %016lx %016lx\n", gpregs[12], gpregs[13], gpregs[14], gpregs[15]); 97 print_stacktrace(gpregs[15]); 98 boot_emerg("Last Breaking-Event-Address:\n"); 99 boot_emerg(" [<%016lx>] %pS\n", regs->last_break, (void *)regs->last_break); 100 /* Convert to disabled wait PSW */ 101 psw->io = 0; 102 psw->ext = 0; 103 psw->wait = 1; 104 } 105