From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756383AbaFYLHV (ORCPT ); Wed, 25 Jun 2014 07:07:21 -0400 Received: from ip4-83-240-18-248.cust.nbox.cz ([83.240.18.248]:41074 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752843AbaFYLHQ (ORCPT ); Wed, 25 Jun 2014 07:07:16 -0400 From: Jiri Slaby To: linux-kernel@vger.kernel.org Cc: tj@kernel.org, rostedt@goodmis.org, mingo@redhat.com, akpm@linux-foundation.org, andi@firstfloor.org, paulmck@linux.vnet.ibm.com, pavel@ucw.cz, jirislaby@gmail.com, Vojtech Pavlik , Michael Matz , Jiri Kosina , Jiri Slaby , Frederic Weisbecker Subject: [PATCH -repost 01/21] ftrace: Add function to find fentry of function Date: Wed, 25 Jun 2014 13:06:55 +0200 Message-Id: <1403694435-3180-1-git-send-email-jslaby@suse.cz> X-Mailer: git-send-email 2.0.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is needed for kGraft to find a fentry location to be "ftraced". We use this to find a place where to jump to a new/old code location. Note that we use a O(n) algorithm to assert correctness (and simplicity). This algorithm can be further optimized to be O(log(n)) using binary search, but care has to be taken about the first member of each entries page. I.e. we cannot use 1:1 what is in ftrace_location_range etc. Signed-off-by: Jiri Slaby Cc: Steven Rostedt Cc: Frederic Weisbecker Cc: Ingo Molnar --- include/linux/ftrace.h | 1 + kernel/trace/ftrace.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 404a686a3644..c142816c2801 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -295,6 +295,7 @@ extern void unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops); extern void unregister_ftrace_function_probe_all(char *glob); +extern unsigned long ftrace_function_to_fentry(unsigned long addr); extern int ftrace_text_reserved(const void *start, const void *end); extern int ftrace_nr_registered_ops(void); diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 5b372e3ed675..f4da441c0125 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1422,6 +1422,36 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs) } \ } +/** + * ftrace_function_to_fentry -- lookup fentry location for a function + * @addr: function address to find a fentry in + * + * Perform a lookup in a list of fentry callsites to find one that fits a + * specified function @addr. It returns the corresponding fentry callsite or + * zero on failure. + */ +unsigned long ftrace_function_to_fentry(unsigned long addr) +{ + const struct dyn_ftrace *rec; + const struct ftrace_page *pg; + unsigned long ret = 0; + + mutex_lock(&ftrace_lock); + do_for_each_ftrace_rec(pg, rec) { + unsigned long off; + + if (!kallsyms_lookup_size_offset(rec->ip, NULL, &off)) + continue; + if (addr + off == rec->ip) { + ret = rec->ip; + goto end; + } + } while_for_each_ftrace_rec() +end: + mutex_unlock(&ftrace_lock); + + return ret; +} static int ftrace_cmp_recs(const void *a, const void *b) { -- 2.0.0