[RFC PATCH tracing/kprobes] kprobes: Call vmalloc_sync_all() for avoiding in-kernel paging on kprobes

Masami Hiramatsu
2009-09-08T16:53:34Z

Call vmalloc_sync_all() before registering new kprobes and using new
instruction buffers to sync page table entries of the pages on where
kprobes data structure and instruction buffers are.
With this patch, kprobes can avoid in-kernel on-demand paging on these
kprobes, and it allows kprobes to put probes on page-fault path.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
---

kernel/kprobes.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 00d01b0..7cc8266 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -44,6 +44,7 @@
#include <linux/debugfs.h>
#include <linux/kdebug.h>
#include <linux/memory.h>
+#include <linux/vmalloc.h>

#include <asm-generic/sections.h>
#include <asm/cacheflush.h>
@@ -191,6 +192,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void)
kfree(kip);
return NULL;
}
+ vmalloc_sync_all(); /* Prohibit on-demand kernel paging on kprobe */
INIT_LIST_HEAD(&kip->list);
list_add(&kip->list, &kprobe_insn_pages);
memset(kip->slot_used, SLOT_CLEAN, INSNS_PER_PAGE);
@@ -724,6 +726,7 @@ int __kprobes register_kprobe(struct kprobe *p)
}
preempt_enable();

+ vmalloc_sync_all(); /* Prohibit on-demand kernel paging on kprobe */
p->nmissed = 0;
INIT_LIST_HEAD(&p->list);
mutex_lock(&kprobe_mutex);

--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com