Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbbDXCpB (ORCPT ); Thu, 23 Apr 2015 22:45:01 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:34221 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753955AbbDXCoz (ORCPT ); Thu, 23 Apr 2015 22:44:55 -0400 From: AKASHI Takahiro To: rostedt@goodmis.org, mingo@kernel.org, jpoimboe@redhat.com, sjenning@redhat.com, jkosina@suse.cz, vojtech@suse.cz, catalin.marinas@arm.com, will.deacon@arm.com Cc: broonie@kernel.org, masami.hiramatsu.pt@hitachi.com, live-patching@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [RFC 1/4] ftrace: add a helper function for livepatch Date: Fri, 24 Apr 2015 11:44:06 +0900 Message-Id: <1429843449-7388-2-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429843449-7388-1-git-send-email-takahiro.akashi@linaro.org> References: <1429843449-7388-1-git-send-email-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1853 Lines: 66 ftrace_lookup_mcount() will return an address of mcount call in a function. Signed-off-by: AKASHI Takahiro --- include/linux/ftrace.h | 2 ++ kernel/trace/ftrace.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 1da6029..1d0271f 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -699,6 +699,8 @@ static inline void __ftrace_enabled_restore(int enabled) # define trace_preempt_off(a0, a1) do { } while (0) #endif +extern unsigned long ftrace_lookup_mcount(unsigned long addr); + #ifdef CONFIG_FTRACE_MCOUNT_RECORD extern void ftrace_init(void); #else diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 4f22802..fcfb04f 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4857,6 +4857,32 @@ static int ftrace_process_locs(struct module *mod, return ret; } +unsigned long ftrace_lookup_mcount(unsigned long addr) +{ + struct ftrace_page *pg; + struct dyn_ftrace *rec; + char str[KSYM_SYMBOL_LEN]; + char *modname; + const char *name; + unsigned long mcount = 0; + unsigned long offset; + + mutex_lock(&ftrace_lock); + + do_for_each_ftrace_rec(pg, rec) { + name = kallsyms_lookup(rec->ip, NULL, &offset, &modname, str); + if (name && rec->ip == (addr + offset)) { + mcount = rec->ip; + goto out_unlock; + } + } while_for_each_ftrace_rec(); + + out_unlock: + mutex_unlock(&ftrace_lock); + + return mcount; +} + #ifdef CONFIG_MODULES #define next_to_ftrace_page(p) container_of(p, struct ftrace_page, next) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/