linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: takahiro.akashi@linaro.org (AKASHI Takahiro)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC 1/4] ftrace: add a helper function for livepatch
Date: Fri, 24 Apr 2015 11:44:06 +0900	[thread overview]
Message-ID: <1429843449-7388-2-git-send-email-takahiro.akashi@linaro.org> (raw)
In-Reply-To: <1429843449-7388-1-git-send-email-takahiro.akashi@linaro.org>

ftrace_lookup_mcount() will return an address of mcount call in a function.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 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

  reply	other threads:[~2015-04-24  2:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-24  2:44 [RFC 0/4] arm64: add livepatch support AKASHI Takahiro
2015-04-24  2:44 ` AKASHI Takahiro [this message]
2015-04-24  2:44 ` [RFC 2/4] livepatch: adjust a patched function's address AKASHI Takahiro
2015-04-24  2:44 ` [RFC 3/4] arm64: ftrace: add DYNAMIC_TRACE_WITH_REGS version AKASHI Takahiro
2015-04-24  2:44 ` [RFC 4/4] arm64: add livepatch support AKASHI Takahiro
2015-04-24  2:58 ` [RFC 0/4] " Steven Rostedt
2015-04-24  3:24 ` Li Bin
2015-04-24  6:05   ` Masami Hiramatsu
2015-04-24  8:04     ` AKASHI Takahiro
2015-05-28  5:40     ` Li Bin
2015-04-24  9:27 ` Jiri Kosina
2015-05-27  6:09   ` AKASHI Takahiro
2015-05-27  6:15     ` Jiri Kosina
2015-05-27  9:29     ` Masami Hiramatsu
2015-05-28  6:06   ` Li Bin
2015-05-28  6:08   ` Li Bin
2015-05-28  8:58     ` Will Deacon
2015-05-28  9:58       ` AKASHI Takahiro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429843449-7388-2-git-send-email-takahiro.akashi@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).