From patchwork Fri Feb 28 05:18:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 25506 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 727DD2055D for ; Fri, 28 Feb 2014 05:20:01 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id e16sf522252qcx.2 for ; Thu, 27 Feb 2014 21:20:01 -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=lV/ZpjSX30UxOKvnukn+3oghwYqLJp6GD1Ei2hXlpWoDGp5CJFXLu2VbicM92W4qIC I0Y0JBPJJr0ErlhKCYG9Np3oS6gAF/P7VhEpEdxQYEvawxG2A5oNaqOWNDhGzpYsVsjI +ApoeiVmLsZ31W7dAdB9kpdrSHRkQCGGsWDVgOCJjsW++0AYfU6XY86f66Da2ydCQvR5 cNYu5NyLJ+ZkWSZJisZ++ksXHPHmI7D8xKoUNhYyORhWIFR6bdlFFl2AeC6xQ79tAR5s 9VrE7mfVFZ5Nps3SnbpzOvGhZY977BA4UuzyiXIX+1eisO/1tsIJNX51lvUDR9jmYL1f zggw== X-Gm-Message-State: ALoCoQmKcUl7alcpppsYi99qwrzdKdL89s0Ok9ME+GSm4/dMC41inx4Tt395Cjga63Md7ZHHFTpr X-Received: by 10.236.149.137 with SMTP id x9mr352784yhj.54.1393564801056; Thu, 27 Feb 2014 21:20:01 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.7 with SMTP id o7ls998933qgo.15.gmail; Thu, 27 Feb 2014 21:20:01 -0800 (PST) X-Received: by 10.58.59.100 with SMTP id y4mr862952veq.4.1393564800987; Thu, 27 Feb 2014 21:20:00 -0800 (PST) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id rl1si1182435vcb.74.2014.02.27.21.20.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 21:20:00 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.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.220.178; Received: by mail-vc0-f178.google.com with SMTP id ik5so234025vcb.23 for ; Thu, 27 Feb 2014 21:20:00 -0800 (PST) X-Received: by 10.52.89.230 with SMTP id br6mr12084856vdb.20.1393564800865; Thu, 27 Feb 2014 21:20:00 -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.130.193 with SMTP id u1csp28922vcs; Thu, 27 Feb 2014 21:20:00 -0800 (PST) X-Received: by 10.68.29.72 with SMTP id i8mr1265539pbh.116.1393564799904; Thu, 27 Feb 2014 21:19:59 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si599197pbl.298.2014.02.27.21.19.59; Thu, 27 Feb 2014 21:19:59 -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 S1752028AbaB1FTw (ORCPT + 26 others); Fri, 28 Feb 2014 00:19:52 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:35975 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750835AbaB1FTt (ORCPT ); Fri, 28 Feb 2014 00:19:49 -0500 Received: by mail-pa0-f54.google.com with SMTP id fa1so273267pad.27 for ; Thu, 27 Feb 2014 21:19:48 -0800 (PST) X-Received: by 10.66.136.103 with SMTP id pz7mr1246890pab.140.1393564788799; Thu, 27 Feb 2014 21:19:48 -0800 (PST) Received: from localhost.localdomain (KD182249084248.au-net.ne.jp. [182.249.84.248]) by mx.google.com with ESMTPSA id vn10sm1790978pbc.21.2014.02.27.21.19.35 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 21:19:47 -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 v5 3/7] arm64: ftrace: Add CALLER_ADDRx macros Date: Fri, 28 Feb 2014 14:18:40 +0900 Message-Id: <1393564724-3966-4-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393564724-3966-1-git-send-email-takahiro.akashi@linaro.org> References: <1393320196-2942-1-git-send-email-takahiro.akashi@linaro.org> <1393564724-3966-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.220.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);