From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH 6/9][RFC] kprobes: Allow probe on ftrace reserved text (but move it)
Date: Wed, 02 May 2012 15:24:24 -0400 [thread overview]
Message-ID: <20120502193237.321234712@goodmis.org> (raw)
In-Reply-To: <20120502192418.024103772@goodmis.org>
[-- Attachment #1: 0006-kprobes-Allow-probe-on-ftrace-reserved-text-but-move.patch --]
[-- Type: text/plain, Size: 3034 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
If a probe is placed on a ftrace nop (or ftrace_caller), simply move the
probe to the next instruction instead of rejecting it. This will allow
kprobes not to be affected by ftrace using the -mfentry gcc option which
will put the ftrace nop at the beginning of the function. As a very common
case for kprobes is to add a probe to the very beginning of a function
we need a way to handle the case when ftrace takes the first instruction.
Added KPROBE_FLAG_MOVED (as suggested by Masami) that is set when the address
is moved to get around an ftrace nop.
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
include/linux/ftrace.h | 2 ++
include/linux/kprobes.h | 1 +
kernel/kprobes.c | 13 ++++++++++++-
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 9310993..211ae45 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -414,6 +414,8 @@ static inline int ftrace_text_reserved(void *start, void *end)
#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
#define ftrace_free_filter(ops) do { } while (0)
+static inline unsigned long ftrace_location(unsigned long ip) { return 0; }
+
static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
size_t cnt, loff_t *ppos) { return -ENODEV; }
static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index b6e1f8c..23cf41e 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -128,6 +128,7 @@ struct kprobe {
* NOTE:
* this flag is only for optimized_kprobe.
*/
+#define KPROBE_FLAG_MOVED 8 /* probe was moved passed ftrace nop */
/* Has this kprobe gone ? */
static inline int kprobe_gone(struct kprobe *p)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index c62b854..952619b 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1319,10 +1319,22 @@ int __kprobes register_kprobe(struct kprobe *p)
struct kprobe *old_p;
struct module *probed_mod;
kprobe_opcode_t *addr;
+ unsigned long ftrace_addr;
addr = kprobe_addr(p);
if (IS_ERR(addr))
return PTR_ERR(addr);
+
+ /*
+ * If the address is located on a ftrace nop, set the
+ * breakpoint to the following instruction.
+ */
+ ftrace_addr = ftrace_location((unsigned long)addr);
+ if (unlikely(ftrace_addr)) {
+ addr = (kprobe_opcode_t *)(ftrace_addr + MCOUNT_INSN_SIZE);
+ p->flags |= KPROBE_FLAG_MOVED;
+ }
+
p->addr = addr;
ret = check_kprobe_rereg(p);
@@ -1333,7 +1345,6 @@ int __kprobes register_kprobe(struct kprobe *p)
preempt_disable();
if (!kernel_text_address((unsigned long) p->addr) ||
in_kprobes_functions((unsigned long) p->addr) ||
- ftrace_text_reserved(p->addr, p->addr) ||
jump_label_text_reserved(p->addr, p->addr)) {
ret = -EINVAL;
goto cannot_probe;
--
1.7.9.5
next prev parent reply other threads:[~2012-05-02 19:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-02 19:24 [PATCH 0/9][RFC] ftrace: ftrace location lookup speedup, and clean ups Steven Rostedt
2012-05-02 19:24 ` [PATCH 1/9][RFC] ftrace: Sort all function addresses, not just per page Steven Rostedt
2012-05-02 19:24 ` [PATCH 2/9][RFC] ftrace: Remove extra helper functions Steven Rostedt
2012-05-02 19:24 ` [PATCH 3/9][RFC] ftrace: Speed up search by skipping pages by address Steven Rostedt
2012-05-02 19:24 ` [PATCH 4/9][RFC] ftrace: Consolidate ftrace_location() and ftrace_text_reserved() Steven Rostedt
2012-05-02 19:24 ` [PATCH 5/9][RFC] ftrace: Return record ip addr for ftrace_location() Steven Rostedt
2012-05-02 19:24 ` Steven Rostedt [this message]
2012-05-02 20:40 ` [PATCH 6/9][RFC] kprobes: Allow probe on ftrace reserved text (but move it) Frank Ch. Eigler
2012-05-02 23:40 ` Steven Rostedt
2012-05-07 11:37 ` Masami Hiramatsu
2012-05-07 11:59 ` Masami Hiramatsu
2012-05-07 12:44 ` Steven Rostedt
2012-05-07 12:51 ` Steven Rostedt
2012-05-07 12:43 ` Steven Rostedt
2012-05-08 3:08 ` Masami Hiramatsu
2012-05-08 13:04 ` Steven Rostedt
2012-05-09 5:53 ` Masami Hiramatsu
2012-05-09 8:12 ` Masami Hiramatsu
2012-05-09 9:02 ` Masami Hiramatsu
2012-05-09 14:50 ` Steven Rostedt
2012-05-10 11:54 ` [RFC PATCH -tip ] x86/kprobes: kprobes call optimization Masami Hiramatsu
2012-05-11 8:29 ` Masami Hiramatsu
2012-05-02 19:24 ` [PATCH 7/9][RFC] ftrace: Make ftrace_modify_all_code() global for archs to use Steven Rostedt
2012-05-02 19:24 ` [PATCH 8/9][RFC] ftrace/x86: Have x86 ftrace use the ftrace_modify_all_code() Steven Rostedt
2012-05-02 19:24 ` [PATCH 9/9][RFC] ftrace: Remove selecting FRAME_POINTER with FUNCTION_TRACER Steven Rostedt
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=20120502193237.321234712@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@elte.hu \
/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
all inboxes | Powered by JetHome®