Commit 9c003907 authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Ingo Molnar

x86/dumpstack: Simplify in_exception_stack()

in_exception_stack() does some bad, bad things just so the unwinder can
print different values for different areas of the debug exception stack.

There's no need to clarify where exactly on the stack it is.  Just print
"#DB" and be done with it.
Signed-off-by: default avatarJosh 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/e91cb410169dd576678dd427c35efb716fd0cee1.1473905218.git.jpoimboe@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent cfeeed27
...@@ -16,83 +16,46 @@ ...@@ -16,83 +16,46 @@
#include <asm/stacktrace.h> #include <asm/stacktrace.h>
static char *exception_stack_names[N_EXCEPTION_STACKS] = {
#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", [ DOUBLEFAULT_STACK-1 ] = "#DF",
[ NMI_STACK-1 ] = "NMI",
[ DEBUG_STACK-1 ] = "#DB",
[ MCE_STACK-1 ] = "#MC", [ MCE_STACK-1 ] = "#MC",
#if DEBUG_STKSZ > EXCEPTION_STKSZ };
[ N_EXCEPTION_STACKS ...
N_EXCEPTION_STACKS_END ] = "#DB[?]" static unsigned long exception_stack_sizes[N_EXCEPTION_STACKS] = {
#endif [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STKSZ,
[DEBUG_STACK - 1] = DEBUG_STKSZ
}; };
static unsigned long *in_exception_stack(unsigned long stack, unsigned *usedp, static unsigned long *in_exception_stack(unsigned long stack, unsigned *usedp,
char **idp) char **idp)
{ {
unsigned long begin, end;
unsigned k; unsigned k;
/* BUILD_BUG_ON(N_EXCEPTION_STACKS != 4);
* Iterate over all exception stacks, and figure out whether
* 'stack' is in one of them:
*/
for (k = 0; k < N_EXCEPTION_STACKS; k++) { for (k = 0; k < N_EXCEPTION_STACKS; k++) {
unsigned long end = raw_cpu_ptr(&orig_ist)->ist[k]; end = raw_cpu_ptr(&orig_ist)->ist[k];
/* begin = end - exception_stack_sizes[k];
* Is 'stack' above this exception frame's end?
* If yes then skip to the next frame. if (stack < begin || stack >= end)
*/
if (stack >= end)
continue; continue;
/* /*
* Is 'stack' above this exception frame's start address? * Make sure we only iterate through an exception stack once.
* If yes then we found the right frame. * If it comes up for the second time then there's something
*/ * wrong going on - just break and return NULL:
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)) if (*usedp & (1U << k))
break; break;
*usedp |= 1U << k; *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;
/* *idp = exception_stack_names[k];
* 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; return (unsigned long *)end;
} }
#endif
}
return NULL; return NULL;
} }
......
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