mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Arjan van de Ven <arjan@infradead.org>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, akpm@linux-foundation.org
Subject: Re: Make the 32 bit Frame Pointer backtracer fall back to traditional
Date: Thu, 10 Jan 2008 08:36:57 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.1.00.0801100816450.3148@woody.linux-foundation.org> (raw)
In-Reply-To: <20080109220508.686bbda4@laptopd505.fenrus.org>



On Wed, 9 Jan 2008, Arjan van de Ven wrote:
>
> +	if (valid_stack_ptr(tinfo, frame, sizeof(*frame)))
> +		while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) {

Why?

Why not just make this something like the appended instead?

This is *totally* untested, but the basic notion is very simple: start off 
using the frame pointer until it is no longer valid (for any reason - 
whether the return address is corrupt, or the next frame info is bad), and 
update the stack pointer a you go.

When we've run out of frame pointers, we then scan any remaining stack the 
oldfashioned way, regardless of what happened. No unnecessary conditionals 
that will just mean that we don't show enough of the stack if *part* of it 
is corrupt.

The code is simpler and more robust (assuming it works - as mentioned, I 
didn't actually test it, so there may be some stupid thinko there).

		Linus

---
 arch/x86/kernel/traps_32.c |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/traps_32.c b/arch/x86/kernel/traps_32.c
index c88bbff..36714d7 100644
--- a/arch/x86/kernel/traps_32.c
+++ b/arch/x86/kernel/traps_32.c
@@ -107,6 +107,11 @@ static inline int valid_stack_ptr(struct thread_info *tinfo, void *p, unsigned s
 		p <= (void *)tinfo + THREAD_SIZE - size;
 }
 
+static inline int valid_frame_ptr(struct thread_info *tinfo, void *stack, void *p, unsigned size)
+{
+	return p >= stack && valid_stack_ptr(tinfo, p, size);
+}
+
 /* The form of the top of the frame on the stack */
 struct stack_frame {
 	struct stack_frame *next_frame;
@@ -119,24 +124,23 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
 {
 #ifdef	CONFIG_FRAME_POINTER
 	struct stack_frame *frame = (struct stack_frame *)ebp;
-	while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) {
-		struct stack_frame *next;
+	while (valid_frame_ptr(tinfo, stack, frame, sizeof(*frame))) {
 		unsigned long addr;
 
 		addr = frame->return_address;
+		if (!__kernel_text_address(addr))
+			break;
 		ops->address(data, addr);
+
 		/*
-		 * break out of recursive entries (such as
-		 * end_of_stack_stop_unwind_function). Also,
-		 * we can never allow a frame pointer to
-		 * move downwards!
+		 * Update the stack pointer to past the return
+		 * address we just printed out, and try the next
+		 * frame..
 		 */
-		next = frame->next_frame;
-		if (next <= frame)
-			break;
-		frame = next;
+		stack = 1+&frame->return_address;
+		frame = frame->next_frame;
 	}
-#else
+#endif
 	while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) {
 		unsigned long addr;
 
@@ -144,7 +148,6 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
 		if (__kernel_text_address(addr))
 			ops->address(data, addr);
 	}
-#endif
 	return ebp;
 }
 

  parent reply	other threads:[~2008-01-10 16:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-10  6:05 Arjan van de Ven
2008-01-10  6:21 ` Harvey Harrison
2008-01-10 12:46   ` Ingo Molnar
2008-01-10 15:15     ` Arjan van de Ven
2008-01-10  6:55 ` Ingo Molnar
2008-01-10 16:36 ` Linus Torvalds [this message]
2008-01-10 16:49   ` Arjan van de Ven
2008-01-11  4:35   ` Arjan van de Ven
2008-01-11 11:54     ` Olaf Dietsche
2008-01-11 19:41     ` Linus Torvalds
2008-01-11 19:56       ` Arjan van de Ven
2008-01-11 22:01       ` Theodore Tso

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=alpine.LFD.1.00.0801100816450.3148@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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

all inboxes | Powered by JetHome®