Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1778037imu; Tue, 6 Nov 2018 04:18:02 -0800 (PST) X-Google-Smtp-Source: AJdET5f/aECG3IH3QWmVOaRF3ViRAsumYNIvUkCv87BDCRZ7EBL9628Q0JoUuaxVXgNgKzSyVFzG X-Received: by 2002:a63:2a4a:: with SMTP id q71mr9419941pgq.374.1541506681961; Tue, 06 Nov 2018 04:18:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541506681; cv=none; d=google.com; s=arc-20160816; b=UVsQqVHQaQ4n2GoOFIZEKfrkdbAWKjis9FYCFcaEtq3yu4fY3JPWm+nPtuCTNgbOLS xKMupmoQ7dcjr9Ad4OyP/PLR/dtAu84PieHnwJnzYNQHJU0rqklD5HjRv+8lD0TsQ+tD O4ufZmClJsJ1XNPMiofAtgAsoUXh0QzIgiPlYtZ7Fj2cFhLgXFnrUwuaJ0I6BPAQjww9 ktCo0UO1By7QeCtHLz5VR+Xqv8kPFjvtjfovH7A5oJEH/m7+YaTcQTf98zz7xbN8GRdr M62gSFb1qZRaEjTytHAJ8amGCUiygxqIDiWF8xX3spGu3WX3c0Tgzgl2kSmeRdQgoMzk KXSQ== 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:dkim-signature; bh=ihD/hM2HTxE7M0zg9lTRAfTdRdJCN/VBGoL4XIWGUJQ=; b=hV4GEPLBI+/wT3A1LmLJ8YQg2mzL9sUYzuktiQlbRy85lsloz8Kyg5qnRNKGEgMq4Y XYoCHbUBwLENhZSi9LAUoFyUZGHfXVYG3IptKRDeRrtAWNCFHsxfXJDLr3eVwpRJ9vHH fVAq+F9iUPZLBsX/gxWZkBXrTDD3/tleerCrBSFKeW3Trqer3TrKp9a9oKGr8nZj5UAm 2HWqmQDf3Ab87GqJ2ZkSHrcBx1NRDiZRLWL98eRjF/ITktUod9s77t6omg9F/b1ZzdRg EUvLmTRcL1mEmH87sE03kKTI/CAicrs+oNI9YOoTNxwkaJIqgmNI4BltTTp5RxZZvNtf zmLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FHZVHAID; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1-v6si1938015pld.395.2018.11.06.04.17.45; Tue, 06 Nov 2018 04:18:01 -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; dkim=pass header.i=@linaro.org header.s=google header.b=FHZVHAID; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730668AbeKFVaG (ORCPT + 99 others); Tue, 6 Nov 2018 16:30:06 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51094 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726976AbeKFVaG (ORCPT ); Tue, 6 Nov 2018 16:30:06 -0500 Received: by mail-wm1-f67.google.com with SMTP id 124-v6so6232012wmw.0 for ; Tue, 06 Nov 2018 04:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ihD/hM2HTxE7M0zg9lTRAfTdRdJCN/VBGoL4XIWGUJQ=; b=FHZVHAIDyB5duNWne9eSqLBR75F/VQpg0kQPBaqhRKTOUSRdUSqGJunYZX4EyFzXH1 dvbRjZIk13svtE6okubWTUsDcfd5QUunomC3CT8H0FHoWIGV5//2ovfVVaZs3DA0VUKi iGm78lZSHTuEI0YfItzop6iT25En/RZM7TZVw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ihD/hM2HTxE7M0zg9lTRAfTdRdJCN/VBGoL4XIWGUJQ=; b=mUk/h0XegNmpZiSGfpvneczbhW0yJmJ9XoeJifzA7Gr2Dp7mR0aIci2PWmIqEC6MlP j3kL3pJIsH7R6MPxjdzXjqj7smNvjU2md5F4reDg8wdsIgMzsamXgIVrBDEtYRbNSigY pKTOctnYuIPH6VsMAvkNpH31ANB8iEnPEnI+E6XnzA4gp1F090Pwrv86cAu8vjeN0RRm 1Ro+FyFR82PLueJXoCxm9nAjDFs8PNbK8B7AZZmP/M/rDagVARHWvOiys5xeA+fcc45U a6AB0VK9ta9TZjDLuSThDOtCVY8PtOZkD2G+vf2egtDYFCsF+muDK6hDP3JEPpzRBbT+ dLvw== X-Gm-Message-State: AGRZ1gKjZl6/eYoyfHjHsd1bb85aRMZpwopR11+VoSm2LeqA4terLJnE ng2eGrBBa2ocpi5GnNjawwS8gyjg5+OPVw== X-Received: by 2002:a1c:1b91:: with SMTP id b139-v6mr1803955wmb.37.1541505911199; Tue, 06 Nov 2018 04:05:11 -0800 (PST) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id m13-v6sm8111796wrw.14.2018.11.06.04.05.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 04:05:10 -0800 (PST) Date: Tue, 6 Nov 2018 12:05:08 +0000 From: Daniel Thompson To: Mark Rutland 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: <20181106120508.hftgyoj47qygt7b2@holly.lan> References: <1541488775-29610-1-git-send-email-huangzhaoyang@gmail.com> <20181106083901.erezwtcomiijvdrk@salmiak> <20181106085751.hrp7qkp53cftgew6@holly.lan> <20181106110019.36ps3tyakvocwst4@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181106110019.36ps3tyakvocwst4@lakrids.cambridge.arm.com> User-Agent: NeoMutt/20180716 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 11:00:19AM +0000, Mark Rutland wrote: > 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. I guess that explains why the compiler chooses BL over B (since B would be a tail call). > 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. It might be worth discussing. One related question though... is there any other case there the symbol name other than __noreturn where the symbol can change between LR and LR-1? If not can't we just switch over to %pB which is designed for this case (and in case you ask: no... I didn't know about %pB until this morning when I started trying to implement the heuristic it uses by hand and then discovering it by accident). Something like: From 70a2c9ffc962a650ff894d40b775f8310190bf86 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Tue, 6 Nov 2018 11:59:56 +0000 Subject: [PATCH] arm64: Use %pB to print backtrace symbols Currently arm64 uses %pS to print backtrace symbols but %pB (which takes into consideration the effect of compiler optimisations which may occur when tail-calls are used and marked with the noreturn GCC attribute) is a better alternative. Signed-off-by: Daniel Thompson --- arch/arm64/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 5f4d9acb32f5..ea571d3a1373 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -62,7 +62,7 @@ int show_unhandled_signals = 0; static void dump_backtrace_entry(unsigned long where) { - printk(" %pS\n", (void *)where); + printk(" %pB\n", (void *)where); } static void __dump_instr(const char *lvl, struct pt_regs *regs) -- 2.19.1