0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/kallsyms.h>
0009 #include <linux/hardirq.h>
0010 #include <linux/kprobes.h>
0011 #include <linux/utsname.h>
0012 #include <linux/export.h>
0013 #include <linux/kdebug.h>
0014 #include <linux/ptrace.h>
0015 #include <linux/mm.h>
0016 #include <linux/module.h>
0017 #include <linux/sched.h>
0018 #include <linux/sched/debug.h>
0019 #include <linux/sched/task_stack.h>
0020 #include <asm/processor.h>
0021 #include <asm/debug.h>
0022 #include <asm/dis.h>
0023 #include <asm/ipl.h>
0024 #include <asm/unwind.h>
0025
0026 const char *stack_type_name(enum stack_type type)
0027 {
0028 switch (type) {
0029 case STACK_TYPE_TASK:
0030 return "task";
0031 case STACK_TYPE_IRQ:
0032 return "irq";
0033 case STACK_TYPE_NODAT:
0034 return "nodat";
0035 case STACK_TYPE_RESTART:
0036 return "restart";
0037 default:
0038 return "unknown";
0039 }
0040 }
0041 EXPORT_SYMBOL_GPL(stack_type_name);
0042
0043 static inline bool in_stack(unsigned long sp, struct stack_info *info,
0044 enum stack_type type, unsigned long low,
0045 unsigned long high)
0046 {
0047 if (sp < low || sp >= high)
0048 return false;
0049 info->type = type;
0050 info->begin = low;
0051 info->end = high;
0052 return true;
0053 }
0054
0055 static bool in_task_stack(unsigned long sp, struct task_struct *task,
0056 struct stack_info *info)
0057 {
0058 unsigned long stack;
0059
0060 stack = (unsigned long) task_stack_page(task);
0061 return in_stack(sp, info, STACK_TYPE_TASK, stack, stack + THREAD_SIZE);
0062 }
0063
0064 static bool in_irq_stack(unsigned long sp, struct stack_info *info)
0065 {
0066 unsigned long frame_size, top;
0067
0068 frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
0069 top = S390_lowcore.async_stack + frame_size;
0070 return in_stack(sp, info, STACK_TYPE_IRQ, top - THREAD_SIZE, top);
0071 }
0072
0073 static bool in_nodat_stack(unsigned long sp, struct stack_info *info)
0074 {
0075 unsigned long frame_size, top;
0076
0077 frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
0078 top = S390_lowcore.nodat_stack + frame_size;
0079 return in_stack(sp, info, STACK_TYPE_NODAT, top - THREAD_SIZE, top);
0080 }
0081
0082 static bool in_mcck_stack(unsigned long sp, struct stack_info *info)
0083 {
0084 unsigned long frame_size, top;
0085
0086 frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
0087 top = S390_lowcore.mcck_stack + frame_size;
0088 return in_stack(sp, info, STACK_TYPE_MCCK, top - THREAD_SIZE, top);
0089 }
0090
0091 static bool in_restart_stack(unsigned long sp, struct stack_info *info)
0092 {
0093 unsigned long frame_size, top;
0094
0095 frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
0096 top = S390_lowcore.restart_stack + frame_size;
0097 return in_stack(sp, info, STACK_TYPE_RESTART, top - THREAD_SIZE, top);
0098 }
0099
0100 int get_stack_info(unsigned long sp, struct task_struct *task,
0101 struct stack_info *info, unsigned long *visit_mask)
0102 {
0103 if (!sp)
0104 goto unknown;
0105
0106
0107 if (sp & 0x7)
0108 goto unknown;
0109
0110
0111 if (in_task_stack(sp, task, info))
0112 goto recursion_check;
0113
0114 if (task != current)
0115 goto unknown;
0116
0117
0118 if (!in_irq_stack(sp, info) &&
0119 !in_nodat_stack(sp, info) &&
0120 !in_restart_stack(sp, info) &&
0121 !in_mcck_stack(sp, info))
0122 goto unknown;
0123
0124 recursion_check:
0125
0126
0127
0128
0129
0130 if (*visit_mask & (1UL << info->type))
0131 goto unknown;
0132 *visit_mask |= 1UL << info->type;
0133 return 0;
0134 unknown:
0135 info->type = STACK_TYPE_UNKNOWN;
0136 return -EINVAL;
0137 }
0138
0139 void show_stack(struct task_struct *task, unsigned long *stack,
0140 const char *loglvl)
0141 {
0142 struct unwind_state state;
0143
0144 printk("%sCall Trace:\n", loglvl);
0145 unwind_for_each_frame(&state, task, NULL, (unsigned long) stack)
0146 printk(state.reliable ? "%s [<%016lx>] %pSR \n" :
0147 "%s([<%016lx>] %pSR)\n",
0148 loglvl, state.ip, (void *) state.ip);
0149 debug_show_held_locks(task ? : current);
0150 }
0151
0152 static void show_last_breaking_event(struct pt_regs *regs)
0153 {
0154 printk("Last Breaking-Event-Address:\n");
0155 printk(" [<%016lx>] %pSR\n", regs->last_break, (void *)regs->last_break);
0156 }
0157
0158 void show_registers(struct pt_regs *regs)
0159 {
0160 struct psw_bits *psw = &psw_bits(regs->psw);
0161 char *mode;
0162
0163 mode = user_mode(regs) ? "User" : "Krnl";
0164 printk("%s PSW : %px %px", mode, (void *)regs->psw.mask, (void *)regs->psw.addr);
0165 if (!user_mode(regs))
0166 pr_cont(" (%pSR)", (void *)regs->psw.addr);
0167 pr_cont("\n");
0168 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
0169 "P:%x AS:%x CC:%x PM:%x", psw->per, psw->dat, psw->io, psw->ext,
0170 psw->key, psw->mcheck, psw->wait, psw->pstate, psw->as, psw->cc, psw->pm);
0171 pr_cont(" RI:%x EA:%x\n", psw->ri, psw->eaba);
0172 printk("%s GPRS: %016lx %016lx %016lx %016lx\n", mode,
0173 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
0174 printk(" %016lx %016lx %016lx %016lx\n",
0175 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
0176 printk(" %016lx %016lx %016lx %016lx\n",
0177 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
0178 printk(" %016lx %016lx %016lx %016lx\n",
0179 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
0180 show_code(regs);
0181 }
0182
0183 void show_regs(struct pt_regs *regs)
0184 {
0185 show_regs_print_info(KERN_DEFAULT);
0186 show_registers(regs);
0187
0188 if (!user_mode(regs))
0189 show_stack(NULL, (unsigned long *) regs->gprs[15], KERN_DEFAULT);
0190 show_last_breaking_event(regs);
0191 }
0192
0193 static DEFINE_SPINLOCK(die_lock);
0194
0195 void __noreturn die(struct pt_regs *regs, const char *str)
0196 {
0197 static int die_counter;
0198
0199 oops_enter();
0200 lgr_info_log();
0201 debug_stop_all();
0202 console_verbose();
0203 spin_lock_irq(&die_lock);
0204 bust_spinlocks(1);
0205 printk("%s: %04x ilc:%d [#%d] ", str, regs->int_code & 0xffff,
0206 regs->int_code >> 17, ++die_counter);
0207 #ifdef CONFIG_PREEMPT
0208 pr_cont("PREEMPT ");
0209 #elif defined(CONFIG_PREEMPT_RT)
0210 pr_cont("PREEMPT_RT ");
0211 #endif
0212 pr_cont("SMP ");
0213 if (debug_pagealloc_enabled())
0214 pr_cont("DEBUG_PAGEALLOC");
0215 pr_cont("\n");
0216 notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV);
0217 print_modules();
0218 show_regs(regs);
0219 bust_spinlocks(0);
0220 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
0221 spin_unlock_irq(&die_lock);
0222 if (in_interrupt())
0223 panic("Fatal exception in interrupt");
0224 if (panic_on_oops)
0225 panic("Fatal exception: panic_on_oops");
0226 oops_exit();
0227 make_task_dead(SIGSEGV);
0228 }