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 AA7A1C6FD1F for ; Wed, 20 Mar 2024 16:06:06 +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: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=IIH7/G+1Sp8/0TJ9w36xd5znKrZQAIX3nuClRIaInnQ=; b=PwL1KG/S+mhdPp 8BhH/JQBH7Z2ca/yc1DPlnyAcRxe+k7mHPbTXub5+NYium0geTU9ccc83WMzkGZKMTnRr2XVA0T1W u4XDvNWK5T8JiyGPBzpNT7ZeQzzuLNwsMnmr/XWFDfIAjTssEI0y0FXT5rrjjFP97iQpAtbevr0Jc 7qQxAobZ4CO4lfAQlNbtfF7My/9SULiUIol68U4wHEdWyU/6pATDOdeglHpLjx64B3qAswrbGZjnn SpqZBIKxWhGRBHsolPLn8LhBaDUTuajt1cHDeGvcXd48DuqNRS6Yk0wRhdGhvX9zTYgaCnxfveZkz AufX3u3iUKagtwaLi07Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmyRp-00000000Dmr-36w2; Wed, 20 Mar 2024 16:05:49 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmyRm-00000000DkC-1w0U for linux-arm-kernel@lists.infradead.org; Wed, 20 Mar 2024 16:05:48 +0000 Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4V0D1W2jdvz1vxBr; Thu, 21 Mar 2024 00:04:31 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id B91A41A0172; Thu, 21 Mar 2024 00:05:17 +0800 (CST) Received: from huawei.com (10.67.189.167) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 21 Mar 2024 00:05:17 +0800 From: Jiangfeng Xiao To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , Subject: [PATCH v3] ARM: unwind: improve unwinders for noreturn case Date: Wed, 20 Mar 2024 23:41:34 +0800 Message-ID: <1710949294-29287-1-git-send-email-xiaojiangfeng@huawei.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1709516385-7778-1-git-send-email-xiaojiangfeng@huawei.com> References: <1709516385-7778-1-git-send-email-xiaojiangfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.189.167] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240320_090546_693219_D1C9788E X-CRM114-Status: GOOD ( 15.42 ) 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 This is an off-by-one bug which is common in unwinders, due to the fact that the address on the stack points to the return address rather than the call address. So, for example, when the last instruction of a function is a function call (e.g., to a noreturn function), it can cause the unwinder to incorrectly try to unwind from the function after the callee. foo: ... bl bar ... end of function and thus next function ... which results in LR pointing into the next function. Fixed this by subtracting 1 from frmae->pc in the call frame like ORC on x86 does. Refer to the unwind_next_frame function in the unwind_orc.c Suggested-by: Josh Poimboeuf Link: https://lkml.kernel.org/lkml/20240305175846.qnyiru7uaa7itqba@treble/ Suggested-by: "Russell King (Oracle)" Link: https://lkml.kernel.org/lkml/Zeg8wRYFemMjcCxG@shell.armlinux.org.uk/ Signed-off-by: Jiangfeng Xiao --- ChangeLog v1->v2 - stay printk("%s...", loglvl, ...) ChangeLog v2->v3 - Redundant code is deleted to simplify the code --- arch/arm/kernel/unwind.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index 9d21921..abfa8e9 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -514,6 +514,14 @@ int unwind_frame(struct stackframe *frame) frame->sp = ctrl.vrs[SP]; frame->lr = ctrl.vrs[LR]; frame->pc = ctrl.vrs[PC]; + /* + * When the last instruction of a function is a function call + * (e.g., to a noreturn function), it can cause the unwinder + * incorrectly try to unwind from the function after the callee, + * fixed this by subtracting 1 from frame->pc in the call frame + * like ORC on x86 does. + */ + frame->pc = frame->pc - 1; frame->lr_addr = ctrl.lr_addr; return URC_OK; -- 1.8.5.6 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel