From patchwork Tue Aug 4 07:44:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 51901 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id 8E881229FD for ; Tue, 4 Aug 2015 07:45:18 +0000 (UTC) Received: by lady2 with SMTP id y2sf854494lad.1 for ; Tue, 04 Aug 2015 00:45:17 -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=XnVcq2aitYrbUuHBUbR7oWpvXYsQ4OztOTyRw6uZsdk=; b=Z+rEZ51WRQO/yGKQHb9djLCaeBxsJrMoTnTw1z/9GecGkToUZ7KH5LuW3QNaUbAmpV uBptbEKBRqPCg9iLm9Ls5we2HrDXAkBVY/nkrA3VpT0yyhg+H77wT+jncoatUIDTNKkb QScLSwtr5jWtR6p1pcHw3Fnj3qohzKejDxezNhcxmb6J3uxnqBrajzA23V2kgJ8txmY7 2XdiJiK26rmYhIiWdPlMrkeoI8A3y87b5UnZxIA59N/2M/T9DMIQKPv6Za+eVGHt08J0 wLts9LBGV5HhZ3FKZKxo/7osmExhjM2ftiG86LDuF5UFTcpyrSYuRbyoeMTdZaQN9hlq A9mg== X-Gm-Message-State: ALoCoQn6h+gNw//4MytZjF9+vvNbCjL8T7XjMNGZDY0uZwOUxPf46A9uDXI0LpJH+cSUeo2i9RBP X-Received: by 10.112.125.71 with SMTP id mo7mr720273lbb.2.1438674317580; Tue, 04 Aug 2015 00:45:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.133 with SMTP id y5ls9972laj.19.gmail; Tue, 04 Aug 2015 00:45:17 -0700 (PDT) X-Received: by 10.152.28.194 with SMTP id d2mr1925105lah.122.1438674317399; Tue, 04 Aug 2015 00:45:17 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id jj4si129505lbc.66.2015.08.04.00.45.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Aug 2015 00:45:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labix3 with SMTP id ix3so1424873lab.0 for ; Tue, 04 Aug 2015 00:45:17 -0700 (PDT) X-Received: by 10.152.88.78 with SMTP id be14mr173746lab.29.1438674317297; Tue, 04 Aug 2015 00:45:17 -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.7.198 with SMTP id l6csp2266864lba; Tue, 4 Aug 2015 00:45:15 -0700 (PDT) X-Received: by 10.66.121.163 with SMTP id ll3mr5165963pab.100.1438674315055; Tue, 04 Aug 2015 00:45:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si376829pdh.146.2015.08.04.00.45.13; Tue, 04 Aug 2015 00:45:15 -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 S1755273AbbHDHpD (ORCPT + 28 others); Tue, 4 Aug 2015 03:45:03 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:34718 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755220AbbHDHo6 (ORCPT ); Tue, 4 Aug 2015 03:44:58 -0400 Received: by pawu10 with SMTP id u10so2017301paw.1 for ; Tue, 04 Aug 2015 00:44:58 -0700 (PDT) X-Received: by 10.68.169.69 with SMTP id ac5mr5123685pbc.14.1438674298524; Tue, 04 Aug 2015 00:44:58 -0700 (PDT) Received: from localhost.localdomain (61-205-6-81m5.grp1.mineo.jp. [61.205.6.81]) by smtp.googlemail.com with ESMTPSA id bd5sm287869pbb.85.2015.08.04.00.44.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Aug 2015 00:44:57 -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: [RFC v2 2/4] arm64: ftrace: add arch-specific stack tracer Date: Tue, 4 Aug 2015 16:44:07 +0900 Message-Id: <1438674249-3447-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438674249-3447-1-git-send-email-takahiro.akashi@linaro.org> References: <1438674249-3447-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.215.42 as permitted sender) smtp.mail=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: , This patch uses walk_stackframe(), instead of slurping stack contents as orignal check_stack() does, to identify each stack frame. return_to_handler() is handled in a special way because it is not a function, but invoked via function graph tracer by faking a saved lr register on stack. Signed-off-by: AKASHI Takahiro --- arch/arm64/include/asm/ftrace.h | 2 ++ arch/arm64/kernel/ftrace.c | 37 +++++++++++++++++++++++++ arch/arm64/kernel/stacktrace.c | 58 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 2b43e20..b7d597c 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -29,6 +29,8 @@ struct dyn_arch_ftrace { extern unsigned long ftrace_graph_call; +extern void return_to_handler(void); + static inline unsigned long ftrace_call_adjust(unsigned long addr) { /* diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index c851be7..d812870 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -176,3 +176,40 @@ int ftrace_disable_ftrace_graph_caller(void) } #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ + +#ifdef CONFIG_STACK_TRACER +#define stack_top(fp) (((fp) & ~(THREAD_SIZE-1)) + THREAD_SIZE) +#define stack_index(fp) (stack_top((fp)) - (fp)) + +extern struct stack_trace max_stack_trace; +extern void save_stack_trace_index(struct stack_trace *trace); + +void arch_check_stack(unsigned long ip, unsigned long *stack, + unsigned long *max_size, int *tracer_size) +{ + int i, j; + + max_stack_trace.skip = 0; + save_stack_trace_index(&max_stack_trace); + max_stack_trace.nr_entries--; /* for '-1' entry */ + + /* Skip over the overhead of the stack tracer itself */ + for (i = 0; i < max_stack_trace.nr_entries; i++) { + if ((max_stack_trace.entries[i] + FTRACE_STACK_FRAME_OFFSET) + == ip) + break; + } + + if (unlikely(!*tracer_size)) { + *tracer_size = stack_index((unsigned long)stack) + - max_stack_trace.index[i]; + *max_size -= *tracer_size; + } + + max_stack_trace.nr_entries -= i; + for (j = 0; j < max_stack_trace.nr_entries; j++) { + max_stack_trace.index[j] = max_stack_trace.index[j + i]; + max_stack_trace.entries[j] = max_stack_trace.entries[j + i]; + } +} +#endif /* CONFIG_STACK_TRACER */ diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index bc0689a..496ab0f 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -17,12 +17,15 @@ */ #include #include +#include #include #include #include #include +#define S_FRAME_SIZE sizeof(struct pt_regs) /* asm-offsets.h */ + /* * AArch64 PCS assigns the frame pointer to x29. * @@ -78,9 +81,29 @@ struct stack_trace_data { struct stack_trace *trace; unsigned int no_sched_functions; unsigned int skip; +#ifdef CONFIG_STACK_TRACER + int ftracer; + int ret_stack_index; +#endif }; -static int save_trace(struct stackframe *frame, void *d) +#ifdef CONFIG_STACK_TRACER +static void notrace arm64_stack_index(struct stackframe *frame, + struct stack_trace_data *data) +{ + struct stack_trace *trace = data->trace; + unsigned long top; + unsigned int x = trace->nr_entries; + + top = (frame->fp & ~(THREAD_SIZE-1)) + THREAD_SIZE; + trace->index[x] = top - frame->fp; + /* should not go beyond this frame */ + if (trace->index[x] == THREAD_SIZE) + trace->index[x] = 0; +} +#endif /* CONFIG_STACK_TRACER */ + +static int notrace save_trace(struct stackframe *frame, void *d) { struct stack_trace_data *data = d; struct stack_trace *trace = data->trace; @@ -93,7 +116,13 @@ static int save_trace(struct stackframe *frame, void *d) return 0; } - trace->entries[trace->nr_entries++] = addr; + trace->entries[trace->nr_entries] = addr; +#ifdef CONFIG_STACK_TRACER + if (data->ftracer) { + arm64_stack_index(frame, data); + } +#endif + trace->nr_entries++; return trace->nr_entries >= trace->max_entries; } @@ -105,6 +134,9 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) data.trace = trace; data.skip = trace->skip; +#ifdef CONFIG_STACK_TRACER + data.ftracer = 0; +#endif if (tsk != current) { data.no_sched_functions = 1; @@ -128,4 +160,26 @@ void save_stack_trace(struct stack_trace *trace) save_stack_trace_tsk(current, trace); } EXPORT_SYMBOL_GPL(save_stack_trace); + +#ifdef CONFIG_STACK_TRACER +void notrace save_stack_trace_index(struct stack_trace *trace) +{ + struct stack_trace_data data; + struct stackframe frame; + + data.trace = trace; + data.skip = trace->skip; + data.ftracer = 1; + data.ret_stack_index = current->curr_ret_stack; + + data.no_sched_functions = 0; + frame.fp = (unsigned long)__builtin_frame_address(0); + frame.sp = current_stack_pointer; + frame.pc = (unsigned long)save_stack_trace_index; + + walk_stackframe(&frame, save_trace, &data); + if (trace->nr_entries < trace->max_entries) + trace->entries[trace->nr_entries++] = ULONG_MAX; +} +#endif /* CONFIG_STACK_TRACER */ #endif