From: tip-bot for Josh Poimboeuf <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: jpoimboe@redhat.com, rostedt@goodmis.org, fweisbec@gmail.com,
brgerst@gmail.com, dvlasenk@redhat.com, luto@kernel.org,
luto@amacapital.net, nilayvaish@gmail.com, peterz@infradead.org,
keescook@chromium.org, linux-kernel@vger.kernel.org,
mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com,
bp@alien8.de, byungchul.park@lge.com,
torvalds@linux-foundation.org
Subject: [tip:x86/asm] x86/dumpstack: Simplify in_exception_stack()
Date: Thu, 15 Sep 2016 03:40:05 -0700 [thread overview]
Message-ID: <tip-9c00390757fd9f5851f7973b2f0e1e41550bb3b8@git.kernel.org> (raw)
In-Reply-To: <e91cb410169dd576678dd427c35efb716fd0cee1.1473905218.git.jpoimboe@redhat.com>
Commit-ID: 9c00390757fd9f5851f7973b2f0e1e41550bb3b8
Gitweb: http://git.kernel.org/tip/9c00390757fd9f5851f7973b2f0e1e41550bb3b8
Author: Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Wed, 14 Sep 2016 21:07:41 -0500
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 15 Sep 2016 08:13:14 +0200
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: 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/e91cb410169dd576678dd427c35efb716fd0cee1.1473905218.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/kernel/dumpstack_64.c | 89 ++++++++++++------------------------------
1 file changed, 26 insertions(+), 63 deletions(-)
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index 07373be..904fb46 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -16,83 +16,46 @@
#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 long stack, unsigned *usedp,
char **idp)
{
+ unsigned long begin, end;
unsigned k;
- /*
- * Iterate over all exception stacks, and figure out whether
- * 'stack' is in one of them:
- */
+ BUILD_BUG_ON(N_EXCEPTION_STACKS != 4);
+
for (k = 0; k < N_EXCEPTION_STACKS; k++) {
- unsigned long end = raw_cpu_ptr(&orig_ist)->ist[k];
- /*
- * Is 'stack' above this exception frame's end?
- * If yes then skip to the next frame.
- */
- if (stack >= end)
+ end = raw_cpu_ptr(&orig_ist)->ist[k];
+ begin = end - exception_stack_sizes[k];
+
+ if (stack < begin || 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:
+ * 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 and return NULL:
*/
-#if DEBUG_STKSZ > EXCEPTION_STKSZ
- if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
- unsigned j = N_EXCEPTION_STACKS - 1;
+ if (*usedp & (1U << k))
+ break;
+ *usedp |= 1U << 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;
- }
-#endif
+ *idp = exception_stack_names[k];
+ return (unsigned long *)end;
}
+
return NULL;
}
next prev parent reply other threads:[~2016-09-15 10:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-15 2:07 [PATCH 0/4] x86/dumpstack: yet more stack dump improvements Josh Poimboeuf
2016-09-15 2:07 ` [PATCH 1/4] x86/dumpstack: simplify in_exception_stack() Josh Poimboeuf
2016-09-15 10:40 ` tip-bot for Josh Poimboeuf [this message]
2016-09-15 2:07 ` [PATCH 2/4] x86/dumpstack: add get_stack_info() interface Josh Poimboeuf
2016-09-15 10:40 ` [tip:x86/asm] x86/dumpstack: Add " tip-bot for Josh Poimboeuf
2016-09-15 2:07 ` [PATCH 3/4] x86/dumpstack: support for unwinding empty irq stacks Josh Poimboeuf
2016-09-15 10:40 ` [tip:x86/asm] x86/dumpstack: Add support for unwinding empty IRQ stacks tip-bot for Josh Poimboeuf
2016-09-15 2:07 ` [PATCH 4/4] x86/dumpstack: add recursion checking for all stacks Josh Poimboeuf
2016-09-15 10:41 ` [tip:x86/asm] x86/dumpstack: Add " tip-bot for Josh Poimboeuf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-9c00390757fd9f5851f7973b2f0e1e41550bb3b8@git.kernel.org \
--to=tipbot@zytor.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=byungchul.park@lge.com \
--cc=dvlasenk@redhat.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=nilayvaish@gmail.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox