From patchwork Thu Oct 8 10:01:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 54656 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 4E17422FF4 for ; Thu, 8 Oct 2015 10:03:59 +0000 (UTC) Received: by wicb12 with SMTP id b12sf8198915wic.1 for ; Thu, 08 Oct 2015 03:03:58 -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=bPaVn7jjqZ6MUwidsvU64ILAvQsEqlIUu3/qqUdTe3E=; b=B5BGPO/ptpFreHliWpf/l3/yMUVUfE26/f05sYBSu60Ku7ne+IzkGO8hTTADnF18sr VjPNZlBop0tkTMVizX4k+0D4gLgPTeQOuaWddPMoMaC/mPtI1l46W8PeLpHGNvhITKhD Gjl5xeLrRshLZqI4Ks8/WVkwEbVXFrtsk0oZAIDuHdTTUFCpT4ZXxy+Px8tBKZ7WnAQq jr3kv7RcZjPL1yysaCB17KqUc77RYzrIemZVvLZzhh4qHb87KiyairU8EkUCWB5mSzAy SxxsQvafmcxLzpzsN1OItfTwJ4jF6UwbRf9qGPqL7dCOesI0tD0vJobcinsmBUeFrPaK wGYg== X-Gm-Message-State: ALoCoQl9uTRR2lKlgetB1mAcQszUZG+a4hTAeYqJb5G/YsKhl1GLDSyWgXd4APJh0LCv9qY6u2dQ X-Received: by 10.112.158.202 with SMTP id ww10mr1234452lbb.13.1444298638653; Thu, 08 Oct 2015 03:03:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.23.155 with SMTP id 27ls171508lfx.49.gmail; Thu, 08 Oct 2015 03:03:58 -0700 (PDT) X-Received: by 10.112.13.161 with SMTP id i1mr3116939lbc.96.1444298638484; Thu, 08 Oct 2015 03:03:58 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id o196si22631050lfb.9.2015.10.08.03.03.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 03:03:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbwt4 with SMTP id wt4so41105527lbb.1 for ; Thu, 08 Oct 2015 03:03:58 -0700 (PDT) X-Received: by 10.25.19.21 with SMTP id j21mr2128940lfi.106.1444298638353; Thu, 08 Oct 2015 03:03:58 -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 w3csp482998lbq; Thu, 8 Oct 2015 03:03:57 -0700 (PDT) X-Received: by 10.107.40.12 with SMTP id o12mr7465262ioo.84.1444298634645; Thu, 08 Oct 2015 03:03:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 103si31036489iol.12.2015.10.08.03.03.54; Thu, 08 Oct 2015 03:03:54 -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 S1755823AbbJHKDs (ORCPT + 30 others); Thu, 8 Oct 2015 06:03:48 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:35695 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753870AbbJHKDp (ORCPT ); Thu, 8 Oct 2015 06:03:45 -0400 Received: by pabve7 with SMTP id ve7so9978298pab.2 for ; Thu, 08 Oct 2015 03:03:45 -0700 (PDT) X-Received: by 10.67.22.97 with SMTP id hr1mr1724740pad.81.1444298624995; Thu, 08 Oct 2015 03:03:44 -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.03.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Oct 2015 03:03:44 -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 5/7] ftrace: allow arch-specific stack tracer Date: Thu, 8 Oct 2015 19:01:42 +0900 Message-Id: <1444298504-10392-6-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.171 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: , A stack frame may be used in a different way depending on cpu architecture. Thus it is not always appropriate to slurp the stack contents, as current check_stack() does, in order to calcurate a stack index (height) at a given function call. At least not on arm64. In addition, there is a possibility that we will mistakenly detect a stale stack frame which has not been overwritten. This patch makes check_stack() a weak function so as to later implement arch-specific version. Signed-off-by: AKASHI Takahiro --- include/linux/ftrace.h | 10 ++++++++++ kernel/trace/trace_stack.c | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index d77b195..e538400 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -270,7 +270,17 @@ static inline void ftrace_kill(void) { } #define FTRACE_STACK_FRAME_OFFSET 0 #endif +#define STACK_TRACE_ENTRIES 500 + +struct stack_trace; + +extern unsigned stack_dump_index[]; +extern struct stack_trace max_stack_trace; +extern unsigned long max_stack_size; +extern arch_spinlock_t max_stack_lock; + extern int stack_tracer_enabled; +void print_max_stack(void); int stack_trace_sysctl(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c index 30521ea..ff1a191 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c @@ -16,24 +16,22 @@ #include "trace.h" -#define STACK_TRACE_ENTRIES 500 - static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES+1] = { [0 ... (STACK_TRACE_ENTRIES)] = ULONG_MAX }; -static unsigned stack_dump_index[STACK_TRACE_ENTRIES]; +unsigned stack_dump_index[STACK_TRACE_ENTRIES]; /* * Reserve one entry for the passed in ip. This will allow * us to remove most or all of the stack size overhead * added by the stack tracer itself. */ -static struct stack_trace max_stack_trace = { +struct stack_trace max_stack_trace = { .max_entries = STACK_TRACE_ENTRIES - 1, .entries = &stack_dump_trace[0], }; -static unsigned long max_stack_size; -static arch_spinlock_t max_stack_lock = +unsigned long max_stack_size; +arch_spinlock_t max_stack_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; static DEFINE_PER_CPU(int, trace_active); @@ -42,7 +40,7 @@ static DEFINE_MUTEX(stack_sysctl_mutex); int stack_tracer_enabled; static int last_stack_tracer_enabled; -static inline void print_max_stack(void) +void print_max_stack(void) { long i; int size; @@ -65,7 +63,15 @@ static inline void print_max_stack(void) } } -static inline void +/* + * When arch-specific code overides this function, the following + * data should be filled up, assuming max_stack_lock is held to + * prevent concurrent updates. + * stack_dump_index[] + * max_stack_trace + * max_stack_size + */ +void __weak check_stack(unsigned long ip, unsigned long *stack) { unsigned long this_size, flags; unsigned long *p, *top, *start;