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 EF879C54E58 for ; Wed, 20 Mar 2024 15:30:39 +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:In-Reply-To:MIME-Version:Date: Message-ID:From:CC:References:To:Subject:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=OODbiESvU+GXYhRmjuJ6JJLYvHJ+KEj2MtNQiLtYYcs=; b=Z6H/u+7o+AzaCnBL7vhMt+bOrc VeZFtQMHUOjFKvrDdMx0hyDHbYtboC2vnx9xcMkdVV+b+vY+CkGL0OmdRQ4pl3EiLtw6LZTunJjYx jS+IAuaUOVXbm7/jVTHH3tzsYdD7VG/lGaBp70r1Rt/LQlq+7LbzZkb7t2BReNL1FVKb9buJ3meY8 4r2Lamjk2KODm3ORoUS7q5wu9dqiWktYKWxwxWfzIATsx9zNPS95fEtxzV/p+NyRtYpj/wIrffYMW W2u6lUJexZfRQh7WSCVkUsS8Isg5cba9C7iDq6HO0mdkXpAlDKKqAnWPLqAMDCsszDVzzcikBp2TV +cW2yQFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmxtZ-000000005Gx-2ari; Wed, 20 Mar 2024 15:30:25 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmxtU-000000005EV-3qe5 for linux-arm-kernel@lists.infradead.org; Wed, 20 Mar 2024 15:30:24 +0000 Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V0CBx5BTFz1h3Bm; Wed, 20 Mar 2024 23:27:37 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 22E0F1A0172; Wed, 20 Mar 2024 23:30:11 +0800 (CST) Received: from [10.67.111.82] (10.67.111.82) 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; Wed, 20 Mar 2024 23:30:10 +0800 Subject: Re: [PATCH v2] ARM: unwind: improve unwinders for noreturn case To: "Russell King (Oracle)" References: <1709516385-7778-1-git-send-email-xiaojiangfeng@huawei.com> <1710906278-23851-1-git-send-email-xiaojiangfeng@huawei.com> CC: , , , , , , , , , , , , , , , , , , , , , , From: Jiangfeng Xiao Message-ID: <84a57ca8-8963-ca24-8bd1-ddc5c33bf4da@huawei.com> Date: Wed, 20 Mar 2024 23:30:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [10.67.111.82] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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_083021_466196_29BA4C89 X-CRM114-Status: GOOD ( 26.26 ) 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 On 2024/3/20 16:45, Russell King (Oracle) wrote: > On Wed, Mar 20, 2024 at 11:44:38AM +0800, Jiangfeng Xiao wrote: >> 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 >> (but not exception frames) like ORC on x86 does. > > The reason that I'm not accepting this patch is because the above says > that it fixes it by subtracting 1 from the PC value, but the patch is > *way* more complicated than that and there's no explanation why. > > For example, the following are unexplained: > > - Why do we always need ex_frame ``` bar: ... ... end of function bar ... foo: BUG(); ... end of function foo ... ``` For example, when the first instruction of function 'foo' is a undefined instruction, after function 'foo' is executed to trigger an exception, 'arm_get_current_stackframe' assigns 'regs->ARM_pc' to 'frame.pc'. If we always decrement frame.pc by 1, unwinder will incorrectly try to unwind from the function 'bar' before the function 'foo'. So we need to 'ext_frame' to distinguish this case where we don't need to subtract 1. > - What is the purpose of the change in format string for the display of > backtraces ``` unwind_frame(&frame); dump_backtrace_entry(...from) //from = frame.pc printk("...%pS\n", ...(void *)from); ``` %pB will do sprint_backtrace and print the symbol at (from - 1) address %pS will do sprint_symbol_build_id and print the symbol at (from) address In unwind_frame, although we use 'frame->pc - 1' to execute unwind_find_idx, but frame->pc itself does not change, in the noreturn case, frame->pc still pointing into the next function. So this is going to be replaced by %pB. > >> >> 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/ >> Signed-off-by: Jiangfeng Xiao >> --- >> ChangeLog v1->v2 >> - stay printk("%s...", loglvl, ...) Thank you for your suggestion. I'll change the code to be more concise in my [patch v3]. >> -- >> 1.8.5.6 >> >> > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel