This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC -mm][PATCH ] Patch to avoid probing __init functions using kprobes


On Thursday 13 Dec 2007 1:53:26 pm Ananth N Mavinakayanahalli wrote:
> On Thu, Dec 13, 2007 at 01:47:50PM +0530, Srinivasa Ds wrote:
> > Ananth N Mavinakayanahalli wrote:
> > >On Wed, Dec 12, 2007 at 08:21:01PM -0500, Masami Hiramatsu wrote:
> > >>Masami Hiramatsu wrote:
> > >>>Finally, I reproduced it by executing a command below:
> > >>>% stap -e 'probe kernel.function("migration_init"){}'
> > >
> > >That does seem like the right thing to do. This also needs to live in
> > >common code.
> > >
> > >Srini,
> > >Want to take a stab at it?
> >

This patch taken against the 2.6.24-rc4-mm1 fixes the problem 
of probing __init functions.I have reused the code from extable.c
and modified the kprobes.c accordingly.

Since we are checking __init functions in __register_kprobe, there is 
no need to call kernel_noninit_text_address() in register_kretprobe.


Signed-off-by: Srinivasa DS <srinivasa@in.ibm.com>

 
---
 include/linux/kernel.h |    1 +
 kernel/extable.c       |   17 ++++++++++++++++-
 kernel/kprobes.c       |    4 ++--
 3 files changed, 19 insertions(+), 3 deletions(-)

Index: linux-2.6.24-rc4/include/linux/kernel.h
===================================================================
--- linux-2.6.24-rc4.orig/include/linux/kernel.h
+++ linux-2.6.24-rc4/include/linux/kernel.h
@@ -169,6 +169,7 @@ extern unsigned long long memparse(char 
 extern int core_kernel_text(unsigned long addr);
 extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
+extern int kernel_noninit_text_address(unsigned long addr);
 struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
Index: linux-2.6.24-rc4/kernel/extable.c
===================================================================
--- linux-2.6.24-rc4.orig/kernel/extable.c
+++ linux-2.6.24-rc4/kernel/extable.c
@@ -40,11 +40,18 @@ const struct exception_table_entry *sear
 	return e;
 }
 
-int core_kernel_text(unsigned long addr)
+static int  core_kernel_noninit_text(unsigned long addr)
 {
 	if (addr >= (unsigned long)_stext &&
 	    addr <= (unsigned long)_etext)
 		return 1;
+	return 0;
+}
+
+int core_kernel_text(unsigned long addr)
+{
+	if (core_kernel_noninit_text(addr))
+		return 1;
 
 	if (addr >= (unsigned long)_sinittext &&
 	    addr <= (unsigned long)_einittext)
@@ -65,3 +72,11 @@ int kernel_text_address(unsigned long ad
 		return 1;
 	return module_text_address(addr) != NULL;
 }
+
+int kernel_noninit_text_address(unsigned long addr)
+{
+	if (core_kernel_noninit_text(addr))
+		return 1;
+	return module_text_address(addr) != NULL;
+}
+
Index: linux-2.6.24-rc4/kernel/kprobes.c
===================================================================
--- linux-2.6.24-rc4.orig/kernel/kprobes.c
+++ linux-2.6.24-rc4/kernel/kprobes.c
@@ -520,7 +520,7 @@ static int __kprobes __register_kprobe(s
 		return -EINVAL;
 	p->addr = (kprobe_opcode_t *)(((char *)p->addr)+ p->offset);
 
-	if (!kernel_text_address((unsigned long) p->addr) ||
+	if (!kernel_noninit_text_address((unsigned long) p->addr) ||
 	    in_kprobes_functions((unsigned long) p->addr))
 		return -EINVAL;
 
@@ -662,7 +662,7 @@ int __kprobes register_jprobe(struct jpr
 {
 	unsigned long addr = arch_deref_entry_point(jp->entry);
 
-	if (!kernel_text_address(addr))
+	if (!kernel_noninit_text_address(addr))
 		return -EINVAL;
 
 	/* Todo: Verify probepoint is a function entry point */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]