Commit 2223f6f6 authored by Steven Rostedt's avatar Steven Rostedt Committed by H. Peter Anvin

x86: Clean up dumpstack_64.c code

The dump_trace() function in dumpstack_64.c is hard to follow.
The test for exception stack is processed differently than the
test for irq stack, and the normal stack is outside completely.

By restructuring this code to have all the stacks determined by
a single function that returns an enum of the following:

 STACK_IS_NORMAL
 STACK_IS_EXCEPTION
 STACK_IS_IRQ
 STACK_IS_UNKNOWN

and has the logic of each within a switch statement.
This should make the code much easier to read and understand.

Link: http://lkml.kernel.org/r/20110806012354.684598995@goodmis.org

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Brian Gerst <brgerst@gmail.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/20140206144322.086050042@goodmis.orgSigned-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
parent 198d208d
...@@ -104,6 +104,45 @@ in_irq_stack(unsigned long *stack, unsigned long *irq_stack, ...@@ -104,6 +104,45 @@ in_irq_stack(unsigned long *stack, unsigned long *irq_stack,
return (stack >= irq_stack && stack < irq_stack_end); 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, char **id)
{
unsigned long *irq_stack;
unsigned long addr;
unsigned used = 0;
addr = ((unsigned long)stack & (~(THREAD_SIZE - 1)));
if ((unsigned long)task_stack_page(task) == addr)
return STACK_IS_NORMAL;
*stack_end = in_exception_stack(cpu, (unsigned long)stack,
&used, id);
if (*stack_end)
return STACK_IS_EXCEPTION;
*stack_end = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
if (!*stack_end)
return STACK_IS_UNKNOWN;
irq_stack = *stack_end - irq_stack_size;
if (in_irq_stack(stack, irq_stack, *stack_end))
return STACK_IS_IRQ;
return STACK_IS_UNKNOWN;
}
/* /*
* x86-64 can have up to three kernel stacks: * x86-64 can have up to three kernel stacks:
* process stack * process stack
...@@ -116,12 +155,11 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, ...@@ -116,12 +155,11 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
const struct stacktrace_ops *ops, void *data) const struct stacktrace_ops *ops, void *data)
{ {
const unsigned cpu = get_cpu(); const unsigned cpu = get_cpu();
unsigned long *irq_stack_end =
(unsigned long *)per_cpu(irq_stack_ptr, cpu);
unsigned used = 0;
struct thread_info *tinfo; struct thread_info *tinfo;
int graph = 0; unsigned long *irq_stack;
unsigned long dummy; unsigned long dummy;
int graph = 0;
int done = 0;
if (!task) if (!task)
task = current; task = current;
...@@ -143,50 +181,61 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, ...@@ -143,50 +181,61 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
* exceptions * exceptions
*/ */
tinfo = task_thread_info(task); tinfo = task_thread_info(task);
for (;;) { while (!done) {
unsigned long *stack_end;
enum stack_type stype;
char *id; char *id;
unsigned long *estack_end;
estack_end = in_exception_stack(cpu, (unsigned long)stack,
&used, &id);
if (estack_end) { stype = analyze_stack(cpu, task, stack, &stack_end, &id);
/* Default finish unless specified to continue */
done = 1;
switch (stype) {
/* Break out early if we are on the thread stack */
case STACK_IS_NORMAL:
break;
case STACK_IS_EXCEPTION:
if (ops->stack(data, id) < 0) if (ops->stack(data, id) < 0)
break; break;
bp = ops->walk_stack(tinfo, stack, bp, ops, bp = ops->walk_stack(tinfo, stack, bp, ops,
data, estack_end, &graph); data, stack_end, &graph);
ops->stack(data, "<EOE>"); ops->stack(data, "<EOE>");
/* /*
* We link to the next stack via the * We link to the next stack via the
* second-to-last pointer (index -2 to end) in the * second-to-last pointer (index -2 to end) in the
* exception stack: * exception stack:
*/ */
stack = (unsigned long *) estack_end[-2]; stack = (unsigned long *) stack_end[-2];
continue; done = 0;
} break;
if (irq_stack_end) {
unsigned long *irq_stack; case STACK_IS_IRQ:
irq_stack = irq_stack_end -
(IRQ_STACK_SIZE - 64) / sizeof(*irq_stack);
if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
if (ops->stack(data, "IRQ") < 0) if (ops->stack(data, "IRQ") < 0)
break; break;
bp = ops->walk_stack(tinfo, stack, bp, bp = ops->walk_stack(tinfo, stack, bp,
ops, data, irq_stack_end, &graph); ops, data, stack_end, &graph);
/* /*
* We link to the next stack (which would be * We link to the next stack (which would be
* the process stack normally) the last * the process stack normally) the last
* pointer (index -1 to end) in the IRQ stack: * pointer (index -1 to end) in the IRQ stack:
*/ */
stack = (unsigned long *) (irq_stack_end[-1]); stack = (unsigned long *) (stack_end[-1]);
irq_stack_end = NULL; irq_stack = stack_end - irq_stack_size;
ops->stack(data, "EOI"); ops->stack(data, "EOI");
continue; done = 0;
} break;
}
case STACK_IS_UNKNOWN:
ops->stack(data, "UNK");
break; break;
} }
}
/* /*
* This handles the process stack: * This handles the process stack:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment