From patchwork Sat Oct 17 14:28:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jungseok Lee X-Patchwork-Id: 7422181 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 D20819F1B9 for ; Sat, 17 Oct 2015 14:30:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EDF2320637 for ; Sat, 17 Oct 2015 14:30:38 +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 18A20205F0 for ; Sat, 17 Oct 2015 14:30:38 +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 1ZnSTp-0008UK-GV; Sat, 17 Oct 2015 14:29:05 +0000 Received: from mail-pa0-x22a.google.com ([2607:f8b0:400e:c03::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZnSTn-0007tc-Gp for linux-arm-kernel@lists.infradead.org; Sat, 17 Oct 2015 14:29:04 +0000 Received: by pasz6 with SMTP id z6so4792807pas.1 for ; Sat, 17 Oct 2015 07:28:41 -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=G1IN7ITwJKbghSp+hyL3+ylYy5QNiwnnL0//fi6nLAA=; b=xNfeSOb/VL89On9kSm6E25g2EinX7SDZdJzOJiDuP0TxEKPKBRp7frXJFPCIFy4v8V R2kFqeVzBkM8WxzcYcxD+xv5vXm+arajC35+Dr4lsY/zGjH7hjnxsfqRxfWBKGe6qhT0 k4AVNb7V4bBNtZxOI5MYSpYPtboe01HTABrRI2m8utcQwa4Oi4KBjWcR8be+Ms4RnDJl 1LR5uGl52kcB3DQUspSCtamd/v271FvfkfFIw9iSwpI6zI0ZGXMjo5qeBK7+M5w2SFce sRyvPM/Xib7z7ZTPt0reHrnkDW4uYjakMIBT7v5DYCKYx73v4TtlfkfWwxVInxouYR/7 HBJQ== X-Received: by 10.68.93.227 with SMTP id cx3mr23210969pbb.155.1445092121844; Sat, 17 Oct 2015 07:28:41 -0700 (PDT) Received: from ip-10-185-2-34.ap-northeast-1.compute.internal (ec2-54-178-112-48.ap-northeast-1.compute.amazonaws.com. [54.178.112.48]) by smtp.gmail.com with ESMTPSA id b6sm26945408pbu.90.2015.10.17.07.28.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Oct 2015 07:28:41 -0700 (PDT) From: Jungseok Lee To: catalin.marinas@arm.com, will.deacon@arm.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3] arm64: Synchronise dump_backtrace() with perf callchain Date: Sat, 17 Oct 2015 14:28:11 +0000 Message-Id: <1445092091-12373-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-20151017_072903_610314_D2FCA576 X-CRM114-Status: GOOD ( 15.05 ) 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 symbol *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 v2: - Fixed a typo and mixed data in the commit msg 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); } }