提交 21b32bbf 编写于 作者: I Ingo Molnar 提交者: Linus Torvalds

[PATCH] lockdep: stacktrace subsystem, x86_64 support

Framework to generate and save stacktraces quickly, without printing anything
to the console.  x86_64 support.
Signed-off-by: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NArjan van de Ven <arjan@linux.intel.com>
Cc: Andi Kleen <ak@muc.de>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 4a7c7197
master alk-4.19.24 alk-4.19.30 alk-4.19.34 alk-4.19.36 alk-4.19.43 alk-4.19.48 alk-4.19.57 ck-4.19.67 ck-4.19.81 ck-4.19.91 github/fork/deepanshu1422/fix-typo-in-comment github/fork/haosdent/fix-typo linux-next v4.19.91 v4.19.90 v4.19.89 v4.19.88 v4.19.87 v4.19.86 v4.19.85 v4.19.84 v4.19.83 v4.19.82 v4.19.81 v4.19.80 v4.19.79 v4.19.78 v4.19.77 v4.19.76 v4.19.75 v4.19.74 v4.19.73 v4.19.72 v4.19.71 v4.19.70 v4.19.69 v4.19.68 v4.19.67 v4.19.66 v4.19.65 v4.19.64 v4.19.63 v4.19.62 v4.19.61 v4.19.60 v4.19.59 v4.19.58 v4.19.57 v4.19.56 v4.19.55 v4.19.54 v4.19.53 v4.19.52 v4.19.51 v4.19.50 v4.19.49 v4.19.48 v4.19.47 v4.19.46 v4.19.45 v4.19.44 v4.19.43 v4.19.42 v4.19.41 v4.19.40 v4.19.39 v4.19.38 v4.19.37 v4.19.36 v4.19.35 v4.19.34 v4.19.33 v4.19.32 v4.19.31 v4.19.30 v4.19.29 v4.19.28 v4.19.27 v4.19.26 v4.19.25 v4.19.24 v4.19.23 v4.19.22 v4.19.21 v4.19.20 v4.19.19 v4.19.18 v4.19.17 v4.19.16 v4.19.15 v4.19.14 v4.19.13 v4.19.12 v4.19.11 v4.19.10 v4.19.9 v4.19.8 v4.19.7 v4.19.6 v4.19.5 v4.19.4 v4.19.3 v4.19.2 v4.19.1 v4.19 v4.19-rc8 v4.19-rc7 v4.19-rc6 v4.19-rc5 v4.19-rc4 v4.19-rc3 v4.19-rc2 v4.19-rc1 ck-release-21 ck-release-20 ck-release-19.2 ck-release-19.1 ck-release-19 ck-release-18 ck-release-17.2 ck-release-17.1 ck-release-17 ck-release-16 ck-release-15.1 ck-release-15 ck-release-14 ck-release-13.2 ck-release-13 ck-release-12 ck-release-11 ck-release-10 ck-release-9 ck-release-7 alk-release-15 alk-release-14 alk-release-13.2 alk-release-13 alk-release-12 alk-release-11 alk-release-10 alk-release-9 alk-release-7
无相关合并请求
......@@ -24,6 +24,10 @@ config X86
bool
default y
config STACKTRACE_SUPPORT
bool
default y
config SEMAPHORE_SLEEPERS
bool
default y
......
......@@ -10,6 +10,7 @@ obj-y := process.o signal.o entry.o traps.o irq.o \
setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \
pci-dma.o pci-nommu.o alternative.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o
obj-$(CONFIG_X86_MCE) += mce.o
obj-$(CONFIG_X86_MCE_INTEL) += mce_intel.o
obj-$(CONFIG_X86_MCE_AMD) += mce_amd.o
......
/*
* arch/x86_64/kernel/stacktrace.c
*
* Stack trace management functions
*
* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
*/
#include <linux/sched.h>
#include <linux/stacktrace.h>
#include <asm/smp.h>
static inline int
in_range(unsigned long start, unsigned long addr, unsigned long end)
{
return addr >= start && addr <= end;
}
static unsigned long
get_stack_end(struct task_struct *task, unsigned long stack)
{
unsigned long stack_start, stack_end, flags;
int i, cpu;
/*
* The most common case is that we are in the task stack:
*/
stack_start = (unsigned long)task->thread_info;
stack_end = stack_start + THREAD_SIZE;
if (in_range(stack_start, stack, stack_end))
return stack_end;
/*
* We are in an interrupt if irqstackptr is set:
*/
raw_local_irq_save(flags);
cpu = safe_smp_processor_id();
stack_end = (unsigned long)cpu_pda(cpu)->irqstackptr;
if (stack_end) {
stack_start = stack_end & ~(IRQSTACKSIZE-1);
if (in_range(stack_start, stack, stack_end))
goto out_restore;
/*
* We get here if we are in an IRQ context but we
* are also in an exception stack.
*/
}
/*
* Iterate over all exception stacks, and figure out whether
* 'stack' is in one of them:
*/
for (i = 0; i < N_EXCEPTION_STACKS; i++) {
/*
* set 'end' to the end of the exception stack.
*/
stack_end = per_cpu(init_tss, cpu).ist[i];
stack_start = stack_end - EXCEPTION_STKSZ;
/*
* Is 'stack' above this exception frame's end?
* If yes then skip to the next frame.
*/
if (stack >= stack_end)
continue;
/*
* Is 'stack' above this exception frame's start address?
* If yes then we found the right frame.
*/
if (stack >= stack_start)
goto out_restore;
/*
* 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 (i == DEBUG_STACK - 1 && stack >= stack_end - DEBUG_STKSZ) {
/*
* Black magic. A large debug stack is composed of
* multiple exception stack entries, which we
* iterate through now. Dont look:
*/
do {
stack_end -= EXCEPTION_STKSZ;
stack_start -= EXCEPTION_STKSZ;
} while (stack < stack_start);
goto out_restore;
}
#endif
}
/*
* Ok, 'stack' is not pointing to any of the system stacks.
*/
stack_end = 0;
out_restore:
raw_local_irq_restore(flags);
return stack_end;
}
/*
* Save stack-backtrace addresses into a stack_trace buffer:
*/
static inline unsigned long
save_context_stack(struct stack_trace *trace, unsigned int skip,
unsigned long stack, unsigned long stack_end)
{
unsigned long addr;
#ifdef CONFIG_FRAME_POINTER
unsigned long prev_stack = 0;
while (in_range(prev_stack, stack, stack_end)) {
pr_debug("stack: %p\n", (void *)stack);
addr = (unsigned long)(((unsigned long *)stack)[1]);
pr_debug("addr: %p\n", (void *)addr);
if (!skip)
trace->entries[trace->nr_entries++] = addr-1;
else
skip--;
if (trace->nr_entries >= trace->max_entries)
break;
if (!addr)
return 0;
/*
* Stack frames must go forwards (otherwise a loop could
* happen if the stackframe is corrupted), so we move
* prev_stack forwards:
*/
prev_stack = stack;
stack = (unsigned long)(((unsigned long *)stack)[0]);
}
pr_debug("invalid: %p\n", (void *)stack);
#else
while (stack < stack_end) {
addr = ((unsigned long *)stack)[0];
stack += sizeof(long);
if (__kernel_text_address(addr)) {
if (!skip)
trace->entries[trace->nr_entries++] = addr-1;
else
skip--;
if (trace->nr_entries >= trace->max_entries)
break;
}
}
#endif
return stack;
}
#define MAX_STACKS 10
/*
* Save stack-backtrace addresses into a stack_trace buffer.
* If all_contexts is set, all contexts (hardirq, softirq and process)
* are saved. If not set then only the current context is saved.
*/
void save_stack_trace(struct stack_trace *trace,
struct task_struct *task, int all_contexts,
unsigned int skip)
{
unsigned long stack = (unsigned long)&stack;
int i, nr_stacks = 0, stacks_done[MAX_STACKS];
WARN_ON(trace->nr_entries || !trace->max_entries);
if (!task)
task = current;
pr_debug("task: %p, ti: %p\n", task, task->thread_info);
if (!task || task == current) {
/* Grab rbp right from our regs: */
asm ("mov %%rbp, %0" : "=r" (stack));
pr_debug("rbp: %p\n", (void *)stack);
} else {
/* rbp is the last reg pushed by switch_to(): */
stack = task->thread.rsp;
pr_debug("other task rsp: %p\n", (void *)stack);
stack = (unsigned long)(((unsigned long *)stack)[0]);
pr_debug("other task rbp: %p\n", (void *)stack);
}
while (1) {
unsigned long stack_end = get_stack_end(task, stack);
pr_debug("stack: %p\n", (void *)stack);
pr_debug("stack end: %p\n", (void *)stack_end);
/*
* Invalid stack addres?
*/
if (!stack_end)
return;
/*
* Were we in this stack already? (recursion)
*/
for (i = 0; i < nr_stacks; i++)
if (stacks_done[i] == stack_end)
return;
stacks_done[nr_stacks] = stack_end;
stack = save_context_stack(trace, skip, stack, stack_end);
if (!all_contexts || !stack ||
trace->nr_entries >= trace->max_entries)
return;
trace->entries[trace->nr_entries++] = ULONG_MAX;
if (trace->nr_entries >= trace->max_entries)
return;
if (++nr_stacks >= MAX_STACKS)
return;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部