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 09CBFC433F5 for ; Sun, 17 Oct 2021 13:20:19 +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 C329360F9E for ; Sun, 17 Oct 2021 13:20:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C329360F9E 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=LOrnmSl2DGFto+Lv76PTa+gg7eZHc6xNV2GXt4ohUsU=; b=uXd5zvRxGN5COX L76bh3u2yMctqT0cebTS//eQkbCgUVZWJCQhtRVo6X4ZfdtYQHK2pM2IHBgEnFCoFa5XViw/9u49L AfOR8QFZuaMmFQ5ppx+T+DKDIieGpHFuAL2FTfYCECu//5aj8e8I9hmika7W6vPD/I63H6RbQBf5T vThuQ2+kgH30k/d/wirjapjVHFVh9fA/a6K4KpXvJltrymjRstyYBd7CQKrrX+yvUDHdePIT+LR6c 6jpXyT9SiQ91Do6+qCn+ybpn5SuKWVe1rF0Ceyxy9Xckbv8E4iXWGjH2CjTFV82wdnMV2vf+FYFSU Yk/kQeBjIg9muCnPjaNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mc63w-00Cays-MU; Sun, 17 Oct 2021 13:18:52 +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 1mc62t-00Cacb-Nz for linux-arm-kernel@lists.infradead.org; Sun, 17 Oct 2021 13:17:49 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3D65A61038; Sun, 17 Oct 2021 13:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634476667; bh=WCtbL8eWm9oMJI6f5UjA9WazSfc2NFC7dxpRMWhxVx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kn3QSZnpn+8GKfNGDahmFSW4fzRgZvLBaOSI6zEqT9ZWCIOgkLuOfkoHVXQAuJQ7O CUw/BaGvd9OaJ0QGLfdU4MleLEfpzSi80K5oIW+KBglajNNP6jfeBkYQ/XoQ5kE7Vf oCcBhqx1NkOX/5n7xxEWJrxGfkcYxR8vpa4XpGsoyRgYKzJA5jYGeEGFkmxty5ivia gK9+hdxtvvCjrbMwc0N46IEab8XBKmkfMYQKWgQPU/I237h1dilc13NbLdt3nnTLHq QMDChT7tJ2CyJxht2pBArKxVV7EO8Wgh8fh1+P8puJ4fL71Euj48rQ+Ud2kjwbjcnW PE0vlTqHzf3ug== 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 v3 06/10] ARM: unwind: dump exception stack from calling frame Date: Sun, 17 Oct 2021 15:17:19 +0200 Message-Id: <20211017131723.4034662-7-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211017131723.4034662-1-ardb@kernel.org> References: <20211017131723.4034662-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3329; h=from:subject; bh=WCtbL8eWm9oMJI6f5UjA9WazSfc2NFC7dxpRMWhxVx8=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhbCJaofeU3TJ2gvYRaVAFybndjO9ZVY8sudSAWpjk IoKJqfCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYWwiWgAKCRDDTyI5ktmPJHGLC/ 9jVFHnDtSzCHjFE16Vw3wVFHjADCBkDsPvtLYRm8DFNJtMx5Z44rNZCAm5lhF4f/UhKRp9GlWsIpUu 1hTk96JQ9rP5IHdcK/ojW9eRIpMv/daZNW2Tr6s5AMwekDa7e+CceX6nWInMCxg+IN4OB46xZCqv4S vcLGK/3Lb9b5HYH6BmkpUyTB1Nr8ov9AX4TxJpQ9i5ql2DusRJdR295ilylyIsR8QnOK36VKz0B0ca wgJTnv7kSDnosb3HF++0f1WyM2khopDX0CXSYXRz6sw52sV638bi3CdmNIK6a+cYWsGg45JijOLoWZ EIHnOZWih2MFD5IoeO9qOsuzVLPXazY48qfKv8GdJ0vfTY07xbbYjgAumaPzf8LdOL/+XKZJCH5a59 j6eyjDpolKw1SLzGsmTRXeKUCvDkHPR5OVsVOeFeabEO6Jw801hy2oolzJrcsC1f2zWlswu8Tj8JIc 22aqSzryveFUvt2FeNZOrnUFIC1/Z/Z57HF+Aj6fQYPeE= 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-20211017_061747_853894_07E08FFB X-CRM114-Status: GOOD ( 18.78 ) 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 | 11 +++++++++++ arch/arm/kernel/traps.c | 3 ++- arch/arm/kernel/unwind.c | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/stacktrace.h b/arch/arm/include/asm/stacktrace.h index e86f55155500..8dcad8156561 100644 --- a/arch/arm/include/asm/stacktrace.h +++ b/arch/arm/include/asm/stacktrace.h @@ -13,6 +13,17 @@ struct stackframe { unsigned long sp; unsigned long lr; unsigned long pc; + +#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 b1ea2e4870ce..cda32385552b 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