mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
x86/dumpstack: Add get_stack_info() interface
valid_stack_ptr() is buggy: it assumes that all stacks are of size THREAD_SIZE, which is not true for exception stacks. So the walk_stack() callbacks will need to know the location of the beginning of the stack as well as the end. Another issue is that in general the various features of a stack (type, size, next stack pointer, description string) are scattered around in various places throughout the stack dump code. Encapsulate all that information in a single place with a new stack_info struct and a get_stack_info() interface. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Byungchul Park <byungchul.park@lge.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Nilay Vaish <nilayvaish@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/8164dd0db96b7e6a279fa17ae5e6dc375eecb4a9.1473905218.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
9c00390757
commit
cb76c93982
7 changed files with 238 additions and 132 deletions
|
@ -16,61 +16,117 @@
|
|||
|
||||
#include <asm/stacktrace.h>
|
||||
|
||||
static void *is_irq_stack(void *p, void *irq)
|
||||
void stack_type_str(enum stack_type type, const char **begin, const char **end)
|
||||
{
|
||||
if (p < irq || p >= (irq + THREAD_SIZE))
|
||||
return NULL;
|
||||
return irq + THREAD_SIZE;
|
||||
switch (type) {
|
||||
case STACK_TYPE_IRQ:
|
||||
case STACK_TYPE_SOFTIRQ:
|
||||
*begin = "IRQ";
|
||||
*end = "EOI";
|
||||
break;
|
||||
default:
|
||||
*begin = NULL;
|
||||
*end = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void *is_hardirq_stack(unsigned long *stack)
|
||||
static bool in_hardirq_stack(unsigned long *stack, struct stack_info *info)
|
||||
{
|
||||
void *irq = this_cpu_read(hardirq_stack);
|
||||
unsigned long *begin = (unsigned long *)this_cpu_read(hardirq_stack);
|
||||
unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
|
||||
|
||||
return is_irq_stack(stack, irq);
|
||||
if (stack < begin || stack >= end)
|
||||
return false;
|
||||
|
||||
info->type = STACK_TYPE_IRQ;
|
||||
info->begin = begin;
|
||||
info->end = end;
|
||||
|
||||
/*
|
||||
* See irq_32.c -- the next stack pointer is stored at the beginning of
|
||||
* the stack.
|
||||
*/
|
||||
info->next_sp = (unsigned long *)*begin;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *is_softirq_stack(unsigned long *stack)
|
||||
static bool in_softirq_stack(unsigned long *stack, struct stack_info *info)
|
||||
{
|
||||
void *irq = this_cpu_read(softirq_stack);
|
||||
unsigned long *begin = (unsigned long *)this_cpu_read(softirq_stack);
|
||||
unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
|
||||
|
||||
return is_irq_stack(stack, irq);
|
||||
if (stack < begin || stack >= end)
|
||||
return false;
|
||||
|
||||
info->type = STACK_TYPE_SOFTIRQ;
|
||||
info->begin = begin;
|
||||
info->end = end;
|
||||
|
||||
/*
|
||||
* The next stack pointer is stored at the beginning of the stack.
|
||||
* See irq_32.c.
|
||||
*/
|
||||
info->next_sp = (unsigned long *)*begin;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int get_stack_info(unsigned long *stack, struct task_struct *task,
|
||||
struct stack_info *info, unsigned long *visit_mask)
|
||||
{
|
||||
if (!stack)
|
||||
goto unknown;
|
||||
|
||||
task = task ? : current;
|
||||
|
||||
if (in_task_stack(stack, task, info))
|
||||
return 0;
|
||||
|
||||
if (task != current)
|
||||
goto unknown;
|
||||
|
||||
if (in_hardirq_stack(stack, info))
|
||||
return 0;
|
||||
|
||||
if (in_softirq_stack(stack, info))
|
||||
return 0;
|
||||
|
||||
unknown:
|
||||
info->type = STACK_TYPE_UNKNOWN;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
void dump_trace(struct task_struct *task, struct pt_regs *regs,
|
||||
unsigned long *stack, unsigned long bp,
|
||||
const struct stacktrace_ops *ops, void *data)
|
||||
{
|
||||
unsigned long visit_mask = 0;
|
||||
int graph = 0;
|
||||
u32 *prev_esp;
|
||||
|
||||
task = task ? : current;
|
||||
stack = stack ? : get_stack_pointer(task, regs);
|
||||
bp = bp ? : (unsigned long)get_frame_pointer(task, regs);
|
||||
|
||||
for (;;) {
|
||||
void *end_stack;
|
||||
const char *begin_str, *end_str;
|
||||
struct stack_info info;
|
||||
|
||||
end_stack = is_hardirq_stack(stack);
|
||||
if (!end_stack)
|
||||
end_stack = is_softirq_stack(stack);
|
||||
|
||||
bp = ops->walk_stack(task, stack, bp, ops, data,
|
||||
end_stack, &graph);
|
||||
|
||||
/* Stop if not on irq stack */
|
||||
if (!end_stack)
|
||||
if (get_stack_info(stack, task, &info, &visit_mask))
|
||||
break;
|
||||
|
||||
/* The previous esp is saved on the bottom of the stack */
|
||||
prev_esp = (u32 *)(end_stack - THREAD_SIZE);
|
||||
stack = (unsigned long *)*prev_esp;
|
||||
if (!stack)
|
||||
stack_type_str(info.type, &begin_str, &end_str);
|
||||
|
||||
if (begin_str && ops->stack(data, begin_str) < 0)
|
||||
break;
|
||||
|
||||
if (ops->stack(data, "IRQ") < 0)
|
||||
bp = ops->walk_stack(task, stack, bp, ops, data, &info, &graph);
|
||||
|
||||
if (end_str && ops->stack(data, end_str) < 0)
|
||||
break;
|
||||
|
||||
stack = info.next_sp;
|
||||
|
||||
touch_nmi_watchdog();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue