From patchwork Thu Oct 8 10:01:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 54652 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 06FC922FF4 for ; Thu, 8 Oct 2015 10:03:13 +0000 (UTC) Received: by lbwr8 with SMTP id r8sf21148137lbw.0 for ; Thu, 08 Oct 2015 03:03:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=ogTNwjsZSTKn2zMxMRcYYz6cKIAH8s+VgZh1j3emw5A=; b=clh4w4sHVM4c19dusQ4ije7BTkfgmQ/M18xjKJp0xIV66hq23sl0PGx641cGE6g/wA Zcg04VLLLJXi4iNg9C0UpZfSh6bwnAXZKJ9YpZdtD62QSPdCPBtjpNkF7qgZ8XXsCdNL OMqcce1KueF0eJJPsJMvIM1qRR/jcISdmS2VXLS4k7hUScikcIXPNNx8ad9mYRT3+JZp CA0gGxQdxxLI3fE3aBHu9oIck2fKlq1/0ehNwxTsZb+QJ3LZAZsbrQjfNQPxljU7V1gC ELoBAYf0k8c2g0t1C7yW3YVwFSCBu0ovcBlAP12z0Dq8lxiEgIjchj9fbuQErfKR3NEY IsRg== X-Gm-Message-State: ALoCoQlHwhd/Ibc8l8Va2qZyMSn0ST7hx72qzIi3t1pa+SyS4IDYxjNEFnHo5weFn/f69BTbuGqC X-Received: by 10.180.210.71 with SMTP id ms7mr525915wic.4.1444298591633; Thu, 08 Oct 2015 03:03:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.210.198 with SMTP id j189ls151600lfg.86.gmail; Thu, 08 Oct 2015 03:03:11 -0700 (PDT) X-Received: by 10.25.143.73 with SMTP id r70mr2100201lfd.108.1444298591442; Thu, 08 Oct 2015 03:03:11 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id kw4si28030675lbc.9.2015.10.08.03.03.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 03:03:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbwt4 with SMTP id wt4so41082825lbb.1 for ; Thu, 08 Oct 2015 03:03:11 -0700 (PDT) X-Received: by 10.25.86.213 with SMTP id k204mr2067084lfb.36.1444298591276; Thu, 08 Oct 2015 03:03:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp482564lbq; Thu, 8 Oct 2015 03:03:10 -0700 (PDT) X-Received: by 10.107.137.144 with SMTP id t16mr7563746ioi.102.1444298590098; Thu, 08 Oct 2015 03:03:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g79si31036084ioi.68.2015.10.08.03.03.09; Thu, 08 Oct 2015 03:03:10 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754668AbbJHKDH (ORCPT + 30 others); Thu, 8 Oct 2015 06:03:07 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:34924 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753349AbbJHKDF (ORCPT ); Thu, 8 Oct 2015 06:03:05 -0400 Received: by pabve7 with SMTP id ve7so9961143pab.2 for ; Thu, 08 Oct 2015 03:03:05 -0700 (PDT) X-Received: by 10.66.101.106 with SMTP id ff10mr7374505pab.100.1444298584953; Thu, 08 Oct 2015 03:03:04 -0700 (PDT) Received: from localhost.localdomain (61-205-1-208m5.grp1.mineo.jp. [61.205.1.208]) by smtp.googlemail.com with ESMTPSA id ya10sm44431428pbc.69.2015.10.08.03.02.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Oct 2015 03:03:03 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, rostedt@goodmis.org Cc: jungseoklee85@gmail.com, olof@lixom.net, broonie@kernel.org, david.griego@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 1/7] arm64: ftrace: adjust callsite addresses examined by stack tracer Date: Thu, 8 Oct 2015 19:01:38 +0900 Message-Id: <1444298504-10392-2-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444298504-10392-1-git-send-email-takahiro.akashi@linaro.org> References: <1444298504-10392-1-git-send-email-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: takahiro.akashi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On arm64, no PC values returned by save_stack_trace() will match to LR values saved in stack frames on a stack after the following commit: commit e306dfd06fcb ("ARM64: unwind: Fix PC calculation") As a result, the output from stack tracer will be messed up. This patch introduces an arch-defined macro, FTRACE_STACK_FRAME_OFFSET, so that check_stack() can handle this case correctly. Signed-off-by: AKASHI Takahiro Acked-by: Jungseok Lee --- arch/arm64/include/asm/ftrace.h | 5 +++-- arch/arm64/kernel/stacktrace.c | 7 ++++--- include/linux/ftrace.h | 7 +++++++ kernel/trace/trace_stack.c | 5 +++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index c5534fa..2b43e20 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -13,8 +13,9 @@ #include -#define MCOUNT_ADDR ((unsigned long)_mcount) -#define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE +#define MCOUNT_ADDR ((unsigned long)_mcount) +#define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE +#define FTRACE_STACK_FRAME_OFFSET AARCH64_INSN_SIZE #ifndef __ASSEMBLY__ #include diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 407991b..bc0689a 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -20,6 +20,7 @@ #include #include +#include #include /* @@ -49,10 +50,10 @@ int notrace unwind_frame(struct stackframe *frame) frame->sp = fp + 0x10; frame->fp = *(unsigned long *)(fp); /* - * -4 here because we care about the PC at time of bl, - * not where the return will go. + * decrement PC by AARCH64_INSN_SIZE here because we care about + * the PC at time of bl, not where the return will go. */ - frame->pc = *(unsigned long *)(fp + 8) - 4; + frame->pc = *(unsigned long *)(fp + 8) - AARCH64_INSN_SIZE; return 0; } diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 6cd8c0e..d77b195 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -263,6 +263,13 @@ static inline void ftrace_kill(void) { } #endif /* CONFIG_FUNCTION_TRACER */ #ifdef CONFIG_STACK_TRACER +/* + * the offset value to add to return address from save_stack_trace() + */ +#ifndef FTRACE_STACK_FRAME_OFFSET +#define FTRACE_STACK_FRAME_OFFSET 0 +#endif + extern int stack_tracer_enabled; int stack_trace_sysctl(struct ctl_table *table, int write, diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c index b746399..30521ea 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c @@ -105,7 +105,7 @@ check_stack(unsigned long ip, unsigned long *stack) /* Skip over the overhead of the stack tracer itself */ for (i = 0; i < max_stack_trace.nr_entries; i++) { - if (stack_dump_trace[i] == ip) + if ((stack_dump_trace[i] + FTRACE_STACK_FRAME_OFFSET) == ip) break; } @@ -133,7 +133,8 @@ check_stack(unsigned long ip, unsigned long *stack) for (; p < top && i < max_stack_trace.nr_entries; p++) { if (stack_dump_trace[i] == ULONG_MAX) break; - if (*p == stack_dump_trace[i]) { + if (*p == (stack_dump_trace[i] + + FTRACE_STACK_FRAME_OFFSET)) { stack_dump_trace[x] = stack_dump_trace[i++]; this_size = stack_dump_index[x++] = (top - p) * sizeof(unsigned long);