Commit 2c96b2fe authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Ingo Molnar

x86/unwind: Include __schedule() in stack traces

In the following commit:

  0100301b ("sched/x86: Rewrite the switch_to() code")

... the layout of the 'inactive_task_frame' struct was designed to have
a frame pointer header embedded in it, so that the unwinder could use
the 'bp' and 'ret_addr' fields to report __schedule() on the stack (or
ret_from_fork() for newly forked tasks which haven't actually run yet).

Finish the job by changing get_frame_pointer() to return a pointer to
inactive_task_frame's 'bp' field rather than 'bp' itself.  This allows
the unwinder to start one frame higher on the stack, so that it properly
reports __schedule().
Reported-by: default avatarMiroslav Benes <mbenes@suse.cz>
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: Dave Jones <davej@codemonkey.org.uk>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/598e9f7505ed0aba86e8b9590aa528c6c7ae8dcd.1483978430.git.jpoimboe@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 84936118
...@@ -52,16 +52,13 @@ static inline bool on_stack(struct stack_info *info, void *addr, size_t len) ...@@ -52,16 +52,13 @@ static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
static inline unsigned long * static inline unsigned long *
get_frame_pointer(struct task_struct *task, struct pt_regs *regs) get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
{ {
struct inactive_task_frame *frame;
if (regs) if (regs)
return (unsigned long *)regs->bp; return (unsigned long *)regs->bp;
if (task == current) if (task == current)
return __builtin_frame_address(0); return __builtin_frame_address(0);
frame = (struct inactive_task_frame *)task->thread.sp; return &((struct inactive_task_frame *)task->thread.sp)->bp;
return (unsigned long *)READ_ONCE_NOCHECK(frame->bp);
} }
#else #else
static inline unsigned long * static inline unsigned long *
......
...@@ -36,7 +36,10 @@ static inline void prepare_switch_to(struct task_struct *prev, ...@@ -36,7 +36,10 @@ static inline void prepare_switch_to(struct task_struct *prev,
asmlinkage void ret_from_fork(void); asmlinkage void ret_from_fork(void);
/* data that is pointed to by thread.sp */ /*
* This is the structure pointed to by thread.sp for an inactive task. The
* order of the fields must match the code in __switch_to_asm().
*/
struct inactive_task_frame { struct inactive_task_frame {
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
unsigned long r15; unsigned long r15;
...@@ -48,6 +51,11 @@ struct inactive_task_frame { ...@@ -48,6 +51,11 @@ struct inactive_task_frame {
unsigned long di; unsigned long di;
#endif #endif
unsigned long bx; unsigned long bx;
/*
* These two fields must be together. They form a stack frame header,
* needed by get_frame_pointer().
*/
unsigned long bp; unsigned long bp;
unsigned long ret_addr; unsigned long ret_addr;
}; };
......
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