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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5400BC433F5 for ; Wed, 9 Mar 2022 12:20:57 +0000 (UTC) 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:Date:Message-Id:MIME-Version:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=pBhHb6Souiu3jaM/71TmFhpKQPujhRUI/QP0A4+cqXQ=; b=QfGB0BTeNgJUeC tetq1l9rCAhk+NDCTx09YOIwYbVFQq5xdH4Kxb4U0NR66XYw350Y8gzdPvDSTx2uQhUCw2db56yDb CX1Z0rmnwH8hmEBxSkYU/ZMMSHx7JpsgjP82wWp58EiaF7HCsCXDBWfrDCG95XriWampXmQKo0I4l vCdQI8ccwVotDv6PyLmwLIQLZfGk6pW+QRhe74wzGCfmPfB+BgWgKd4LKRv1/2Rv8bds1I62bCOdn 4/eYGVk2b8UHv6jCjVYBfN80TNsFIrQBWhyAdXkwzz91Z708y8s2kUoB8k4IsoEPxtWubQ85PrnP2 qVsAk5Gq/dea6Ze7rogg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRvHz-008YCA-OX; Wed, 09 Mar 2022 12:19:35 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRvHw-008YBX-Vx for linux-arm-kernel@lists.infradead.org; Wed, 09 Mar 2022 12:19:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:To:From:Reply-To:Cc:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bCXKKhZq3a9MaTrQlFjYutziuBvSP/ktZwoxbis3WlU=; b=sDxNdTROzDopa0lVD6zIdu8mNj TkIfblzZF151XGQSk5tdAyBI6+sIgVKc8mh3FfJhUUFj0ptnbxS1jSaum001Kx6RPqHHFjJe0S3g2 tG9LAXEZ0AvSKs0lDsp6dPuTuG0oR8+sIDFn/KkUyckn1632nmV8CqgwKNEyl9Zwq0QtQasSx2IWM BPhFMl8CIVqJtpMmCyp6+ktLjnkXl2vTSydnVi4kAQDrkM393Kk6yDFw/X9sw4DaTdtbftlmEmJtQ 5JmPEXDCaXYxylJNcddk/KCoWTZLzG4I/0s21ECEZYPX2aYpfCBW7RiSJDiWcK1UYkXf0HYDvA05f 4togm8kw==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:52664 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nRvHv-0001ng-5U; Wed, 09 Mar 2022 12:19:31 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1nRvHu-00F7Yd-JJ; Wed, 09 Mar 2022 12:19:30 +0000 From: "Russell King (Oracle)" To: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel Subject: [PATCH v2] ARM: unwind: set frame.pc correctly for current-thread unwinding MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Wed, 09 Mar 2022 12:19:30 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220309_041933_054763_1645B121 X-CRM114-Status: GOOD ( 13.77 ) 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 When e.g. a WARN_ON() is encountered, we attempt to unwind the current thread. To do this, we set frame.pc to unwind_backtrace, which means it points at the beginning of the function. However, the rest of the state is initialised from within the function, which means the function prologue has already been run. This can be confusing, and with a recent patch from Ard, can result in the unwinder misbehaving if we want to be strict about the PC value. If we correctly initialise the state so it is self-consistent (in other words, set frame.pc to the location we are initialising it) then we eliminate this confusion, and avoid possible future issues. Signed-off-by: Russell King (Oracle) --- arch/arm/kernel/return_address.c | 3 ++- arch/arm/kernel/stacktrace.c | 3 ++- arch/arm/kernel/unwind.c | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/return_address.c b/arch/arm/kernel/return_address.c index 00c11579406c..8aac1e10b117 100644 --- a/arch/arm/kernel/return_address.c +++ b/arch/arm/kernel/return_address.c @@ -41,7 +41,8 @@ void *return_address(unsigned int level) frame.fp = (unsigned long)__builtin_frame_address(0); frame.sp = current_stack_pointer; frame.lr = (unsigned long)__builtin_return_address(0); - frame.pc = (unsigned long)return_address; +here: + frame.pc = (unsigned long)&&here; #ifdef CONFIG_KRETPROBES frame.kr_cur = NULL; frame.tsk = current; diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c index 75e905508f27..b5efecb3d730 100644 --- a/arch/arm/kernel/stacktrace.c +++ b/arch/arm/kernel/stacktrace.c @@ -160,7 +160,8 @@ static noinline void __save_stack_trace(struct task_struct *tsk, frame.fp = (unsigned long)__builtin_frame_address(0); frame.sp = current_stack_pointer; frame.lr = (unsigned long)__builtin_return_address(0); - frame.pc = (unsigned long)__save_stack_trace; +here: + frame.pc = (unsigned long)&&here; } #ifdef CONFIG_KRETPROBES frame.kr_cur = NULL; diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index a007af0f0209..0e2244e26f37 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -487,7 +487,12 @@ void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk, frame.fp = (unsigned long)__builtin_frame_address(0); frame.sp = current_stack_pointer; frame.lr = (unsigned long)__builtin_return_address(0); - frame.pc = (unsigned long)unwind_backtrace; + /* We are saving the stack and execution state at this + * point, so we should ensure that frame.pc is within + * this block of code. + */ +here: + frame.pc = (unsigned long)&&here; } else { /* task blocked in __switch_to */ frame.fp = thread_saved_fp(tsk); -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel