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 AC1F1C433F5 for ; Tue, 5 Oct 2021 07:19:57 +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 7B25160F59 for ; Tue, 5 Oct 2021 07:19:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7B25160F59 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=iHhexGiElTyIp+r9cvkj8+qe7jVXVEJlBVb8CLXmi2w=; b=NShnzeb3SuVo0j Q0VJPh1GKOi/mXJCt6nP9LNRud7E1+y43oYZGeH1HXKhawzkAhs6fObB5MsMbYnom/k6gf+ySYYNO au9mUoi/6j+0jnI/SrbDKzWXxBWTELy8SGsWjRLEUM7VKBd7fdgdtiOpg3bK/E3/H6/or+mkdgmU2 5Bl+Uk1MC9MHTYBOAykE9kecMwVLWi7eWv9HA/sRS2FYQD9t6eDtLon/zWCclB3xqvIRARZJU9RJT fJBt8cqH8a7GdLjxw01kSkK2BEKcspq6BC+zvUN2WuHqqRKeixssyp262OEYf0tUnpZA4QpUkgLEi PslvbxVqzhZIT2MRjWkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXeiC-009J1d-63; Tue, 05 Oct 2021 07:18:04 +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 1mXegW-009IL2-Ls for linux-arm-kernel@lists.infradead.org; Tue, 05 Oct 2021 07:16:22 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id BDD4B61506; Tue, 5 Oct 2021 07:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633418180; bh=43+HYszJko/24FXKRYnC0Th1/VI9K6oedzmv2L3l/yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h6nNeoTeQgemBBiWxPiXC/Jq79LShXEn+UKn8jIgxg81VWnpw/yMOAYdb5Q+x5uDn OXfTCbxOwVCWhKUL/HqHEXbjxI1WXEPIMkVfqUdeoUhbrE4e/eSyGRZcZPZ6dKNbD/ ajBfg1XCpiXy6Z++XLhA6o2EjsOnITBj0w7DRQCvt8kAZVHSGWovY7MLW8gQodDXCz T4FKUBrXVhH1oi+c+9mQKm9O8uEC6Nlkn3HyJlCGK4NYd5P/hxnioNNccatZpuBrvT RRTYrfiULytBJ/mty3RY1ctBZRhiEx84G81JJrdrYM4ev7HKwW5UepoGesymWrTw4M BiIsrhD8h8WiA== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: Ard Biesheuvel , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij Subject: [PATCH v2 6/9] ARM: unwind: dump exception stack from calling frame Date: Tue, 5 Oct 2021 09:15:39 +0200 Message-Id: <20211005071542.3127341-7-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211005071542.3127341-1-ardb@kernel.org> References: <20211005071542.3127341-1-ardb@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211005_001620_777453_FCD53C12 X-CRM114-Status: GOOD ( 17.92 ) 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 --- 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 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