Skip to content

Commit 441ccc3

Browse files
Jiri Slabyingomolnar
authored andcommitted
x86/stacktrace: Clarify the reliable success paths
Make clear which path is for user tasks and for kthreads and idle tasks. This will allow easier plug-in of the ORC unwinder in the next patches. Note that we added a check for unwind error to the top of the loop, so that an error is returned also for user tasks (the 'goto success' would skip the check after the loop otherwise). Signed-off-by: Jiri Slaby <jslaby@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.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: https://lkml.kernel.org/lkml/20180518064713.26440-3-jslaby@suse.cz Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 1742692 commit 441ccc3

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎arch/x86/kernel/stacktrace.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,24 @@ __save_stack_trace_reliable(struct stack_trace *trace,
8989
struct pt_regs *regs;
9090
unsigned long addr;
9191

92-
for (unwind_start(&state, task, NULL, NULL); !unwind_done(&state);
92+
for (unwind_start(&state, task, NULL, NULL);
93+
!unwind_done(&state) && !unwind_error(&state);
9394
unwind_next_frame(&state)) {
9495

9596
regs = unwind_get_entry_regs(&state, NULL);
9697
if (regs) {
98+
/* Success path for user tasks */
99+
if (user_mode(regs))
100+
goto success;
101+
97102
/*
98103
* Kernel mode registers on the stack indicate an
99104
* in-kernel interrupt or exception (e.g., preemption
100105
* or a page fault), which can make frame pointers
101106
* unreliable.
102107
*/
103-
if (!user_mode(regs))
104-
return -EINVAL;
105108

106-
break;
109+
return -EINVAL;
107110
}
108111

109112
addr = unwind_get_return_address(&state);
@@ -124,6 +127,11 @@ __save_stack_trace_reliable(struct stack_trace *trace,
124127
if (unwind_error(&state))
125128
return -EINVAL;
126129

130+
/* Success path for non-user tasks, i.e. kthreads and idle tasks */
131+
if (!(task->flags & (PF_KTHREAD | PF_IDLE)))
132+
return -EINVAL;
133+
134+
success:
127135
if (trace->nr_entries < trace->max_entries)
128136
trace->entries[trace->nr_entries++] = ULONG_MAX;
129137

0 commit comments

Comments
 (0)