Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1584415imu; Tue, 6 Nov 2018 00:40:14 -0800 (PST) X-Google-Smtp-Source: AJdET5cxAb3F2Qx1iwUQHnN/U6qltkhCJIBO0R3RvXmQAnqFoz6Z7ZO9nW6Fc9DrjpgCIANea7FE X-Received: by 2002:a17:902:9a91:: with SMTP id w17-v6mr24624172plp.274.1541493614019; Tue, 06 Nov 2018 00:40:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541493613; cv=none; d=google.com; s=arc-20160816; b=d9kRm/mrTjaEpMIGmzSkg9gbSwkLmST1/i+I1OaiX0beLzmnOwW3lrMmvJA9Y/UdsN mZy7TQ6mHjF0vIs+PipOG5hGRwkCKiBFE6YCcCYXq1mq+48wv530ItmZy6J2RomdUEcr 9JbXdRE8AwdKjr35XIMIfVcEPRj5AgxrpdVeYouWjpJqfYOTi0Zhf/jC/Pp9ryTCdNPW vNWAXBtNVC5NJORDRSgjvkNOpNIDmltzhi+q/68Wz9/qwPTt4igJSh6jpyaIA+ysT3NJ T5bXJXCTWIDsy00Wtx4rLNqqOoP9tjL2E/EnqITmTWRdKcADPnMTXDgsDgse/+Tz9+cP zgIQ== 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=pTU3y5GwyCK9F1Tw5ihWncHMsuQz04AgX86nIXHHJAc=; b=oJDWIDFC24E8RYDjK1CbuFaiJO/uWjfMRY4/XE4y536Icw7kGQQqsQOsxT9yh8RXYt 3WIV/eWZcK6lip0NN/fjG4+OUiuhTvwgL+0+JysoAksfrJtp0Mim3/dpA+z8kRWPbQGR WYPZmlV0IA0LLN+XPYRBmPEPW2kf1cq+wiBcPmuZCcltmjAgPVNtSvrnbs5yPsUiB58R 5z3jueL5boR165bNYFtFl5h4Gzq/81lva8tYW8jv+1GQlIywZ3/EC7uzhwMms0ucYQ7y tc2mAaPTwebjvvfJrV7zTeYh1RAWML+9AnHYf198bHcngDyWkC+660QWlaQyR7+3bmDg JInA== 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 3si13989951pgf.124.2018.11.06.00.39.58; Tue, 06 Nov 2018 00:40:13 -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 S1730098AbeKFSDP (ORCPT + 99 others); Tue, 6 Nov 2018 13:03:15 -0500 Received: from foss.arm.com ([217.140.101.70]:56574 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729021AbeKFSDO (ORCPT ); Tue, 6 Nov 2018 13:03:14 -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 660FB80D; Tue, 6 Nov 2018 00:39:08 -0800 (PST) Received: from salmiak (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E7BC83F5BD; Tue, 6 Nov 2018 00:39:06 -0800 (PST) Date: Tue, 6 Nov 2018 08:39:01 +0000 From: Mark Rutland To: Zhaoyang Huang Cc: 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: <20181106083901.erezwtcomiijvdrk@salmiak> References: <1541488775-29610-1-git-send-email-huangzhaoyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1541488775-29610-1-git-send-email-huangzhaoyang@gmail.com> 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 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. Thanks, Mark. > > [1] > 0xffffff80081e6b04 : adrp x0, 0xffffff8008ca8000 > 0xffffff80081e6b08 : add x0, x0, #0x5a8 > 0xffffff80081e6b0c : bl 0xffffff80081b0ca0 > 0xffffff80081e6b10 : stp x29, x30, [sp,#-64]! > 0xffffff80081e6b14 : mov x29, sp > > [2] > crash_arm64> rd ffffffc02eec3bd0 2 > ffffffc02eec3bd0: ffffffc02eec3cb0 ffffff80081e6b10 > > [3] > wrong: > [] panic+0xf0/0x24c > [] access_remote_vm+0x0/0x5c > [] do_page_fault+0x290/0x3b8 > [] do_mem_abort+0x64/0xdc > > correct: > [ffffffc02eec3bd0] panic at ffffff80081b0da4 > [ffffffc02eec3cb0] handle_mm_fault at ffffff80081e6b0c > [ffffffc02eec3d80] do_page_fault at ffffff800809d7ac > [ffffffc02eec3df0] do_mem_abort at ffffff800808156c > > Signed-off-by: Zhaoyang Huang > --- > arch/arm64/kernel/traps.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > index d399d45..7a097cc 100644 > --- a/arch/arm64/kernel/traps.c > +++ b/arch/arm64/kernel/traps.c > @@ -113,7 +113,7 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) > > if (tsk == current) { > frame.fp = (unsigned long)__builtin_frame_address(0); > - frame.pc = (unsigned long)dump_backtrace; > + frame.pc = (unsigned long)dump_backtrace + 4; > } else { > /* > * task blocked in __switch_to > @@ -130,7 +130,7 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) > do { > /* skip until specified stack frame */ > if (!skip) { > - dump_backtrace_entry(frame.pc); > + dump_backtrace_entry(frame.pc - 4); > } else if (frame.fp == regs->regs[29]) { > skip = 0; > /* > -- > 1.9.1 >