From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39554C433EF for ; Mon, 15 Nov 2021 08:50:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A00163213 for ; Mon, 15 Nov 2021 08:50:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0A00163213 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6j1ad5LNHbTboVcL8tcCRAtTFVPpHgFpwP5AGVD/F3I=; b=tw1/JpfnHIAXtB krgL0hb7prjurkZYzw9ReFqDZ4SU+4qCC3xoFbq4cpABsxHmrOJVyP2M60JX4eqWiwm9j8sohQaJL AsATwGO8xma62QIR31gk4tmK3gQdF1aH+1Gvd+ExG2/s8AD0SVZBb4Pu9G0Zf3HSLafc8WxkS/CCG XUkE9q2U7WsfHoT7IQ+CaGdetVWci85dYbSg0WXEB4OnoxCGPejiexZvZHm5bvvXgRaGufmgF5jOS tg4vr8xO8jMfewhdMYVjBs8NSAgsTeVbeiqJhB5Yle9E5Qbf1ls0pNgI+7Y3X4ZBwhcGDhrNPGXYP WN/xYDSy/XAHoDCNL/fA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmXfU-00EjQd-Is; Mon, 15 Nov 2021 08:48:48 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmXea-00Ej72-72 for linux-arm-kernel@lists.infradead.org; Mon, 15 Nov 2021 08:47:53 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED3CA63213; Mon, 15 Nov 2021 08:47:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636966071; bh=Iv3SkW3A4NstsZ9+oDcWk0PAzKu5iD67EOZkzkAlNN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lF0Clmo1UNm4In//AmqaA5MdAR8kf4wl27w7yE6m2rfuU5Yl1PXJSWkIxIf3LHT5j fKZrIZocvEO/xoGPaRh/YmCLPS77IpmIi0ochl9xFdttCFNe32ZKGfwR0inGrSjNsp K+xjLq0lfFnyBExB/1jwfI0iw0yjDMcuoI7MIsZwMkOgccZ061EGRAa2EvfUrPGX0n 3kpQk3pCga5L0JUAYUD1Fy5aPBtODQ5EqJu48ololhIk4XSykBefGPnwZ7rVsymxqG ICjZCVVCgF3zZhokOvCEix/iWKQ+trR21unSVEPlD8+o6nG6Mm0nd9oXQq38NJXyPX Jolh7/2utsKiQ== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Russell King , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Nicolas Pitre Subject: [PATCH v4 5/9] ARM: unwind: dump exception stack from calling frame Date: Mon, 15 Nov 2021 09:47:28 +0100 Message-Id: <20211115084732.3704393-6-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211115084732.3704393-1-ardb@kernel.org> References: <20211115084732.3704393-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3329; h=from:subject; bh=Iv3SkW3A4NstsZ9+oDcWk0PAzKu5iD67EOZkzkAlNN4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhkh6c/xelvdWZzFJGmiNLyxpUbo5PKGNYWFLHjTzM QyNtvf6JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYZIenAAKCRDDTyI5ktmPJBnYC/ 9zz7txTy/1I87oAIYGVux2lcBuQ4l1Ibzh3bLNvNbgXKi3R5RCu4ZjjjLFpb8+PlIFxThStRGzjvgb CtUlPfaqimlckeM0IhWXAF+b+9WVaI4LhtK0EVeBANxyd65l0hB7zO4aLwQFIoV88dQ9hrOWkUv3bY U9Ar4TrAhh2htolyj9dRlQIohYTFXbom64l/FQ9WGW7BIRtpKHHYdAUTOeJpMy9fr6C+cijpirxApc TdCI5lkBbqWeXVe/BN/HL85Fm4lOygFD965F/vefFzXdEWwKaDHIWhiFIDSF4vc4IW+AZV9IzyC52c cFvLlHqY7vawyKsDUchxsDrqDfCTsFYz4BLxTgLq1n4E6LYNwoYv8Xo/AL0+NotBMdbivDNhurysbG 2MjXbFtQ4lhHTkFUH49JVt4kfWR34n5n1GFRvRIxTuUGrSJWlWBXEpoxZaOW4LZLl1SiopYUNTP05G mf02VdNTNlvgaNbTIrdECk++G/OFLkcRd4aC2P4wzICSo= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211115_004752_338145_3C653B66 X-CRM114-Status: GOOD ( 20.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The existing code that dumps the contents of the pt_regs structure passed to __entry routines does so while unwinding the callee frame, and dereferences the stack pointer as a struct pt_regs*. This will no longer work when we enable support for IRQ or overflow stacks, because the struct pt_regs may live on the task stack, while we are executing from another stack. The unwinder has access to this information, but only while unwinding the calling frame. So let's combine the exception stack dumping code with the handling of the calling frame as well. By printing it before dumping the caller/callee addresses, the output order is preserved. Signed-off-by: Ard Biesheuvel Reviewed-by: Arnd Bergmann Acked-by: Linus Walleij Tested-by: Keith Packard --- arch/arm/include/asm/stacktrace.h | 10 ++++++++++ arch/arm/kernel/traps.c | 3 ++- arch/arm/kernel/unwind.c | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/stacktrace.h b/arch/arm/include/asm/stacktrace.h index 33ee1aa4b8c0..d87d60532b86 100644 --- a/arch/arm/include/asm/stacktrace.h +++ b/arch/arm/include/asm/stacktrace.h @@ -18,6 +18,16 @@ struct stackframe { struct llist_node *kr_cur; struct task_struct *tsk; #endif +#ifdef CONFIG_ARM_UNWIND + /* + * This field is used to track the stack pointer value when calling + * __entry routines. This is needed when IRQ stacks and overflow stacks + * are used, because in that case, the struct pt_regs passed to these + * __entry routines may be at the top of the task stack, while we are + * executing from another stack. + */ + unsigned long sp_low; +#endif }; static __always_inline diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index e4698605bb72..89be21ec3b52 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -74,7 +74,8 @@ void dump_backtrace_entry(unsigned long where, unsigned long from, loglvl, where, from); #endif - if (in_entry_text(from) && end <= ALIGN(frame, THREAD_SIZE)) + if (!IS_ENABLED(CONFIG_UNWINDER_ARM) && + in_entry_text(from) && end <= ALIGN(frame, THREAD_SIZE)) dump_mem(loglvl, "Exception stack", frame + 4, end); } diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index 9cb9af3fc433..b7a6141c342f 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -459,6 +460,7 @@ int unwind_frame(struct stackframe *frame) frame->sp = ctrl.vrs[SP]; frame->lr = ctrl.vrs[LR]; frame->pc = ctrl.vrs[PC]; + frame->sp_low = ctrl.sp_low; return URC_OK; } @@ -502,7 +504,11 @@ void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk, urc = unwind_frame(&frame); if (urc < 0) break; - dump_backtrace_entry(where, frame.pc, frame.sp - 4, loglvl); + if (in_entry_text(where)) + dump_mem(loglvl, "Exception stack", frame.sp_low, + frame.sp_low + sizeof(struct pt_regs)); + + dump_backtrace_entry(where, frame.pc, 0, loglvl); } } -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel