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 8DB27C54E58 for ; Thu, 21 Mar 2024 12:57:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E17F66B0085; Thu, 21 Mar 2024 08:57:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC81D6B0087; Thu, 21 Mar 2024 08:57:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C688A6B0088; Thu, 21 Mar 2024 08:57:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B3B656B0085 for ; Thu, 21 Mar 2024 08:57:40 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 36000C04C0 for ; Thu, 21 Mar 2024 12:57:40 +0000 (UTC) X-FDA: 81921047880.16.927A04A Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf04.hostedemail.com (Postfix) with ESMTP id 4E4E140014 for ; Thu, 21 Mar 2024 12:57:36 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf04.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711025858; 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=Ugs/LBHQ17TVRz8+/1tX85sJb3QOcQv7xVKlpf6dBWE=; b=Ayuvx6fl9vfTyiOBOXA5Gswv4Hcxwk4Rt9suVxJEYkoLqXzRBUx1kgN3zheOdobZG/vver ZR9ytzGvRrW9ycwpbJqwpj5xbyqnosw9DWBSBxmEV1JBg2BsL5vUfJPZGMMIn1c17v0+XJ VnBSyvmkhFlG7yGAtC5ZSJ3R3hovsU8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf04.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711025858; a=rsa-sha256; cv=none; b=vwqUpOKwYc2kDCjGH7NS3irvIDiOzvWsMCzN49xglsdnqVMhVqBdtHX1lEi89ZjaldC+A6 dtGumM5I7b2JZ3UJBYg7qphfNhXPRctUvHsdF6c1Stv3YosJMJx1ylpLrxm5oiCFt8RYzn mQSHD6pTGQGJmRPwbNJfllBJd4yclHg= Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-199-xgFlFvyBPmuyMshxla-1pg-1; Thu, 21 Mar 2024 12:57:33 +0000 X-MC-Unique: xgFlFvyBPmuyMshxla-1pg-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 21 Mar 2024 12:57:07 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Thu, 21 Mar 2024 12:57:07 +0000 From: David Laight To: 'Russell King' CC: Ard Biesheuvel , 'Jiangfeng Xiao' , "arnd@arndb.de" , "keescook@chromium.org" , "haibo.li@mediatek.com" , "angelogioacchino.delregno@collabora.com" , "amergnat@baylibre.com" , "akpm@linux-foundation.org" , "dave.hansen@linux.intel.com" , "douzhaolei@huawei.com" , "gustavoars@kernel.org" , "jpoimboe@kernel.org" , "kepler.chenxin@huawei.com" , "kirill.shutemov@linux.intel.com" , "linux-hardening@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-arm-kernel@lists.infradead.org" , "nixiaoming@huawei.com" , "peterz@infradead.org" , "wangbing6@huawei.com" , "wangfangpeng1@huawei.com" , "jannh@google.com" , "willy@infradead.org" Subject: RE: [PATCH v2] ARM: unwind: improve unwinders for noreturn case Thread-Topic: [PATCH v2] ARM: unwind: improve unwinders for noreturn case Thread-Index: AQHae3ROEuI+AaCprEesIWGaAOB7ebFB9uHAgAAWtoCAAAVW8IAACy4AgAADrmA= Date: Thu, 21 Mar 2024 12:57:07 +0000 Message-ID: <0fd55e156195440bb1d815dd8300894b@AcuMS.aculab.com> References: <1709516385-7778-1-git-send-email-xiaojiangfeng@huawei.com> <1710906278-23851-1-git-send-email-xiaojiangfeng@huawei.com> <84a57ca8-8963-ca24-8bd1-ddc5c33bf4da@huawei.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4E4E140014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 5ikydjet86rp7twzifp4wzb6fgghmmfh X-HE-Tag: 1711025856-590755 X-HE-Meta: U2FsdGVkX1/1ojoo9ZuN/lEW5XLDUQ53BUoj4mIX0/B2/5tDKaEDDDrh6oYthBo+P+6itEE3vAEN47Gir50L8IKfYT/c8IC4/YFRB8OF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zaPuBQ4S33inf6gsv8RDJE9fgLm67EGf4= 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: From: Russell King > Sent: 21 March 2024 12:23 ... > > That might mean you can get the BL in the middle of a function > > but where the following instruction is for the 'no stack frame' > > side of the branch. > > That is very likely to break any stack offset calculations. >=20 > No it can't. At any one point in the function, the stack has to be in > a well defined state, so that access to local variables can work, and > also the stack can be correctly unwound. If there exists a point in > the function body which can be reached where the stack could be in two > different states, then the stack can't be restored to the parent > context. Actually you can get there with a function that has a lot of args. So you can have: =09if (...) { =09=09push x =09=09bl func =09=09add %sp, #8 =09} =09code; which is fine. But if 'func' is 'noreturn' then the 'add %sp, #8' can be discarded and then the saved LR is that of 'code' - but the stack offset is wrong. > > > This is where the problem lies - because the link register value > > > created by the BL instruction will point to the instruction after the > > > BL which will _not_ part of the function that invoked the BL. That > > > will probably cause issues for the ELF unwinder, which means this > > > issue probably goes beyond _just_ printing the function name. > > > > Isn't this already in the unwinder? > > A BL itself isn't going to fault with PC =3D next-instruction. >=20 > You are missing the fact that the PC can be the saved LR, and thus > can very well be the next instruction. A PC from LR will always be the next instruction. It is only the PC from a fault frame that is the current one. The unwinder probably need to be told which one it has. (Or add 4 the fault frame PC so that the unwinder can subtract 4 from it.) At least (I don't think) there are any functions where the called code is responsible for removing arguments. That is a whole different bag of worms. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)