From patchwork Wed Apr 30 09:54:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 29400 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8BFE7203F3 for ; Wed, 30 Apr 2014 09:56:55 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wn1sf7670715obc.5 for ; Wed, 30 Apr 2014 02:56:55 -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=uU5JKAzhsOKeRYSyr31lcoUHF8hNHC5eKKJWIHF/vGw=; b=TqdBYyZwZ0geR7iZfg6JWB58lSkiHWhRt45HXQqwsXlRxAB0WPf8DBvywN7l6Bq3XM mZlWqM9pa8sIWRO75oDW6OdMUIpJ/ZHYz9z2GASvx0Q2O/9/2mwKqZwCUAkQUqDJ0ZyH lmbiGyll7MTZsIJDBDKJHPh1VaAFD8DXEaObI/m8bC9Vt3xHUDOZ9jqFbjiQ0UJnQSiH 7zL7RVkmHVIPGZ99HsN+ShOcE9QluR8mMbLKglZcH7BoyTtWr0XF7wt4ocsaFWJVC63R ilfWQHynVwuyyQY0GbN4E8WhOUvBCUU6ZgoChN9I8VX+T0+0dhips867yqa0ruWFXC3I QwtQ== X-Gm-Message-State: ALoCoQlW13Gh+uHD53/RPfMt3300ZLEvnba1bAbVxfvruAtmQ7Bf0gb6wojzYzIOD9TIMWEoqt9F X-Received: by 10.182.241.9 with SMTP id we9mr1876588obc.22.1398851815147; Wed, 30 Apr 2014 02:56:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.180 with SMTP id w49ls512375qge.3.gmail; Wed, 30 Apr 2014 02:56:55 -0700 (PDT) X-Received: by 10.52.37.196 with SMTP id a4mr2590270vdk.33.1398851814991; Wed, 30 Apr 2014 02:56:54 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id cb3si5192374vdc.203.2014.04.30.02.56.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 02:56:54 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lh4so1837596vcb.20 for ; Wed, 30 Apr 2014 02:56:54 -0700 (PDT) X-Received: by 10.220.105.130 with SMTP id t2mr3169816vco.18.1398851814915; Wed, 30 Apr 2014 02:56:54 -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.220.221.72 with SMTP id ib8csp265360vcb; Wed, 30 Apr 2014 02:56:54 -0700 (PDT) X-Received: by 10.67.14.231 with SMTP id fj7mr6565568pad.115.1398851814121; Wed, 30 Apr 2014 02:56:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wg2si16391335pab.44.2014.04.30.02.56.53 for ; Wed, 30 Apr 2014 02:56:53 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964844AbaD3J4m (ORCPT + 28 others); Wed, 30 Apr 2014 05:56:42 -0400 Received: from mail-ie0-f181.google.com ([209.85.223.181]:39442 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964815AbaD3J4i (ORCPT ); Wed, 30 Apr 2014 05:56:38 -0400 Received: by mail-ie0-f181.google.com with SMTP id y20so1651990ier.12 for ; Wed, 30 Apr 2014 02:56:37 -0700 (PDT) X-Received: by 10.42.58.130 with SMTP id i2mr1055940ich.66.1398851796645; Wed, 30 Apr 2014 02:56:36 -0700 (PDT) Received: from localhost.localdomain (KD182249095136.au-net.ne.jp. [182.249.95.136]) by mx.google.com with ESMTPSA id x7sm1867848igw.1.2014.04.30.02.56.31 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 02:56:35 -0700 (PDT) From: AKASHI Takahiro To: rostedt@goodmis.org, fweisbec@gmail.com, mingo@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com, tim.bird@sonymobile.com Cc: gkulkarni@caviumnetworks.com, dsaxena@linaro.org, arndb@arndb.de, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v8 7/8] arm64: ftrace: Add CALLER_ADDRx macros Date: Wed, 30 Apr 2014 18:54:35 +0900 Message-Id: <1398851676-16389-8-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398851676-16389-1-git-send-email-takahiro.akashi@linaro.org> References: <1394862048-28758-1-git-send-email-takahiro.akashi@linaro.org> <1398851676-16389-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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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: , CALLER_ADDRx returns caller's address at specified level in call stacks. They are used for several tracers like irqsoff and preemptoff. Strange to say, however, they are refered even without FTRACE. Signed-off-by: AKASHI Takahiro --- arch/arm64/include/asm/ftrace.h | 5 +++- arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/return_address.c | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/kernel/return_address.c diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index ed5c448..41e8670 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -18,6 +18,7 @@ #ifndef __ASSEMBLY__ extern void _mcount(unsigned long); +extern void *return_address(unsigned int); struct dyn_arch_ftrace { /* No extra data needed for arm64 */ @@ -33,6 +34,8 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) */ return addr; } -#endif /* __ASSEMBLY__ */ + +#define ftrace_return_address(n) return_address(n) +#endif /* ifndef __ASSEMBLY__ */ #endif /* __ASM_FTRACE_H */ diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 1ebcb4c..1f4d891 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -7,12 +7,13 @@ AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_insn.o = -pg +CFLAGS_REMOVE_return_address.o = -pg # Object file lists. arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \ entry-fpsimd.o process.o ptrace.o setup.o signal.o \ sys.o stacktrace.o time.o traps.o io.o vdso.o \ - hyp-stub.o psci.o cpu_ops.o insn.o + hyp-stub.o psci.o cpu_ops.o insn.o return_address.o arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ sys_compat.o diff --git a/arch/arm64/kernel/return_address.c b/arch/arm64/kernel/return_address.c new file mode 100644 index 0000000..89102a6 --- /dev/null +++ b/arch/arm64/kernel/return_address.c @@ -0,0 +1,55 @@ +/* + * arch/arm64/kernel/return_address.c + * + * Copyright (C) 2013 Linaro Limited + * Author: AKASHI Takahiro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include + +#include + +struct return_address_data { + unsigned int level; + void *addr; +}; + +static int save_return_addr(struct stackframe *frame, void *d) +{ + struct return_address_data *data = d; + + if (!data->level) { + data->addr = (void *)frame->pc; + return 1; + } else { + --data->level; + return 0; + } +} + +void *return_address(unsigned int level) +{ + struct return_address_data data; + struct stackframe frame; + register unsigned long current_sp asm ("sp"); + + data.level = level + 2; + data.addr = NULL; + + frame.fp = (unsigned long)__builtin_frame_address(0); + frame.sp = current_sp; + frame.pc = (unsigned long)return_address; /* dummy */ + + walk_stackframe(&frame, save_return_addr, &data); + + if (!data.level) + return data.addr; + else + return NULL; +} +EXPORT_SYMBOL_GPL(return_address);