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 52204C54E58 for ; Thu, 21 Mar 2024 15:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C22146B0083; Thu, 21 Mar 2024 11:34:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD0F26B0089; Thu, 21 Mar 2024 11:34:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A24076B008A; Thu, 21 Mar 2024 11:34:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8C5C66B0083 for ; Thu, 21 Mar 2024 11:34:17 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 16FDA41632 for ; Thu, 21 Mar 2024 15:34:17 +0000 (UTC) X-FDA: 81921442554.02.5E184B1 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) by imf16.hostedemail.com (Postfix) with ESMTP id CA588180019 for ; Thu, 21 Mar 2024 15:34:13 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=armlinux.org.uk header.s=pandora-2019 header.b=AbMqESPh; spf=none (imf16.hostedemail.com: domain of "linux+linux-mm=kvack.org@armlinux.org.uk" has no SPF policy when checking 78.32.30.218) smtp.mailfrom="linux+linux-mm=kvack.org@armlinux.org.uk"; dmarc=pass (policy=none) header.from=armlinux.org.uk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711035254; a=rsa-sha256; cv=none; b=yWAxA9eu0oI3ZrPSmZCj5hOLy0l+F400p1InhKIvA1FT3JBfEtsq/Y1AEWm0X+QCx+22DH VX8OfXyzbly5VdY1e9IKDi7flovtPVbZSqwelZateVYOYbP9PMN6EXkuYP/M6X3qqjx7FI 1kLDvPWfSmVwAZV7pL942hKT3i8GCC0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=armlinux.org.uk header.s=pandora-2019 header.b=AbMqESPh; spf=none (imf16.hostedemail.com: domain of "linux+linux-mm=kvack.org@armlinux.org.uk" has no SPF policy when checking 78.32.30.218) smtp.mailfrom="linux+linux-mm=kvack.org@armlinux.org.uk"; dmarc=pass (policy=none) header.from=armlinux.org.uk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711035254; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r1uLotYzh1w/n8/XorCAtCsehwC+SrTBTj1aIYvDkuM=; b=uDVTn6HLbGNFXAS083GGpjfXy1k5bcMIiVC5vTweJAr9wTQEiChneK7YvSt72EAzmlLAxH 20rGhqlJLhVRiwB4PBchi6pF+P5gjdECMdVb0UL8WU0cXj5tmsutB0ILSOralYfSdkf+mx vRGM6UXKZg20QkDTZ+ILL4rVZAvuLy8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=r1uLotYzh1w/n8/XorCAtCsehwC+SrTBTj1aIYvDkuM=; b=AbMqESPhaZA5tNhCyI7jjEkxpE FeIj9N+ro0VrWw1AqrnnUp5d9kp9B9DlByKZtXjubJVvXfJObRAjbh7/d8Y/n4luVRGXPDKpYSggg 0b1HJWKgB2XYEH5w8KYZ4QJPu02bTWJrgmlZEHLM/nda8XX4j9+yWDds5NCLErOdgKJU8uQHQ2/fI wqW4slom2JbhPRaiWscJF91dDj/KRrIIau9qlhpZi88wd49v8NpDzk1gfaHn4Qgwo5vGvFYOnyiQ+ IMja0Psx9uGTa1C0o73vihKq2WXq1nMjrNMW6ujAvTPmzgYyI9RXjSCE590drglebMzVHu33WNCqM u75Ro8WA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:57550) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rnKQP-0007jl-0f; Thu, 21 Mar 2024 15:33:49 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rnKQJ-0003kc-MI; Thu, 21 Mar 2024 15:33:43 +0000 Date: Thu, 21 Mar 2024 15:33:43 +0000 From: "Russell King (Oracle)" To: David Laight 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 Message-ID: References: <0fd55e156195440bb1d815dd8300894b@AcuMS.aculab.com> <9d6057b110034c04b6b590522c8c69cc@AcuMS.aculab.com> <401453a216644af98d577f51c12d292b@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <401453a216644af98d577f51c12d292b@AcuMS.aculab.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CA588180019 X-Stat-Signature: jrkwc3qx1pq5sktp5nr1u78hujia1bwm X-Rspam-User: X-HE-Tag: 1711035253-573848 X-HE-Meta: U2FsdGVkX1+M1+I4MaiPmlXbBwUpyUcAkWqlGM0gLMXQ6qYuMETsMogEQ9wZJ9kr4sxhnSuKIgBWGss3IY2hjUM7iyozKGaxk1yHnpSKvfu9qTnec9fHRKrPoe9uh8TLzrIsSQm9au6L245LK0SFAYdDDl8hwaswu4ikzPzOHurztpWY8r/JA7NZwSsRY7fhMxD9bHOKCx3LPkoThfjVTRrOv0CBv82J/mPjjH6jP2B/R05MjeYlfgShdsJX8bfeCgTQDw2D0kewE2nyrRUSoVyiAS7PtMAgqnxX8bFjwHwDZfvPidhKThjlZFCEA1Ra3XWT6L25sWCwWmYHSHW356BNJjUS2Q/i9X3wAzIvXRh+sJ7doR0tDxVCZWaj2ow033uIUnwHDgDtTeh6WMkQrdlk9UTXOeaUulK8xa/IyJhPDDZNt5xmR6QX4jUxwuulPgXX4X14i7NG58jiP/BjG0/aWyq4mgFEtHM1xDxK9QeOQfQi3JrDZ1fMUzmSbg3KofsHkPqby9GssxbpqRL8C4RlTQNSClIGPO/TiFvYWGiT+meg9Q2MmDwKHTNTa9mCUVBwKvfdSsJ3kOWwpf3zPdS/r4sZoUCKR3zf/Vf8MCMdznjDJOt6Trt0QkLHXi/Mo8J/iVrx/NTwL3vEXC8ImHq2O30dURRPWo3bBFiksGP+mnqiTJ4CMpxep4HdoUakaWYbzYkXupp1wvt11qOcrjfeQGyTLaJ8dhtMGn6fDtScRrPrKTGqJV8N5V1dYikYgJ9//hPIuefFwRwlHCMPsliV6hxxUs6uo1waovw1CLeK7D8U7PbJZD5mI93O/cyZo7F75DUfuaHOztWWhWGo9lhnqdzSuXmFpa8bJdUYJwrvLUGqpXWXUCAEUXyf8p0RcA6D/05Dd01ZF3N4Kb2iSRPweAEwrWxYGDzVfvVCZB/n1sxo7zsPWLneXKojRQjJRA2M2tUQ3Tx0rag3o+R QZMHhM7L HoyxJYEYaIzVfMplyKMtkpOahsccyEn+PeBjY7XppgfuzoHANfQjCZYWHqXEDYZ/QS8dJuNAt8Krj64maQT8EHiyv1/0rcO3t6ZBGuFIIjfYLBKRkTEjpaHm19Cm9fMMiiW2wA1iq9ewTPmWmam7lwP8qkjaAc6+BaCIi83IXWQBtLN7dWpMglKyZcXvnMGa4yM+/JHJoIyx45qsQRx4M2V38u6jVHVANP+DhrAYLDKDdsPFEA6yqcGWW/gIvBR110ZXkBeBXUFBLofy99A3BpgdWQB+1XZa2T+e1TxrK2b3z5l2Un+zB03pDV3RIhM3fsBWtuHAwL90f4+wUvQJBxUDB/oak6U+MVESCXb2THJyHl+VSewKwZF/H93vz5aq/05ItPK6LQ63O2C/uhmVcx1LeR4vIGHN3BciJVwL6wkOVOFXqsmc87OB9uP4dQhzVuhi5GYXmtCo5pW9u3EZK8SHb8uUs+PUUOYh1c1rp6P7yAAAu1cThdtOfF2wMjeW4m5DEMQayRL3I8sAia9ch6AicXUwugN+dzBeft+nv+CMjY/eOOPfzyMofe4UJegJAcS+jdLrh1Prh3KoIPpZVvvzW2pZbTaBw3m+BThzHqDZm5DnqBFIhr1dDlw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.003508, 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 Thu, Mar 21, 2024 at 03:20:57PM +0000, David Laight wrote: > From: Russell King > > Sent: 21 March 2024 14:56 > > > > On Thu, Mar 21, 2024 at 02:37:28PM +0000, David Laight wrote: > > > From: Russell King > > > > Sent: 21 March 2024 13:08 > > > > > > > > On Thu, Mar 21, 2024 at 12:57:07PM +0000, David Laight wrote: > > > > > 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. > > > > > > > > > > > > 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: > > > > > if (...) { > > > > > push x > > > > > bl func > > > > > add %sp, #8 > > > > > } > > > > > code; > > > > > which is fine. > > > > > > > > No you can't.... and that isn't even Arm code. Arm doesn't use %sp. > > > > Moreover, that "bl" will stomp over the link register, meaning this > > > > function can not return. > > > > ... > > > > Don't show me Arm64 assembly when we're discussing Arm32. > > Oops - I'd assumed no one did 32bit :-) > In any case it is much the same, see https://godbolt.org/z/7dcbKrs76 > > f4: > push {r3, lr} > subs r3, r0, #0 > ble .L2 > mov r2, r3 > mov r1, r3 > bl f > .L2: > pop {r3, pc} > > f5: > subs r3, r0, #0 > ble .L6 > push {lr} > sub sp, sp, #12 > mov r2, r3 > mov r1, r3 > str r3, [sp] > bl f > .L6: > bx lr > > That is with -mno-sched-prolog but with 5+ args they spill to stack > and the %sp change is pulled into the conditional. > > It does look like %lr is being saved (and for arm64 I think). I see nothing that contradicts anything I've said in your example output. You have been previously refering to a "bl" in the prologue, which is what I thought you were going to give an example of. There is no "bl" in the prologue of f5, the "ble" instruction is a normal branch for less-than-or-equal. It's b + le not bl + e. At .L6, there will be a difference in stack, but as f() is declared as no-return, anything that comes after it is utterly irrelevant as control is not expected to reach any following instruction via that path. If it _were_ to, then in the example you give above, because "lr" points at the bx lr instruction, the result would be to endlessly spin executing bx lr instructions. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!