浏览代码

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>
Jiri Slaby 7 年之前
父节点
当前提交
441ccc3580
共有 1 个文件被更改,包括 12 次插入4 次删除
  1. 12 4
      arch/x86/kernel/stacktrace.c

+ 12 - 4
arch/x86/kernel/stacktrace.c

@@ -89,21 +89,24 @@ __save_stack_trace_reliable(struct stack_trace *trace,
 	struct pt_regs *regs;
 	struct pt_regs *regs;
 	unsigned long addr;
 	unsigned long addr;
 
 
-	for (unwind_start(&state, task, NULL, NULL); !unwind_done(&state);
+	for (unwind_start(&state, task, NULL, NULL);
+	     !unwind_done(&state) && !unwind_error(&state);
 	     unwind_next_frame(&state)) {
 	     unwind_next_frame(&state)) {
 
 
 		regs = unwind_get_entry_regs(&state, NULL);
 		regs = unwind_get_entry_regs(&state, NULL);
 		if (regs) {
 		if (regs) {
+			/* Success path for user tasks */
+			if (user_mode(regs))
+				goto success;
+
 			/*
 			/*
 			 * Kernel mode registers on the stack indicate an
 			 * Kernel mode registers on the stack indicate an
 			 * in-kernel interrupt or exception (e.g., preemption
 			 * in-kernel interrupt or exception (e.g., preemption
 			 * or a page fault), which can make frame pointers
 			 * or a page fault), which can make frame pointers
 			 * unreliable.
 			 * unreliable.
 			 */
 			 */
-			if (!user_mode(regs))
-				return -EINVAL;
 
 
-			break;
+			return -EINVAL;
 		}
 		}
 
 
 		addr = unwind_get_return_address(&state);
 		addr = unwind_get_return_address(&state);
@@ -124,6 +127,11 @@ __save_stack_trace_reliable(struct stack_trace *trace,
 	if (unwind_error(&state))
 	if (unwind_error(&state))
 		return -EINVAL;
 		return -EINVAL;
 
 
+	/* Success path for non-user tasks, i.e. kthreads and idle tasks */
+	if (!(task->flags & (PF_KTHREAD | PF_IDLE)))
+		return -EINVAL;
+
+success:
 	if (trace->nr_entries < trace->max_entries)
 	if (trace->nr_entries < trace->max_entries)
 		trace->entries[trace->nr_entries++] = ULONG_MAX;
 		trace->entries[trace->nr_entries++] = ULONG_MAX;