Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752886AbdLEIzo (ORCPT ); Tue, 5 Dec 2017 03:55:44 -0500 Received: from mx2.suse.de ([195.135.220.15]:34889 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752742AbdLEIzl (ORCPT ); Tue, 5 Dec 2017 03:55:41 -0500 From: Jiri Slaby To: mingo@redhat.com Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby , Thomas Gleixner , "H. Peter Anvin" , x86@kernel.org, Josh Poimboeuf Subject: [PATCH v2 2/5] x86/stacktrace: remove unwind_state->error Date: Tue, 5 Dec 2017 09:55:35 +0100 Message-Id: <20171205085538.24322-2-jslaby@suse.cz> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171205085538.24322-1-jslaby@suse.cz> References: <20171205085538.24322-1-jslaby@suse.cz> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reorganize the unwinding in __save_stack_trace_reliable, so that we don't need to set another variable -- unwind_state->error. In case, unwinding fails, we fail after the for loop too. The only way to escape the loop successfully is via the 'if (user_mode(regs))' check now. Signed-off-by: Jiri Slaby Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Josh Poimboeuf --- arch/x86/include/asm/unwind.h | 6 ------ arch/x86/kernel/stacktrace.c | 15 ++++++--------- arch/x86/kernel/unwind_frame.c | 2 -- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/unwind.h b/arch/x86/include/asm/unwind.h index 5be2fb23825a..6f90295e6547 100644 --- a/arch/x86/include/asm/unwind.h +++ b/arch/x86/include/asm/unwind.h @@ -15,7 +15,6 @@ struct unwind_state { unsigned long stack_mask; struct task_struct *task; int graph_idx; - bool error; #if defined(CONFIG_UNWINDER_ORC) bool signal, full_regs; unsigned long sp, bp, ip; @@ -40,11 +39,6 @@ static inline bool unwind_done(struct unwind_state *state) return state->stack_info.type == STACK_TYPE_UNKNOWN; } -static inline bool unwind_error(struct unwind_state *state) -{ - return state->error; -} - static inline void unwind_start(struct unwind_state *state, struct task_struct *task, struct pt_regs *regs, unsigned long *first_frame) diff --git a/arch/x86/kernel/stacktrace.c b/arch/x86/kernel/stacktrace.c index b088d4f9e43e..9193607e3ead 100644 --- a/arch/x86/kernel/stacktrace.c +++ b/arch/x86/kernel/stacktrace.c @@ -104,16 +104,16 @@ __save_stack_trace_reliable(struct stack_trace *trace, regs = unwind_get_entry_regs(&state); if (regs) { + if (user_mode(regs)) + goto success; + /* * Kernel mode registers on the stack indicate an * in-kernel interrupt or exception (e.g., preemption * or a page fault), which can make frame pointers * unreliable. */ - if (!user_mode(regs)) - return -EINVAL; - - break; + return -EINVAL; } addr = unwind_get_return_address(&state); @@ -132,12 +132,9 @@ __save_stack_trace_reliable(struct stack_trace *trace, return -EINVAL; } - /* Check for stack corruption */ - if (unwind_error(&state)) { - STACKTRACE_DUMP_ONCE(task); - return -EINVAL; - } + return -EINVAL; +success: if (trace->nr_entries < trace->max_entries) trace->entries[trace->nr_entries++] = ULONG_MAX; diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c index 3dc26f95d46e..0c08a56adabe 100644 --- a/arch/x86/kernel/unwind_frame.c +++ b/arch/x86/kernel/unwind_frame.c @@ -332,8 +332,6 @@ bool unwind_next_frame(struct unwind_state *state) return true; bad_address: - state->error = true; - /* * When unwinding a non-current task, the task might actually be * running on another CPU, in which case it could be modifying its -- 2.15.1