Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp412288lqp; Thu, 21 Mar 2024 05:23:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX6pwTCA81Vm4Kga3XEcc3zps1QvKFBgUGKPVrtWmJzK4UNQ1jg5OcuDB7EkBuUfeUO972/Fv7EdI0AVI2bICrDQia6ozPGJ7/9WXpp9A== X-Google-Smtp-Source: AGHT+IFfOTdMu4AFsPlVG1l8QPdG21EBWXCCs0nj23dsANlByEZGfsQEEfMwtv/3qhEU9288iNPA X-Received: by 2002:a50:c2c2:0:b0:56b:cfef:b2de with SMTP id u2-20020a50c2c2000000b0056bcfefb2demr590046edf.26.1711023823174; Thu, 21 Mar 2024 05:23:43 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g7-20020a0564021ec700b0056a2e68b268si4109844edg.6.2024.03.21.05.23.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 05:23:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=Lkj3c18Y; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-110026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110026-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E24791F2236A for ; Thu, 21 Mar 2024 12:23:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A1ED7604E; Thu, 21 Mar 2024 12:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="Lkj3c18Y" Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56A0075811; Thu, 21 Mar 2024 12:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711023814; cv=none; b=KhrTgrYQDM0y/BwqRcth7s5vrxvSydjUbwAUojUBhFETCMP2gfVBuGdlk5ygJJSjfBmMxmmlj7S1slIhX4uZPeL7+/nuKIxPCCHalDN//2lsIHBIGwmhWj1avN8kPrykYaK3G4y9owvuvHFESmxA4OBnxzBapWg/4w37o6n1hm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711023814; c=relaxed/simple; bh=z0N29RLfNcOGlvR4fveRMkFS5KdyxhdBZ5rmI2uvv4A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U5kIvSFcAiXkph14S3ucStB2VCRWLOflNqI052aSxEPPuIay+KR4iBQ+GQTJ1hlYlZjPkPxgeWpd7oFThb3orbxELJb7X/ogwlL5RIcwvpEblFCwRgRUGRLtGtHXF+4lzkUYLn+5qeuJsTBj3JYF4wTWwNRFRzIBkBWoEdzO4Vs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=Lkj3c18Y; arc=none smtp.client-ip=78.32.30.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk 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=bv5iaIHPCtllbUdTBibdobMZ0uFxV6D8XvDh1qKAPRc=; b=Lkj3c18YRRBepAzzJc64myDSZ6 vTbXteiIViBqHGeU6E9lDwpYqA0nDPgbUdpNDKiKND3D3T7kC05v3NOAPvITBZ8sQH/gZ/oYjHuR0 Jr9QRYKBkKGYOSs1J56y0aTRsIsA7gFEzzc4ioVpgPvb96lA+eVHPF27AqqLR96jTwaTeYsmli5DK 6lHemPYIN4ZXJrAQ8ki1duGAs00GxSlSMT5x5tqU7qxB7/sU9bKdNQuB3hXCxVSDzBg5CdCm9aXGM t7xvvUgoUj6DAWZuSdv/CrgjYFfm8lenv+szEn2gueWVKhEgXbVFPfutWDZd7VNTtqWD43wt/75rk 5W9R5S2w==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:55568) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rnHRo-0007XB-0R; Thu, 21 Mar 2024 12:23:04 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rnHRi-0003dh-TB; Thu, 21 Mar 2024 12:22:58 +0000 Date: Thu, 21 Mar 2024 12:22:58 +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: <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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) On Thu, Mar 21, 2024 at 12:07:51PM +0000, David Laight wrote: > From: Russell King > > Sent: 21 March 2024 11:24 > > > > On Thu, Mar 21, 2024 at 10:22:30AM +0000, David Laight wrote: > > > How aggressively does the compiler optimise 'noreturn' functions? > > > > I've seen cases where the compiler emits a BL instruction as the very > > last thing in the function, and nothing after it. > > I've also seen the compiler defer generating a stack frame until > after an initial conditional. . which is why we pass -mno-sched-prolog to GCC. > 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. > > 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 = next-instruction. You are missing the fact that the PC can be the saved LR, and thus can very well be the next instruction. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!