From patchwork Tue Feb 25 09:23:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 25257 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F47A20558 for ; Tue, 25 Feb 2014 09:24:54 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id oz11sf188399veb.4 for ; Tue, 25 Feb 2014 01:24:54 -0800 (PST) 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=LNyqKEKi9T0ud8LYBwXGkLZRXBXIkxMP+ForqN4jMxo=; b=ga4utKXn5nPh4p0ej3HrO26qBEQ2Sz/5T/ZxoA1Qbh+YNmWrY7jHy8W4mUfxOI9+x9 uuBRxLKgKEvwPcml3Jiaa7vkU6h65uRjyLzb0msYbKhEdwmM26jrwmn7AZBw7widct1B 3quIuHP2FxUducCw+Sapb1qQJfL9KOWVgq0gd4jJ0sxuQN6i/aR+wc+xAKQxNUVlMj6z SOvsvSdabl5BbU+NGkEKEQg+iWmvXhRCcQ6PP5BZMYFObrpZfYkRemfbEFMn8+zWYz+Y dSfcUpWj5TqmvKRhuo99VWV/DioIA60wv/ZWozEbLGba7ukAXTpZdTs1kbFGICCENOhg 552g== X-Gm-Message-State: ALoCoQnbaRoc34ICVN2Bnq+oWvB6DChoSCevBpIJhS9kJzq4YnuQ644+w9If6VGHhIej9JAuXwKx X-Received: by 10.236.26.209 with SMTP id c57mr1569209yha.9.1393320294087; Tue, 25 Feb 2014 01:24:54 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.100 with SMTP id i91ls332886qgf.23.gmail; Tue, 25 Feb 2014 01:24:53 -0800 (PST) X-Received: by 10.52.243.102 with SMTP id wx6mr146143vdc.12.1393320293835; Tue, 25 Feb 2014 01:24:53 -0800 (PST) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id f5si6651452vej.149.2014.02.25.01.24.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 01:24:53 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id jy13so115524veb.23 for ; Tue, 25 Feb 2014 01:24:53 -0800 (PST) X-Received: by 10.52.157.8 with SMTP id wi8mr141770vdb.46.1393320293745; Tue, 25 Feb 2014 01:24:53 -0800 (PST) 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.174.196 with SMTP id u4csp123927vcz; Tue, 25 Feb 2014 01:24:53 -0800 (PST) X-Received: by 10.66.8.131 with SMTP id r3mr486140paa.7.1393320281778; Tue, 25 Feb 2014 01:24:41 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id uc9si20058444pac.239.2014.02.25.01.24.40; Tue, 25 Feb 2014 01:24:41 -0800 (PST) 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 S1753219AbaBYJYZ (ORCPT + 26 others); Tue, 25 Feb 2014 04:24:25 -0500 Received: from mail-pd0-f170.google.com ([209.85.192.170]:40853 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752318AbaBYJYS (ORCPT ); Tue, 25 Feb 2014 04:24:18 -0500 Received: by mail-pd0-f170.google.com with SMTP id y10so4338377pdj.1 for ; Tue, 25 Feb 2014 01:24:18 -0800 (PST) X-Received: by 10.66.9.41 with SMTP id w9mr456192paa.39.1393320258501; Tue, 25 Feb 2014 01:24:18 -0800 (PST) Received: from localhost.localdomain (KD182249093189.au-net.ne.jp. [182.249.93.189]) by mx.google.com with ESMTPSA id iq10sm8497678pbc.14.2014.02.25.01.24.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 01:24:17 -0800 (PST) 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 v4 3/7] arm64: ftrace: Add CALLER_ADDRx macros Date: Tue, 25 Feb 2014 18:23:12 +0900 Message-Id: <1393320196-2942-4-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393320196-2942-1-git-send-email-takahiro.akashi@linaro.org> References: <1391768336-5642-1-git-send-email-takahiro.akashi@linaro.org> <1393320196-2942-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: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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. Please note that this implementation assumes that we have frame pointers. (which means kernel should be compiled with -fno-omit-frame-pointer.) Signed-off-by: AKASHI Takahiro --- arch/arm64/include/asm/ftrace.h | 14 +++++++++ arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/return_address.c | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) 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..f93da72 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -35,4 +35,18 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) } #endif /* __ASSEMBLY__ */ +#ifndef __ASSEMBLY__ +#define HAVE_ARCH_CALLER_ADDR + +extern void *return_address(unsigned int); + +#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) +#define CALLER_ADDR1 ((unsigned long)return_address(1)) +#define CALLER_ADDR2 ((unsigned long)return_address(2)) +#define CALLER_ADDR3 ((unsigned long)return_address(3)) +#define CALLER_ADDR4 ((unsigned long)return_address(4)) +#define CALLER_ADDR5 ((unsigned long)return_address(5)) +#define CALLER_ADDR6 ((unsigned long)return_address(6)) +#endif /* ifndef __ASSEMBLY__ */ + #endif /* __ASM_FTRACE_H */ diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index ac67fd0..b5bfa7f 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);