Skip to content

Commit 5d1ceb3

Browse files
author
Peter Zijlstra
committed
x86: Fix __get_wchan() for !STACKTRACE
Use asm/unwind.h to implement wchan, since we cannot always rely on STACKTRACE=y. Fixes: bc9bbb8 ("x86: Fix get_wchan() to support the ORC unwinder") Reported-by: Stephen Rothwell <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 55409ac commit 5d1ceb3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

arch/x86/kernel/process.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <asm/io_bitmap.h>
4444
#include <asm/proto.h>
4545
#include <asm/frame.h>
46+
#include <asm/unwind.h>
4647

4748
#include "process.h"
4849

@@ -944,10 +945,20 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
944945
*/
945946
unsigned long __get_wchan(struct task_struct *p)
946947
{
947-
unsigned long entry = 0;
948+
struct unwind_state state;
949+
unsigned long addr = 0;
948950

949-
stack_trace_save_tsk(p, &entry, 1, 0);
950-
return entry;
951+
for (unwind_start(&state, p, NULL, NULL); !unwind_done(&state);
952+
unwind_next_frame(&state)) {
953+
addr = unwind_get_return_address(&state);
954+
if (!addr)
955+
break;
956+
if (in_sched_functions(addr))
957+
continue;
958+
break;
959+
}
960+
961+
return addr;
951962
}
952963

953964
long do_arch_prctl_common(struct task_struct *task, int option,

0 commit comments

Comments
 (0)