From patchwork Fri Oct 16 14:28:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jungseok Lee X-Patchwork-Id: 7416311 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 01D0A9F1D5 for ; Fri, 16 Oct 2015 14:30:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F085720529 for ; Fri, 16 Oct 2015 14:30:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 087CC2041F for ; Fri, 16 Oct 2015 14:30:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zn60H-0006pG-6S; Fri, 16 Oct 2015 14:29:05 +0000 Received: from mail-pa0-x22f.google.com ([2607:f8b0:400e:c03::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zn608-0006cE-3j for linux-arm-kernel@lists.infradead.org; Fri, 16 Oct 2015 14:28:58 +0000 Received: by pabrc13 with SMTP id rc13so122451785pab.0 for ; Fri, 16 Oct 2015 07:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=2T3yTZ0x2KhHHdS35V9Hg44f+x1Vc4IzqWpsJ6/SvVo=; b=fDKes3ixEV6gS3ou81rrP7QCKWJIA9afaKBV8WPE6JJ2ShX6pOggvzXmmT4gKnRqh/ ni9A9RceKKniJjS6sKYuRbIzq8eiK1XX0ICrn3VUSw4uZ9qELdDWgY3+2plUIBMmhGyD tP1B3gXFC/PpU/Gj+3mrvAmKGoXTtAmtovg+eHELfPNspoHKd2UlvTROq3uvPsn8/tku h13Rd4H2GSCHP8WI449MG0NJMiXbgb+26IgJuG8p5qd4rK9ELt+iSg96RVnAu/mWddmV IU7iQwx0kFSInrZIZa2djWUaUFkBtc6s46Iveg5+oZ+ArAv4js8IC/BxL/nnYMn0hPeL BTOQ== X-Received: by 10.66.163.136 with SMTP id yi8mr16809981pab.124.1445005714070; Fri, 16 Oct 2015 07:28:34 -0700 (PDT) Received: from ip-10-166-141-172.ap-northeast-1.compute.internal (ec2-54-238-82-108.ap-northeast-1.compute.amazonaws.com. [54.238.82.108]) by smtp.gmail.com with ESMTPSA id ug4sm21756315pac.11.2015.10.16.07.28.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Oct 2015 07:28:33 -0700 (PDT) From: Jungseok Lee To: catalin.marinas@arm.com, will.deacon@arm.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] arm64: Synchronise dump_backtrace() with perf callchain Date: Fri, 16 Oct 2015 14:28:16 +0000 Message-Id: <1445005696-7887-1-git-send-email-jungseoklee85@gmail.com> X-Mailer: git-send-email 2.5.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151016_072857_101284_ADC3CAA7 X-CRM114-Status: GOOD ( 15.28 ) X-Spam-Score: -2.5 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , AKASHI Takahiro , James Morse , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Unlike perf callchain relying on walk_stackframe(), dump_backtrace() has its own backtrace logic. A major difference between them is the moment a symbol is recorded. Perf writes down a symobl *before* calling unwind_frame(), but dump_backtrace() prints it out *after* unwind_frame(). As a result, the last valid symbol cannot be hooked in case of dump_backtrace(). This patch addresses the issue as synchronising dump_backtrace() with perf callchain. A simple test and its results are as follows: - crash trigger $ sudo echo c > /proc/sysrq-trigger - current status Call trace: [] sysrq_handle_crash+0x24/0x30 [] __handle_sysrq+0x128/0x19c [] write_sysrq_trigger+0x60/0x74 [] proc_reg_write+0x84/0xc0 [] __vfs_write+0x44/0x104 [] vfs_write+0x98/0x1a8 [] SyS_write+0x50/0xb0 - with this change Call trace: [] sysrq_handle_crash+0x24/0x30 [] __handle_sysrq+0x128/0x19c [] write_sysrq_trigger+0x60/0x74 [] proc_reg_write+0x84/0xc0 [] __vfs_write+0x44/0x104 [] vfs_write+0x98/0x1a8 [] SyS_write+0x50/0xb0 [] el0_svc_naked+0x20/0x28 Note that this patch does not cover a case where MMU is disabled. The last stack frame of swapper, for example, has PC in a form of physical address. Unfortunately, a simple conversion using phys_to_virt() cannot cover all scenarios since PC is retrieved from LR - 4, not LR. It is a big tradeoff to change both head.S and unwind_frame() for only a few of symbols in *.S. Thus, this hunk does not take care of the case. Cc: AKASHI Takahiro Cc: James Morse Cc: Mark Rutland Signed-off-by: Jungseok Lee --- Changes since v1: - Added an example to the commit msg, per Will - Modified a comment. arch/arm64/kernel/traps.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index f93aae5..e9b9b53 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -103,12 +103,12 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom, set_fs(fs); } -static void dump_backtrace_entry(unsigned long where, unsigned long stack) +static void dump_backtrace_entry(unsigned long where) { + /* + * Note that 'where' can have a physical address, but it's not handled. + */ print_ip_sym(where); - if (in_exception_text(where)) - dump_mem("", "Exception stack", stack, - stack + sizeof(struct pt_regs), false); } static void dump_instr(const char *lvl, struct pt_regs *regs) @@ -172,12 +172,17 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) pr_emerg("Call trace:\n"); while (1) { unsigned long where = frame.pc; + unsigned long stack; int ret; + dump_backtrace_entry(where); ret = unwind_frame(&frame); if (ret < 0) break; - dump_backtrace_entry(where, frame.sp); + stack = frame.sp; + if (in_exception_text(where)) + dump_mem("", "Exception stack", stack, + stack + sizeof(struct pt_regs), false); } }