From 54fd15780526c47fa29a85b066cf69996be59a59 Mon Sep 17 00:00:00 2001 From: Borislav Petkov Date: Tue, 26 May 2015 10:28:18 +0200 Subject: [PATCH 1/3] x86/Documentation: Move kernel-stacks doc one level up ... to Documentation/x86/ as it is going to collect more and not only 64-bit specific info. Signed-off-by: Borislav Petkov Cc: Andrew Morton Cc: Andy Lutomirski Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Michal Marek Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: live-patching@vger.kernel.org Link: http://lkml.kernel.org/r/1432628901-18044-16-git-send-email-bp@alien8.de Signed-off-by: Ingo Molnar --- Documentation/x86/{x86_64 => }/kernel-stacks | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Documentation/x86/{x86_64 => }/kernel-stacks (100%) diff --git a/Documentation/x86/x86_64/kernel-stacks b/Documentation/x86/kernel-stacks similarity index 100% rename from Documentation/x86/x86_64/kernel-stacks rename to Documentation/x86/kernel-stacks From d724a9a52b0026ac6a05440c079c9a618acfd8cf Mon Sep 17 00:00:00 2001 From: Borislav Petkov Date: Tue, 26 May 2015 10:28:19 +0200 Subject: [PATCH 2/3] x86/Documentation: Remove STACKFAULT_STACK bulletpoint Update the documentation after 6f442be2fb22 ("x86_64, traps: Stop using IST for #SS"). Signed-off-by: Borislav Petkov Cc: Andrew Morton Cc: Andy Lutomirski Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Michal Marek Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: live-patching@vger.kernel.org Link: http://lkml.kernel.org/r/1432628901-18044-17-git-send-email-bp@alien8.de Signed-off-by: Ingo Molnar --- Documentation/x86/kernel-stacks | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Documentation/x86/kernel-stacks b/Documentation/x86/kernel-stacks index e3c8a49d1a2f..c3c935b9d56e 100644 --- a/Documentation/x86/kernel-stacks +++ b/Documentation/x86/kernel-stacks @@ -1,3 +1,6 @@ +Kernel stacks on x86-64 bit +--------------------------- + Most of the text from Keith Owens, hacked by AK x86_64 page size (PAGE_SIZE) is 4K. @@ -56,13 +59,6 @@ If that assumption is ever broken then the stacks will become corrupt. The currently assigned IST stacks are :- -* STACKFAULT_STACK. EXCEPTION_STKSZ (PAGE_SIZE). - - Used for interrupt 12 - Stack Fault Exception (#SS). - - This allows the CPU to recover from invalid stack segments. Rarely - happens. - * DOUBLEFAULT_STACK. EXCEPTION_STKSZ (PAGE_SIZE). Used for interrupt 8 - Double Fault Exception (#DF). From 113b5e3720e79ad938374163c1b8e295521dc9cf Mon Sep 17 00:00:00 2001 From: Borislav Petkov Date: Tue, 26 May 2015 10:28:20 +0200 Subject: [PATCH 3/3] x86/Documentation: Adapt Ingo's explanation on printing backtraces Hold it down for future reference, as the question about the question mark in stack traces keeps popping up. Signed-off-by: Borislav Petkov Cc: Andrew Morton Cc: Andy Lutomirski Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Michal Marek Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: live-patching@vger.kernel.org Link: http://lkml.kernel.org/r/1432628901-18044-18-git-send-email-bp@alien8.de Link: http://lkml.kernel.org/r/20150521101614.GA10889@gmail.com Signed-off-by: Ingo Molnar --- Documentation/x86/kernel-stacks | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Documentation/x86/kernel-stacks b/Documentation/x86/kernel-stacks index c3c935b9d56e..0f3a6c201943 100644 --- a/Documentation/x86/kernel-stacks +++ b/Documentation/x86/kernel-stacks @@ -95,3 +95,47 @@ The currently assigned IST stacks are :- assumptions about the previous state of the kernel stack. For more details see the Intel IA32 or AMD AMD64 architecture manuals. + + +Printing backtraces on x86 +-------------------------- + +The question about the '?' preceding function names in an x86 stacktrace +keeps popping up, here's an indepth explanation. It helps if the reader +stares at print_context_stack() and the whole machinery in and around +arch/x86/kernel/dumpstack.c. + +Adapted from Ingo's mail, Message-ID: <20150521101614.GA10889@gmail.com>: + +We always scan the full kernel stack for return addresses stored on +the kernel stack(s) [*], from stack top to stack bottom, and print out +anything that 'looks like' a kernel text address. + +If it fits into the frame pointer chain, we print it without a question +mark, knowing that it's part of the real backtrace. + +If the address does not fit into our expected frame pointer chain we +still print it, but we print a '?'. It can mean two things: + + - either the address is not part of the call chain: it's just stale + values on the kernel stack, from earlier function calls. This is + the common case. + + - or it is part of the call chain, but the frame pointer was not set + up properly within the function, so we don't recognize it. + +This way we will always print out the real call chain (plus a few more +entries), regardless of whether the frame pointer was set up correctly +or not - but in most cases we'll get the call chain right as well. The +entries printed are strictly in stack order, so you can deduce more +information from that as well. + +The most important property of this method is that we _never_ lose +information: we always strive to print _all_ addresses on the stack(s) +that look like kernel text addresses, so if debug information is wrong, +we still print out the real call chain as well - just with more question +marks than ideal. + +[*] For things like IRQ and IST stacks, we also scan those stacks, in + the right order, and try to cross from one stack into another + reconstructing the call chain. This works most of the time.