|
@@ -16,261 +16,145 @@
|
|
|
|
|
|
#include <asm/stacktrace.h>
|
|
#include <asm/stacktrace.h>
|
|
|
|
|
|
|
|
+static char *exception_stack_names[N_EXCEPTION_STACKS] = {
|
|
|
|
+ [ DOUBLEFAULT_STACK-1 ] = "#DF",
|
|
|
|
+ [ NMI_STACK-1 ] = "NMI",
|
|
|
|
+ [ DEBUG_STACK-1 ] = "#DB",
|
|
|
|
+ [ MCE_STACK-1 ] = "#MC",
|
|
|
|
+};
|
|
|
|
|
|
-#define N_EXCEPTION_STACKS_END \
|
|
|
|
- (N_EXCEPTION_STACKS + DEBUG_STKSZ/EXCEPTION_STKSZ - 2)
|
|
|
|
-
|
|
|
|
-static char x86_stack_ids[][8] = {
|
|
|
|
- [ DEBUG_STACK-1 ] = "#DB",
|
|
|
|
- [ NMI_STACK-1 ] = "NMI",
|
|
|
|
- [ DOUBLEFAULT_STACK-1 ] = "#DF",
|
|
|
|
- [ MCE_STACK-1 ] = "#MC",
|
|
|
|
-#if DEBUG_STKSZ > EXCEPTION_STKSZ
|
|
|
|
- [ N_EXCEPTION_STACKS ...
|
|
|
|
- N_EXCEPTION_STACKS_END ] = "#DB[?]"
|
|
|
|
-#endif
|
|
|
|
|
|
+static unsigned long exception_stack_sizes[N_EXCEPTION_STACKS] = {
|
|
|
|
+ [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STKSZ,
|
|
|
|
+ [DEBUG_STACK - 1] = DEBUG_STKSZ
|
|
};
|
|
};
|
|
|
|
|
|
-static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
|
|
|
|
- unsigned *usedp, char **idp)
|
|
|
|
|
|
+void stack_type_str(enum stack_type type, const char **begin, const char **end)
|
|
{
|
|
{
|
|
- unsigned k;
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- * Iterate over all exception stacks, and figure out whether
|
|
|
|
- * 'stack' is in one of them:
|
|
|
|
- */
|
|
|
|
- for (k = 0; k < N_EXCEPTION_STACKS; k++) {
|
|
|
|
- unsigned long end = per_cpu(orig_ist, cpu).ist[k];
|
|
|
|
- /*
|
|
|
|
- * Is 'stack' above this exception frame's end?
|
|
|
|
- * If yes then skip to the next frame.
|
|
|
|
- */
|
|
|
|
- if (stack >= end)
|
|
|
|
- continue;
|
|
|
|
- /*
|
|
|
|
- * Is 'stack' above this exception frame's start address?
|
|
|
|
- * If yes then we found the right frame.
|
|
|
|
- */
|
|
|
|
- if (stack >= end - EXCEPTION_STKSZ) {
|
|
|
|
- /*
|
|
|
|
- * Make sure we only iterate through an exception
|
|
|
|
- * stack once. If it comes up for the second time
|
|
|
|
- * then there's something wrong going on - just
|
|
|
|
- * break out and return NULL:
|
|
|
|
- */
|
|
|
|
- if (*usedp & (1U << k))
|
|
|
|
- break;
|
|
|
|
- *usedp |= 1U << k;
|
|
|
|
- *idp = x86_stack_ids[k];
|
|
|
|
- return (unsigned long *)end;
|
|
|
|
- }
|
|
|
|
- /*
|
|
|
|
- * If this is a debug stack, and if it has a larger size than
|
|
|
|
- * the usual exception stacks, then 'stack' might still
|
|
|
|
- * be within the lower portion of the debug stack:
|
|
|
|
- */
|
|
|
|
-#if DEBUG_STKSZ > EXCEPTION_STKSZ
|
|
|
|
- if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
|
|
|
|
- unsigned j = N_EXCEPTION_STACKS - 1;
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- * Black magic. A large debug stack is composed of
|
|
|
|
- * multiple exception stack entries, which we
|
|
|
|
- * iterate through now. Dont look:
|
|
|
|
- */
|
|
|
|
- do {
|
|
|
|
- ++j;
|
|
|
|
- end -= EXCEPTION_STKSZ;
|
|
|
|
- x86_stack_ids[j][4] = '1' +
|
|
|
|
- (j - N_EXCEPTION_STACKS);
|
|
|
|
- } while (stack < end - EXCEPTION_STKSZ);
|
|
|
|
- if (*usedp & (1U << j))
|
|
|
|
- break;
|
|
|
|
- *usedp |= 1U << j;
|
|
|
|
- *idp = x86_stack_ids[j];
|
|
|
|
- return (unsigned long *)end;
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
|
|
+ BUILD_BUG_ON(N_EXCEPTION_STACKS != 4);
|
|
|
|
+
|
|
|
|
+ switch (type) {
|
|
|
|
+ case STACK_TYPE_IRQ:
|
|
|
|
+ *begin = "IRQ";
|
|
|
|
+ *end = "EOI";
|
|
|
|
+ break;
|
|
|
|
+ case STACK_TYPE_EXCEPTION ... STACK_TYPE_EXCEPTION_LAST:
|
|
|
|
+ *begin = exception_stack_names[type - STACK_TYPE_EXCEPTION];
|
|
|
|
+ *end = "EOE";
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ *begin = NULL;
|
|
|
|
+ *end = NULL;
|
|
}
|
|
}
|
|
- return NULL;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-static inline int
|
|
|
|
-in_irq_stack(unsigned long *stack, unsigned long *irq_stack,
|
|
|
|
- unsigned long *irq_stack_end)
|
|
|
|
|
|
+static bool in_exception_stack(unsigned long *stack, struct stack_info *info)
|
|
{
|
|
{
|
|
- return (stack >= irq_stack && stack < irq_stack_end);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static const unsigned long irq_stack_size =
|
|
|
|
- (IRQ_STACK_SIZE - 64) / sizeof(unsigned long);
|
|
|
|
-
|
|
|
|
-enum stack_type {
|
|
|
|
- STACK_IS_UNKNOWN,
|
|
|
|
- STACK_IS_NORMAL,
|
|
|
|
- STACK_IS_EXCEPTION,
|
|
|
|
- STACK_IS_IRQ,
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-static enum stack_type
|
|
|
|
-analyze_stack(int cpu, struct task_struct *task, unsigned long *stack,
|
|
|
|
- unsigned long **stack_end, unsigned long *irq_stack,
|
|
|
|
- unsigned *used, char **id)
|
|
|
|
-{
|
|
|
|
- unsigned long addr;
|
|
|
|
|
|
+ unsigned long *begin, *end;
|
|
|
|
+ struct pt_regs *regs;
|
|
|
|
+ unsigned k;
|
|
|
|
|
|
- addr = ((unsigned long)stack & (~(THREAD_SIZE - 1)));
|
|
|
|
- if ((unsigned long)task_stack_page(task) == addr)
|
|
|
|
- return STACK_IS_NORMAL;
|
|
|
|
|
|
+ BUILD_BUG_ON(N_EXCEPTION_STACKS != 4);
|
|
|
|
|
|
- *stack_end = in_exception_stack(cpu, (unsigned long)stack,
|
|
|
|
- used, id);
|
|
|
|
- if (*stack_end)
|
|
|
|
- return STACK_IS_EXCEPTION;
|
|
|
|
|
|
+ for (k = 0; k < N_EXCEPTION_STACKS; k++) {
|
|
|
|
+ end = (unsigned long *)raw_cpu_ptr(&orig_ist)->ist[k];
|
|
|
|
+ begin = end - (exception_stack_sizes[k] / sizeof(long));
|
|
|
|
+ regs = (struct pt_regs *)end - 1;
|
|
|
|
|
|
- if (!irq_stack)
|
|
|
|
- return STACK_IS_NORMAL;
|
|
|
|
|
|
+ if (stack < begin || stack >= end)
|
|
|
|
+ continue;
|
|
|
|
|
|
- *stack_end = irq_stack;
|
|
|
|
- irq_stack = irq_stack - irq_stack_size;
|
|
|
|
|
|
+ info->type = STACK_TYPE_EXCEPTION + k;
|
|
|
|
+ info->begin = begin;
|
|
|
|
+ info->end = end;
|
|
|
|
+ info->next_sp = (unsigned long *)regs->sp;
|
|
|
|
|
|
- if (in_irq_stack(stack, irq_stack, *stack_end))
|
|
|
|
- return STACK_IS_IRQ;
|
|
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
|
|
- return STACK_IS_UNKNOWN;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
- * x86-64 can have up to three kernel stacks:
|
|
|
|
- * process stack
|
|
|
|
- * interrupt stack
|
|
|
|
- * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-void dump_trace(struct task_struct *task, struct pt_regs *regs,
|
|
|
|
- unsigned long *stack, unsigned long bp,
|
|
|
|
- const struct stacktrace_ops *ops, void *data)
|
|
|
|
|
|
+static bool in_irq_stack(unsigned long *stack, struct stack_info *info)
|
|
{
|
|
{
|
|
- const unsigned cpu = get_cpu();
|
|
|
|
- unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
|
|
|
|
- unsigned long dummy;
|
|
|
|
- unsigned used = 0;
|
|
|
|
- int graph = 0;
|
|
|
|
- int done = 0;
|
|
|
|
-
|
|
|
|
- if (!task)
|
|
|
|
- task = current;
|
|
|
|
-
|
|
|
|
- if (!stack) {
|
|
|
|
- if (regs)
|
|
|
|
- stack = (unsigned long *)regs->sp;
|
|
|
|
- else if (task != current)
|
|
|
|
- stack = (unsigned long *)task->thread.sp;
|
|
|
|
- else
|
|
|
|
- stack = &dummy;
|
|
|
|
- }
|
|
|
|
|
|
+ unsigned long *end = (unsigned long *)this_cpu_read(irq_stack_ptr);
|
|
|
|
+ unsigned long *begin = end - (IRQ_STACK_SIZE / sizeof(long));
|
|
|
|
|
|
- if (!bp)
|
|
|
|
- bp = stack_frame(task, regs);
|
|
|
|
/*
|
|
/*
|
|
- * Print function call entries in all stacks, starting at the
|
|
|
|
- * current stack address. If the stacks consist of nested
|
|
|
|
- * exceptions
|
|
|
|
|
|
+ * This is a software stack, so 'end' can be a valid stack pointer.
|
|
|
|
+ * It just means the stack is empty.
|
|
*/
|
|
*/
|
|
- while (!done) {
|
|
|
|
- unsigned long *stack_end;
|
|
|
|
- enum stack_type stype;
|
|
|
|
- char *id;
|
|
|
|
|
|
+ if (stack < begin || stack > end)
|
|
|
|
+ return false;
|
|
|
|
|
|
- stype = analyze_stack(cpu, task, stack, &stack_end,
|
|
|
|
- irq_stack, &used, &id);
|
|
|
|
|
|
+ info->type = STACK_TYPE_IRQ;
|
|
|
|
+ info->begin = begin;
|
|
|
|
+ info->end = end;
|
|
|
|
|
|
- /* Default finish unless specified to continue */
|
|
|
|
- done = 1;
|
|
|
|
|
|
+ /*
|
|
|
|
+ * The next stack pointer is the first thing pushed by the entry code
|
|
|
|
+ * after switching to the irq stack.
|
|
|
|
+ */
|
|
|
|
+ info->next_sp = (unsigned long *)*(end - 1);
|
|
|
|
|
|
- switch (stype) {
|
|
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
|
|
- /* Break out early if we are on the thread stack */
|
|
|
|
- case STACK_IS_NORMAL:
|
|
|
|
- break;
|
|
|
|
|
|
+int get_stack_info(unsigned long *stack, struct task_struct *task,
|
|
|
|
+ struct stack_info *info, unsigned long *visit_mask)
|
|
|
|
+{
|
|
|
|
+ if (!stack)
|
|
|
|
+ goto unknown;
|
|
|
|
|
|
- case STACK_IS_EXCEPTION:
|
|
|
|
|
|
+ task = task ? : current;
|
|
|
|
|
|
- if (ops->stack(data, id) < 0)
|
|
|
|
- break;
|
|
|
|
|
|
+ if (in_task_stack(stack, task, info))
|
|
|
|
+ goto recursion_check;
|
|
|
|
|
|
- bp = ops->walk_stack(task, stack, bp, ops,
|
|
|
|
- data, stack_end, &graph);
|
|
|
|
- ops->stack(data, "<EOE>");
|
|
|
|
- /*
|
|
|
|
- * We link to the next stack via the
|
|
|
|
- * second-to-last pointer (index -2 to end) in the
|
|
|
|
- * exception stack:
|
|
|
|
- */
|
|
|
|
- stack = (unsigned long *) stack_end[-2];
|
|
|
|
- done = 0;
|
|
|
|
- break;
|
|
|
|
|
|
+ if (task != current)
|
|
|
|
+ goto unknown;
|
|
|
|
|
|
- case STACK_IS_IRQ:
|
|
|
|
|
|
+ if (in_exception_stack(stack, info))
|
|
|
|
+ goto recursion_check;
|
|
|
|
|
|
- if (ops->stack(data, "IRQ") < 0)
|
|
|
|
- break;
|
|
|
|
- bp = ops->walk_stack(task, stack, bp,
|
|
|
|
- ops, data, stack_end, &graph);
|
|
|
|
- /*
|
|
|
|
- * We link to the next stack (which would be
|
|
|
|
- * the process stack normally) the last
|
|
|
|
- * pointer (index -1 to end) in the IRQ stack:
|
|
|
|
- */
|
|
|
|
- stack = (unsigned long *) (stack_end[-1]);
|
|
|
|
- irq_stack = NULL;
|
|
|
|
- ops->stack(data, "EOI");
|
|
|
|
- done = 0;
|
|
|
|
- break;
|
|
|
|
|
|
+ if (in_irq_stack(stack, info))
|
|
|
|
+ goto recursion_check;
|
|
|
|
|
|
- case STACK_IS_UNKNOWN:
|
|
|
|
- ops->stack(data, "UNK");
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ goto unknown;
|
|
|
|
|
|
|
|
+recursion_check:
|
|
/*
|
|
/*
|
|
- * This handles the process stack:
|
|
|
|
|
|
+ * Make sure we don't iterate through any given stack more than once.
|
|
|
|
+ * If it comes up a second time then there's something wrong going on:
|
|
|
|
+ * just break out and report an unknown stack type.
|
|
*/
|
|
*/
|
|
- bp = ops->walk_stack(task, stack, bp, ops, data, NULL, &graph);
|
|
|
|
- put_cpu();
|
|
|
|
|
|
+ if (visit_mask) {
|
|
|
|
+ if (*visit_mask & (1UL << info->type))
|
|
|
|
+ goto unknown;
|
|
|
|
+ *visit_mask |= 1UL << info->type;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
+unknown:
|
|
|
|
+ info->type = STACK_TYPE_UNKNOWN;
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
-EXPORT_SYMBOL(dump_trace);
|
|
|
|
|
|
|
|
-void
|
|
|
|
-show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
|
|
|
|
- unsigned long *sp, unsigned long bp, char *log_lvl)
|
|
|
|
|
|
+void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
|
|
|
|
+ unsigned long *sp, char *log_lvl)
|
|
{
|
|
{
|
|
unsigned long *irq_stack_end;
|
|
unsigned long *irq_stack_end;
|
|
unsigned long *irq_stack;
|
|
unsigned long *irq_stack;
|
|
unsigned long *stack;
|
|
unsigned long *stack;
|
|
- int cpu;
|
|
|
|
int i;
|
|
int i;
|
|
|
|
|
|
- preempt_disable();
|
|
|
|
- cpu = smp_processor_id();
|
|
|
|
|
|
+ if (!try_get_task_stack(task))
|
|
|
|
+ return;
|
|
|
|
|
|
- irq_stack_end = (unsigned long *)(per_cpu(irq_stack_ptr, cpu));
|
|
|
|
- irq_stack = (unsigned long *)(per_cpu(irq_stack_ptr, cpu) - IRQ_STACK_SIZE);
|
|
|
|
|
|
+ irq_stack_end = (unsigned long *)this_cpu_read(irq_stack_ptr);
|
|
|
|
+ irq_stack = irq_stack_end - (IRQ_STACK_SIZE / sizeof(long));
|
|
|
|
|
|
- /*
|
|
|
|
- * Debugging aid: "show_stack(NULL, NULL);" prints the
|
|
|
|
- * back trace for this cpu:
|
|
|
|
- */
|
|
|
|
- if (sp == NULL) {
|
|
|
|
- if (regs)
|
|
|
|
- sp = (unsigned long *)regs->sp;
|
|
|
|
- else if (task)
|
|
|
|
- sp = (unsigned long *)task->thread.sp;
|
|
|
|
- else
|
|
|
|
- sp = (unsigned long *)&sp;
|
|
|
|
- }
|
|
|
|
|
|
+ sp = sp ? : get_stack_pointer(task, regs);
|
|
|
|
|
|
stack = sp;
|
|
stack = sp;
|
|
for (i = 0; i < kstack_depth_to_print; i++) {
|
|
for (i = 0; i < kstack_depth_to_print; i++) {
|
|
@@ -299,18 +183,17 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
|
|
stack++;
|
|
stack++;
|
|
touch_nmi_watchdog();
|
|
touch_nmi_watchdog();
|
|
}
|
|
}
|
|
- preempt_enable();
|
|
|
|
|
|
|
|
pr_cont("\n");
|
|
pr_cont("\n");
|
|
- show_trace_log_lvl(task, regs, sp, bp, log_lvl);
|
|
|
|
|
|
+ show_trace_log_lvl(task, regs, sp, log_lvl);
|
|
|
|
+
|
|
|
|
+ put_task_stack(task);
|
|
}
|
|
}
|
|
|
|
|
|
void show_regs(struct pt_regs *regs)
|
|
void show_regs(struct pt_regs *regs)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
- unsigned long sp;
|
|
|
|
|
|
|
|
- sp = regs->sp;
|
|
|
|
show_regs_print_info(KERN_DEFAULT);
|
|
show_regs_print_info(KERN_DEFAULT);
|
|
__show_regs(regs, 1);
|
|
__show_regs(regs, 1);
|
|
|
|
|
|
@@ -325,8 +208,7 @@ void show_regs(struct pt_regs *regs)
|
|
u8 *ip;
|
|
u8 *ip;
|
|
|
|
|
|
printk(KERN_DEFAULT "Stack:\n");
|
|
printk(KERN_DEFAULT "Stack:\n");
|
|
- show_stack_log_lvl(NULL, regs, (unsigned long *)sp,
|
|
|
|
- 0, KERN_DEFAULT);
|
|
|
|
|
|
+ show_stack_log_lvl(current, regs, NULL, KERN_DEFAULT);
|
|
|
|
|
|
printk(KERN_DEFAULT "Code: ");
|
|
printk(KERN_DEFAULT "Code: ");
|
|
|
|
|