From patchwork Thu Oct 15 12:12:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Bin X-Patchwork-Id: 7405601 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 4A4B19F302 for ; Thu, 15 Oct 2015 12:18:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 77E8820848 for ; Thu, 15 Oct 2015 12:18:01 +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 75F132084F for ; Thu, 15 Oct 2015 12:18:00 +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 1ZmhSL-0000EC-CD; Thu, 15 Oct 2015 12:16:25 +0000 Received: from szxga03-in.huawei.com ([119.145.14.66]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmhSF-0005TK-Eq for linux-arm-kernel@lists.infradead.org; Thu, 15 Oct 2015 12:16:22 +0000 Received: from 172.24.1.47 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BOZ19057; Thu, 15 Oct 2015 20:13:18 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Thu, 15 Oct 2015 20:13:06 +0800 From: Li Bin To: Catalin Marinas , Steven Rostedt , Will Deacon , Christoffer Dall , Punit Agrawal , "Mark Rutland" Subject: [PATCH] arm64: ftrace: function_graph: dump real return addr in call trace Date: Thu, 15 Oct 2015 20:12:35 +0800 Message-ID: <1444911155-17480-1-git-send-email-huawei.libin@huawei.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-Originating-IP: [10.175.100.166] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.561F9860.0029, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: c768f4250b9688b38ff11b9faa43a3d1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151015_051620_292521_DBA171C4 X-CRM114-Status: GOOD ( 12.02 ) X-Spam-Score: -4.2 (----) 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: zhouchengming1@huawei.com, xiexiuqi@huawei.com, dingtianhong@huawei.com, linux-kernel@vger.kernel.org, huawei.libin@huawei.com, guohanjun@huawei.com, linux-arm-kernel@lists.infradead.org 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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 When using function graph tracer, the printed call trace will be as following that has many ftrace_graph_caller (return_to_handler - 4), which is been placed in the stack by ftrace_graph tracer to replace the real return address. [ 198.582568] Call trace: [ 198.583313] [] next_tgid+0x30/0x100 [ 198.584359] [] ftrace_graph_caller+0x6c/0x70 [ 198.585503] [] ftrace_graph_caller+0x6c/0x70 [ 198.586574] [] ftrace_graph_caller+0x6c/0x70 [ 198.587660] [] ftrace_graph_caller+0x6c/0x70 [ 198.588896] Code: aa0003f5 2a0103f4 b4000102 91004043 (885f7c60) [ 198.591092] ---[ end trace 6a346f8f20949ac8 ]--- This patch fix it, and dump the real return address in the call trace. Signed-off-by: Li Bin --- arch/arm64/kernel/traps.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index f93aae5..4a4e679 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -143,9 +143,38 @@ static void dump_instr(const char *lvl, struct pt_regs *regs) set_fs(fs); } +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +static void print_ftrace_graph_addr(unsigned long addr, + struct task_struct *tsk, + unsigned long sp, int *graph) +{ + unsigned long ret_addr; + int index = tsk->curr_ret_stack; + + if (addr != ((unsigned long)return_to_handler - 4)) + return; + + if (!tsk->ret_stack || index < *graph) + return; + + index -= *graph; + ret_addr = tsk->ret_stack[index].ret; + + dump_backtrace_entry(ret_addr - 4, sp); + + (*graph)++; +} +#else +static inline void print_ftrace_graph_addr(unsigned long addr, + struct task_struct *tsk, + unsigned long sp, int *graph) +{} +#endif + static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) { struct stackframe frame; + int graph = 0; pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk); @@ -177,7 +206,9 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) ret = unwind_frame(&frame); if (ret < 0) break; + dump_backtrace_entry(where, frame.sp); + print_ftrace_graph_addr(where, tsk, frame.sp, &graph); } }