diff options
author | Tong Li <tong.n.li@intel.com> | 2006-02-03 06:04:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-02-03 11:32:04 -0500 |
commit | 23332c2e9da16b717f18fd95bc90211a663aa6ee (patch) | |
tree | 873e445688472fd1726c0e48113f63a585d03b39 | |
parent | 8145916996b91d42b8bb4b0fcd508af295222c7c (diff) |
[PATCH] OProfile: fixed x86_64 incorrect kernel call graphs
Fix the problem in kernel 2.6.15.1 (and early versions) that OProfile on
x86_64 does not correctly collect the stack traces for kernel functions.
The original code in valid_kernel_stack() in arch/i386/oprofile/backtrace.c
assumes that the frame pointer (headaddr) should be greater than stack
(i.e., regs).
This assumption is wrong for x86_64 because NMIs in x86_64 use a seperate
stack different from the kernel stack. Therefore, the variable stack now
points to some location on the NMI stack, which turns out to be at a higher
address than the frame pointer (headaddr) on the kernel stack. The correct
comparison here should be between headaddr and regs->rsp for x86_64.
Signed-off-by: Tong Li <tong.n.li@intel.com>
Cc: John Levon <levon@movementarian.org>
Cc: Philippe Elie <phil.el@wanadoo.fr>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | arch/i386/oprofile/backtrace.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/arch/i386/oprofile/backtrace.c b/arch/i386/oprofile/backtrace.c index 21654be3f73f..acc18138fb22 100644 --- a/arch/i386/oprofile/backtrace.c +++ b/arch/i386/oprofile/backtrace.c | |||
@@ -49,7 +49,9 @@ dump_backtrace(struct frame_head * head) | |||
49 | * | stack | | 49 | * | stack | |
50 | * --------------- saved regs->ebp value if valid (frame_head address) | 50 | * --------------- saved regs->ebp value if valid (frame_head address) |
51 | * . . | 51 | * . . |
52 | * --------------- struct pt_regs stored on stack (struct pt_regs *) | 52 | * --------------- saved regs->rsp value if x86_64 |
53 | * | | | ||
54 | * --------------- struct pt_regs * stored on stack if 32-bit | ||
53 | * | | | 55 | * | | |
54 | * . . | 56 | * . . |
55 | * | | | 57 | * | | |
@@ -57,13 +59,26 @@ dump_backtrace(struct frame_head * head) | |||
57 | * | | | 59 | * | | |
58 | * | | \/ Lower addresses | 60 | * | | \/ Lower addresses |
59 | * | 61 | * |
60 | * Thus, &pt_regs <-> stack base restricts the valid(ish) ebp values | 62 | * Thus, regs (or regs->rsp for x86_64) <-> stack base restricts the |
63 | * valid(ish) ebp values. Note: (1) for x86_64, NMI and several other | ||
64 | * exceptions use special stacks, maintained by the interrupt stack table | ||
65 | * (IST). These stacks are set up in trap_init() in | ||
66 | * arch/x86_64/kernel/traps.c. Thus, for x86_64, regs now does not point | ||
67 | * to the kernel stack; instead, it points to some location on the NMI | ||
68 | * stack. On the other hand, regs->rsp is the stack pointer saved when the | ||
69 | * NMI occurred. (2) For 32-bit, regs->esp is not valid because the | ||
70 | * processor does not save %esp on the kernel stack when interrupts occur | ||
71 | * in the kernel mode. | ||
61 | */ | 72 | */ |
62 | #ifdef CONFIG_FRAME_POINTER | 73 | #ifdef CONFIG_FRAME_POINTER |
63 | static int valid_kernel_stack(struct frame_head * head, struct pt_regs * regs) | 74 | static int valid_kernel_stack(struct frame_head * head, struct pt_regs * regs) |
64 | { | 75 | { |
65 | unsigned long headaddr = (unsigned long)head; | 76 | unsigned long headaddr = (unsigned long)head; |
77 | #ifdef CONFIG_X86_64 | ||
78 | unsigned long stack = (unsigned long)regs->rsp; | ||
79 | #else | ||
66 | unsigned long stack = (unsigned long)regs; | 80 | unsigned long stack = (unsigned long)regs; |
81 | #endif | ||
67 | unsigned long stack_base = (stack & ~(THREAD_SIZE - 1)) + THREAD_SIZE; | 82 | unsigned long stack_base = (stack & ~(THREAD_SIZE - 1)) + THREAD_SIZE; |
68 | 83 | ||
69 | return headaddr > stack && headaddr < stack_base; | 84 | return headaddr > stack && headaddr < stack_base; |