Skip to content

Commit 187b96d

Browse files
jpoimboePeter Zijlstra
authored and
Peter Zijlstra
committed
x86/unwind/orc: Fix unwind_get_return_address_ptr() for inactive tasks
Normally, show_trace_log_lvl() scans the stack, looking for text addresses to print. In parallel, it unwinds the stack with unwind_next_frame(). If the stack address matches the pointer returned by unwind_get_return_address_ptr() for the current frame, the text address is printed normally without a question mark. Otherwise it's considered a breadcrumb (potentially from a previous call path) and it's printed with a question mark to indicate that the address is unreliable and typically can be ignored. Since the following commit: f1d9a2a ("x86/unwind/orc: Don't skip the first frame for inactive tasks") ... for inactive tasks, show_trace_log_lvl() prints *only* unreliable addresses (prepended with '?'). That happens because, for the first frame of an inactive task, unwind_get_return_address_ptr() returns the wrong return address pointer: one word *below* the task stack pointer. show_trace_log_lvl() starts scanning at the stack pointer itself, so it never finds the first 'reliable' address, causing only guesses to being printed. The first frame of an inactive task isn't a normal stack frame. It's actually just an instance of 'struct inactive_task_frame' which is left behind by __switch_to_asm(). Now that this inactive frame is actually exposed to callers, fix unwind_get_return_address_ptr() to interpret it properly. Fixes: f1d9a2a ("x86/unwind/orc: Don't skip the first frame for inactive tasks") Reported-by: Tetsuo Handa <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/20200522135435.vbxs7umku5pyrdbk@treble
1 parent d7110a2 commit 187b96d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/kernel/unwind_orc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,19 @@ EXPORT_SYMBOL_GPL(unwind_get_return_address);
320320

321321
unsigned long *unwind_get_return_address_ptr(struct unwind_state *state)
322322
{
323+
struct task_struct *task = state->task;
324+
323325
if (unwind_done(state))
324326
return NULL;
325327

326328
if (state->regs)
327329
return &state->regs->ip;
328330

331+
if (task != current && state->sp == task->thread.sp) {
332+
struct inactive_task_frame *frame = (void *)task->thread.sp;
333+
return &frame->ret_addr;
334+
}
335+
329336
if (state->sp)
330337
return (unsigned long *)state->sp - 1;
331338

0 commit comments

Comments
 (0)