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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1345CC54E58 for ; Wed, 20 Mar 2024 15:30:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BD096B0082; Wed, 20 Mar 2024 11:30:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 749476B0083; Wed, 20 Mar 2024 11:30:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 635456B008C; Wed, 20 Mar 2024 11:30:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5004D6B0082 for ; Wed, 20 Mar 2024 11:30:20 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1BE87C1390 for ; Wed, 20 Mar 2024 15:30:20 +0000 (UTC) X-FDA: 81917803800.29.4C220A7 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf06.hostedemail.com (Postfix) with ESMTP id 691EB180023 for ; Wed, 20 Mar 2024 15:30:16 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of xiaojiangfeng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=xiaojiangfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710948618; a=rsa-sha256; cv=none; b=qpqJTQ/Rjk8HZUDU9F7BrdPVKMLH5Itk9ZJMkALuaDSi2cXzLSTmDT22FAqxjUEq+c5Q0w j8PnvxOLWB9Gdf35mzSXML2xu3eHqdbqKcxItAfK7uy24CiumP807/84WoAqOoDSYb8mPd 66z+WmeUHqpotfCOQp9AgkPJFLUUfK4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of xiaojiangfeng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=xiaojiangfeng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710948618; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ILZltGELNVZPwgpXUICuFoW9+xh4Q0Y5abC5yI1MBMU=; b=4zDd6sDOnQcwfFqu3oi3zfVD72/biTQl6PNK1Ug72zbLJXNJHUpCvG/6TEocoSqWkrh/Nd 6sHcgI900sHW9vNzwQcMkhawzBwK1UhyfDEWWnENa8NJiqL+bSbjt7yf5MwUipekXA5+Cw mJXcJjrjkqDzb7nn7mM3OHjljkPXDyg= 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: Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit 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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 691EB180023 X-Stat-Signature: ke6jhkipt1iidpsuype5h775f11wzd59 X-Rspam-User: X-HE-Tag: 1710948616-59714 X-HE-Meta: U2FsdGVkX1+y9VR0cKNsW2VpGvXkTjA5R6pr4+kFUB5BNM9gB1Y7t53+Hk/r8znFym6O9wohf8W5kcAXPs3A/fNbWqO+yt2QhQZRbVYmuS5rqhnFZuk9vGJScollB46F7LKyKGPvDzz0InF2E9ZZJK7fIZxOWd3hQC3/EgTOfPSVnuEm8sOSsjDEspQeIbeDl86e5lA6gCBiyWPTnOgf3Kf7ff4mntcX7KGXGH1B2FUmTf3oV1ISO88HDu1B5HctK99H91muqHSn6oZU3ThkV8stzSnRtqYByapG2cgZWDlOtZIGX/9XdYi7JYDPbszjIZ8kvg3pDyI5D/q3MfOvV/6wAfst7qYzB/YpmOivDfn3Yekc7LUe5FnDcANUFiUhA6TwythvaLySjkVLsp5T/u/O/IAfEZ7f8JVB+Rjx7WOLsByLECilxaH+cz6DyfrTPfXtdy1JDEMPBg1msmvcw8JDBaa6OuJLfndPx4M1knB5BpHHpiVb2YOPL1+QxvUH0VzgPdkaO2zeyW2EoAswGom1DUQB1PxFtJYfm/py3GN/a7fve3WG6F4/HpeUStKMwqprK2QgIXD/jbNWaLETQV2AnEbzZ5vxnyMSITqb7uWsjVatqG1ym/x5vbrGphXna+PIMvJaLVbg+1kMVwj9E2X8W/lElwTnbAd3KFNQF7bzlqNIC2SqXbE8JuYlLTW+eSLGPWxMHCLHQH7niKeJi8tkKiM00eFmJMCzlJoWoliuqWWyLAvzq/Yt/rnhmYwqDKjWt4g4RS9vu/uadpBoqQ+plfG3Ag9ersbSKS8ydWYuYf6mFixcDYthYCeecuIBW45veB9YmcPqxu0BKpE1pvWwHJ40Cc70ivOYMWWNdfHo0WLumSDPmucFJoVERFAIw9iMVswtuNU9o86G70Ww5ouM+K+9JKNDGJr6+q+95lQzNVZ+5p9QPzpJ42zd7e3CMTnkH00kmH/ctFYl8XQ Dina6fxl O4jS24CO+FxoOWa0Xor40PgNDM2jGaXxgJIrBzeQHsTIbplkcG21Y88o6BHt81jDC0h3sCOfR4kyY1GTHmztPu5dUNDDNJuATC9ycQb4SqWqEsA1s8IZ+iH9KjE/UnQgeOtetTefUkIS+iT6nPcnAJRQ8ck5RALCXtjOmv7DyreRvk04= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 >> >> >