Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1703618imu; Tue, 6 Nov 2018 03:02:29 -0800 (PST) X-Google-Smtp-Source: AJdET5deHn488hVDA0oXss1bcesmxNUFSS8OtLaItzYnsHJO/7DsIePc40VFPHNS8n5p6uywfc8w X-Received: by 2002:a63:e84c:: with SMTP id a12mr14108087pgk.241.1541502149908; Tue, 06 Nov 2018 03:02:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541502149; cv=none; d=google.com; s=arc-20160816; b=K0bMfvog0jS4M6cHg2GA7fzEGSw2k4ggMcIALN391LVNZoGzaXntMijfxkk0OT/vQT C3aZPsGkxjhU0Y2CBsN6BIDywEBHyD+y4qDZHxaWLJMk2eI9Wx3G31pP5K7EDySAeM1o a4a/JVaoQj13RwW1xcoXW9zF2kSvsaZxffl/xckl2TF1CEtUFJZG0FyrWmVb5R+wcE6d QPe9zJZ3sKPcJFC6c9tW9avPFEYKiTfYB3gawYssN4scmuI6Q2Jvqs4JXEkF7U17Xiug 1SZOTUEv4R0J37nP9mjpTu4MsbAQcD3AEVi2V/iTv+0++lTqLOFLpYDSU90+t60CdTNV s4pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8knYZQ8QDc4WohdDl7Rl0BtS2l3WleKTbQxKw2Q2mDU=; b=MHC1iaL4rZb/oWMBu2cQqP8N5InMxSkSGOlOJuh2r1lhJ4O2FAmC52fCbJYOJKH323 fLlcaJElwFN8TBbr8U2H6aHkFKKZL43HrklFPtiqzHvoL5e2pzoudEQtt5TTCIfuH9GI bfrzOQii4fJW03rvsvF3xS8MyPekuCpxLcDrQcgt2DJxL+Np9nL9oCNhxmF/J7a/w2NN 2fGVrmPBqL3GS9ZJy7Zj359fdQ3cgOyo/zWVW+CNnOsq0aH2012Wf20e34arhsyuLJXi AA3xff0QPy2zSR0MA91ew3fTpntCkgMAL82Lr1pa46SGDjZmNSnVZTscy6jw6DfWCw3B 3TFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si9056260pgk.49.2018.11.06.03.02.14; Tue, 06 Nov 2018 03:02:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730370AbeKFUZH (ORCPT + 99 others); Tue, 6 Nov 2018 15:25:07 -0500 Received: from foss.arm.com ([217.140.101.70]:59046 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729816AbeKFUZH (ORCPT ); Tue, 6 Nov 2018 15:25:07 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 20C0BA78; Tue, 6 Nov 2018 03:00:28 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9C5A43F5CF; Tue, 6 Nov 2018 03:00:26 -0800 (PST) Date: Tue, 6 Nov 2018 11:00:19 +0000 From: Mark Rutland To: Daniel Thompson Cc: Zhaoyang Huang , Catalin Marinas , Will Deacon , Dave Martin , Michael Weiser , James Morse , linux-kernel@vger.kernel.org Subject: Re: [PATCH] arch/arm64 : fix error in dump_backtrace Message-ID: <20181106110019.36ps3tyakvocwst4@lakrids.cambridge.arm.com> References: <1541488775-29610-1-git-send-email-huangzhaoyang@gmail.com> <20181106083901.erezwtcomiijvdrk@salmiak> <20181106085751.hrp7qkp53cftgew6@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181106085751.hrp7qkp53cftgew6@holly.lan> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 06, 2018 at 08:57:51AM +0000, Daniel Thompson wrote: > On Tue, Nov 06, 2018 at 08:39:01AM +0000, Mark Rutland wrote: > > On Tue, Nov 06, 2018 at 03:19:35PM +0800, Zhaoyang Huang wrote: > > > From: Zhaoyang Huang > > > > > > In some cases, the instruction of "bl foo1" will be the last one of the > > > foo2[1], which will cause the lr be the first instruction of the adjacent > > > foo3[2]. Hence, the backtrace will show the weird result as bellow[3]. > > > The patch will fix it by miner 4 of the lr when dump_backtrace > > > > This has come up in the past (and a similar patch has been applied, then > > reverted). > > > > In general, we don't know that a function call was made via BL, and therefore > > cannot know that LR - 4 is the address of the caller. The caller could set up > > the LR as it likes, then B or BR to the callee, and depending on how the basic > > blocks get laid out in memory, LR - 4 might point at something completely > > different. > > > > More ideally, the compiler wouldn't end a function with a BL. When does that > > happen, and is there some way we could arrange for that to not happen? e.g. > > somehow pad a NOP after the BL. > > It's a consequence of having __noreturn isn't it? __noreturn frees the > compiler from the burden of having to produce a valid return stack... so > it doesn't and unwinding becomes hard. In that case, the compiler could equally just use B rather than BL, which this patch doesn't solve. The documentation for the GCC noreturn attribute [1] says: | In order to preserve backtraces, GCC will never turn calls to noreturn | functions into tail calls. ... so clearly it's not intended to mess up backtracing. IIUC we mostly use noreturn to prevent warings about uninitialised variables and such after a call to a noreturn function. I think optimization is a secondary concern. We could ask the GCC folk if they can ensure that a noreturn function call leave thes LR pointing into the caller, e.g. by padding with a NOP: BL NOP That seems cheap enough, and would keep backtraces reliable. Thanks, Mark. [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute