Skip to contentSkip to conversation

kprobes for 2.5.30

PATCH In review Rusty Russell 5 participants 17 messages Aug 2, 2002 – Aug 7, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes for 2.5.30

Hi Linus,

Vamsi's kernel probes again, this time with EXPORT_SYMBOL_GPL
so people don't think this is blanket permission to hook into arbitrary parts of the kernel (as separate from debugging, testing, diagnostics, etc).

For a change, this one's cool and *doesn't* break anything 8)

Please apply,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Kprobes for i386
Author: Vamsi Krishna S
Status: Tested on 2.5.26 SMP

D: This patch allows trapping at almost any kernel address, useful for
D: various kernel-hacking tasks, and building on for more
D: infrastructure. This patch is x86 only.

arch/i386/Config.help +6 -0
diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.26/arch/i386/Config.help working-2.5.26-kprobes/arch/i386/Config.help
@@ -967,3 +967,9 @@ CONFIG_SOFTWARE_SUSPEND
   absence of features.
 
   For more information take a look at Documentation/swsusp.txt.
+
+CONFIG_KPROBES
+  Kprobes allows you to trap at almost any kernel address, using
+  register_kprobe(), and providing a callback function.  This is useful
+  for kernel debugging, non-intrusive instrumentation and testing.  If
+  in doubt, say "N".
arch/i386/config.in +1 -0
diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.26/arch/i386/config.in working-2.5.26-kprobes/arch/i386/config.in
@@ -419,6 +419,7 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; th
    if [ "$CONFIG_HIGHMEM" = "y" ]; then
       bool '  Highmem debugging' CONFIG_DEBUG_HIGHMEM
    fi
+   bool '  Probes' CONFIG_KPROBES
 fi
 
 endmenu
arch/i386/kernel/entry.S +30 -0
diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.26/arch/i386/kernel/entry.S working-2.5.26-kprobes/arch/i386/kernel/entry.S
@@ -442,9 +442,24 @@ device_not_available_emulate:
 	jmp ret_from_exception
 
 ENTRY(debug)
+#ifdef CONFIG_KPROBES
+	pushl %eax
+	SAVE_ALL
+	GET_THREAD_INFO(%ebx)
+	movl %esp,%edx
+	pushl $0
+	pushl %edx
+	call do_debug
+	addl $8,%esp
+	cmpl $0,%eax 
+	jnz restore_all
+	preempt_stop
+	jmp ret_from_exception
+#else
 	pushl $0
 	pushl $do_debug
 	jmp error_code
+#endif
 
 ENTRY(nmi)
 	pushl %eax
@@ -457,9 +472,24 @@ ENTRY(nmi)
 	RESTORE_ALL
 
 ENTRY(int3)
+#ifdef CONFIG_KPROBES
+	pushl %eax
+	SAVE_ALL
+	GET_THREAD_INFO(%ebx)
+	movl %esp,%edx
+	pushl $0
+	pushl %edx
+	call do_int3
+	addl $8,%esp
+	cmpl $0,%eax 
+	jnz restore_all
+	preempt_stop
+	jmp ret_from_exception
+#else
 	pushl $0
 	pushl $do_int3
 	jmp error_code
+#endif
 
 ENTRY(overflow)
 	pushl $0
arch/i386/kernel/i386_ksyms.c +6 -0
diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.26/arch/i386/kernel/i386_ksyms.c working-2.5.26-kprobes/arch/i386/kernel/i386_ksyms.c
@@ -29,6 +29,7 @@
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
+#include <asm/kprobes.h>
 
 extern void dump_thread(struct pt_regs *, struct user *);
 extern spinlock_t rtc_lock;
@@ -176,6 +177,11 @@ extern int is_sony_vaio_laptop;
 EXPORT_SYMBOL(is_sony_vaio_laptop);
 
 EXPORT_SYMBOL(__PAGE_KERNEL);
+
+#ifdef CONFIG_KPROBES
+EXPORT_SYMBOL_GPL(register_kprobe);
+EXPORT_SYMBOL_GPL(unregister_kprobe);
+#endif
 
 #ifdef CONFIG_MULTIQUAD
 EXPORT_SYMBOL(xquad_portio);
arch/i386/kernel/traps.c +257 -4

343 lines not on this page · raw message

arch/i386/mm/fault.c +4 -0
diff -urpN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.26/arch/i386/mm/fault.c working-2.5.26-kprobes/arch/i386/mm/fault.c
@@ -20,6 +20,7 @@
 #include <linux/tty.h>
 #include <linux/vt_kern.h>		/* For unblank_screen() */
 
+#include <asm/kprobes.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
@@ -156,6 +157,9 @@ asmlinkage void do_page_fault(struct pt_
 
 	/* get the address */
 	__asm__("movl %%cr2,%0":"=r" (address));
+
+	if (kprobe_fault(regs, 14))
+		return;
 
 	/* It's safe to allow irq's after cr2 has been saved */
 	if (regs->eflags & X86_EFLAGS_IF)
include/asm-i386/kprobes.h +63 -0

63 lines not on this page · raw message

#1 lore raw

From: Rusty Russell <[email protected]>
Date: Fri, 02 Aug 2002 12:11:47 +1000

Vamsi's kernel probes again, this time with EXPORT_SYMBOL_GPL
so people don't think this is blanket permission to hook into arbitrary parts of the kernel (as separate from debugging, testing, diagnostics, etc).

A nice enhancement would be to move the kprobe table and other generic bits into a common area so that it did not need to be duplicated as other arches add kprobe support.

#2 lore raw
Quoted 11 lines · David S. Miller

From: Rusty Russell <[email protected]>
Date: Fri, 02 Aug 2002 12:11:47 +1000

Vamsi's kernel probes again, this time with EXPORT_SYMBOL_GPL
so people don't think this is blanket permission to hook into arbitrary parts of the kernel (as separate from debugging, testing, diagnostics, etc).

A nice enhancement would be to move the kprobe table and other generic bits into a common area so that it did not need to be duplicated as other arches add kprobe support.

Yes. We didn't do it in the first version of this patch to avoid touching too many files.

We do have the full version of dprobes which has generic bits and arch-specific ones cleanly seperated. In fact, dprobes ports are available for ia32, s390, s390x, ppc with ppc64 and ia64 ports in early stages. Please check out:
http://www-124.ibm.com/linux/projects/dprobes/

Thanks,
--Vamsi

Signature · 5 lines
Vamsi Krishna S.
Linux Technology Center,
IBM Software Lab, Bangalore.
Ph: +91 80 5044959
Internet: [email protected]
#3 lore raw
In reply to David S. Miller

In message <[email protected]> you write:

Quoted 11 lines

From: Rusty Russell <[email protected]>
Date: Fri, 02 Aug 2002 12:11:47 +1000

Vamsi's kernel probes again, this time with EXPORT_SYMBOL_GPL
so people don't think this is blanket permission to hook into arbitrary parts of the kernel (as separate from debugging, testing, diagnostics, etc).

A nice enhancement would be to move the kprobe table and other generic bits into a common area so that it did not need to be duplicated as other arches add kprobe support.

Done. Look better?

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Kprobes for i386
Author: Vamsi Krishna S
Status: Experimental

D: This patch allows trapping at almost any kernel address, useful for
D: various kernel-hacking tasks, and building on for more
D: infrastructure. This patch is x86 only, but other archs can add
D: support as required.

arch/i386/Config.help +6 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/Config.help working-2.5.30-kprobes/arch/i386/Config.help
@@ -967,3 +967,9 @@ CONFIG_SOFTWARE_SUSPEND
   absence of features.
 
   For more information take a look at Documentation/swsusp.txt.
+
+CONFIG_KPROBES
+  Kprobes allows you to trap at almost any kernel address, using
+  register_kprobe(), and providing a callback function.  This is useful
+  for kernel debugging, non-intrusive instrumentation and testing.  If
+  in doubt, say "N".
include/linux/kprobes.h +54 -0

54 lines not on this page · raw message

kernel/Makefile +2 -1
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/kernel/Makefile working-2.5.30-kprobes/kernel/Makefile
@@ -10,7 +10,7 @@
 O_TARGET := kernel.o
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o platform.o suspend.o
+		printk.o platform.o suspend.o kprobes.o
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
@@ -23,6 +23,7 @@ obj-$(CONFIG_MODULES) += ksyms.o
 obj-$(CONFIG_PM) += pm.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
+obj-$(CONFIG_KPROBES) += kprobes.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/kprobes.c +94 -0

94 lines not on this page · raw message

arch/i386/config.in +1 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/config.in working-2.5.30-kprobes/arch/i386/config.in
@@ -415,6 +415,7 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; th
    if [ "$CONFIG_HIGHMEM" = "y" ]; then
       bool '  Highmem debugging' CONFIG_DEBUG_HIGHMEM
    fi
+   bool '  Probes' CONFIG_KPROBES
 fi
 
 endmenu
arch/i386/kernel/entry.S +26 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/kernel/entry.S working-2.5.30-kprobes/arch/i386/kernel/entry.S
@@ -430,9 +430,22 @@ device_not_available_emulate:
 	jmp ret_from_exception
 
 ENTRY(debug)
+#ifdef CONFIG_KPROBES
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
+	pushl $0
+	pushl %edx
+	call do_debug
+	addl $8,%esp
+	cmpl $0,%eax 
+	jnz restore_all
+	jmp ret_from_exception
+#else
 	pushl $0
 	pushl $do_debug
 	jmp error_code
+#endif
 
 ENTRY(nmi)
 	pushl %eax
@@ -445,9 +460,22 @@ ENTRY(nmi)
 	RESTORE_ALL
 
 ENTRY(int3)
+#ifdef CONFIG_KPROBES
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
+	pushl $0
+	pushl %edx
+	call do_int3
+	addl $8,%esp
+	cmpl $0,%eax 
+	jnz restore_all
+	jmp ret_from_exception
+#else
 	pushl $0
 	pushl $do_int3
 	jmp error_code
+#endif
 
 ENTRY(overflow)
 	pushl $0
arch/i386/kernel/traps.c +190 -4

282 lines not on this page · raw message

arch/i386/mm/fault.c +4 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/mm/fault.c working-2.5.30-kprobes/arch/i386/mm/fault.c
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <linux/tty.h>
 #include <linux/vt_kern.h>		/* For unblank_screen() */
+#include <linux/kprobes.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -154,6 +155,9 @@ asmlinkage void do_page_fault(struct pt_
 
 	/* get the address */
 	__asm__("movl %%cr2,%0":"=r" (address));
+
+	if (kprobe_fault(regs, 14))
+		return;
 
 	/* It's safe to allow irq's after cr2 has been saved */
 	if (regs->eflags & X86_EFLAGS_IF)
fs/partitions/check.c +1 -1
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/fs/partitions/check.c working-2.5.30-kprobes/fs/partitions/check.c
@@ -467,7 +467,7 @@ void devfs_register_partitions (struct g
 	for (part = 1; part < max_p; part++) {
 		if ( unregister || (p[part].nr_sects < 1) ) {
 			devfs_unregister(p[part].de);
-			dev->part[p].de = NULL;
+			dev->part[part].de = NULL;
 			continue;
 		}
 		devfs_register_partition (dev, minor, part);
include/asm-i386/kprobes.h +28 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/include/asm-i386/kprobes.h working-2.5.30-kprobes/include/asm-i386/kprobes.h
@@ -0,0 +1,28 @@
+#ifndef _ASM_KPROBES_H
+#define _ASM_KPROBES_H
+/*
+ *  Dynamic Probes (kprobes) support
+ *  	Vamsi Krishna S <[email protected]>, July, 2002
+ *	Mailing list: [email protected]
+ */
+#include <linux/smp.h>
+#include <linux/types.h>
+
+struct pt_regs;
+
+#ifdef CONFIG_KPROBES
+typedef u8 kprobe_opcode_t;
+
+#define BREAKPOINT_INSTRUCTION	0xcc
+
+extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
+
+/* kprobe_running() not defined yet, so this is a macro. */
+#define kprobe_fault(regs, trapnr)					\
+	(kprobe_running() && kprobe_fault_handler(regs, trapnr))
+
+#else /* !CONFIG_KPROBES */
+static inline int kprobe_fault(struct pt_regs *regs, int trapnr) { return 0; }
+#endif
+
+#endif /* _ASM_KPROBES_H */
#4 lore raw
Quoted 2 lines · Rusty Russell

Done. Look better?

How about one more cleanup: make the x86 do_int3()/do_debug() calling convention be independent of CONFIG_KPROBE?

Btw, the way to test against zero in x86 asm is not

	cmpl $0,%eax

but rather the shorter

testl %eax,%eax

which just shows that the person who wrote the asm probably was used to saner CPUs ;)

Linus

#16 lore raw
In reply to Rusty Russell

From: Rusty Russell <[email protected]>
Date: Mon, 05 Aug 2002 14:14:12 +1000

In message <[email protected]> you write:

Quoted 3 lines

A nice enhancement would be to move the kprobe table and other generic bits into a common area so that it did not need to be duplicated as other arches add kprobe support.

Done. Look better?

That's exactly how I wanted the generic stuff split out, it's perfect.

#5 lore raw
In reply to Linus Torvalds

In message <[email protected]> you wri te:

Quoted 7 lines · Rusty Russell
Quoted 2 lines

Done. Look better?

How about one more cleanup: make the x86 do_int3()/do_debug() calling convention be independent of CONFIG_KPROBE?

Thanks, fixed (and, because my x86 asm is lousy, actually tested).

In testing, I came up against the "spin_unlock() causes schedule() inside interrupt" problem. Fix is counterintuitive, IMHO (search for "Linus"). If you really want us not to assume that preemption is disabled in interrupt handlers, then more code needs to change.

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Kprobes for i386
Author: Vamsi Krishna S
Status: Experimental

D: This patch allows trapping at almost any kernel address, useful for
D: various kernel-hacking tasks, and building on for more
D: infrastructure. This patch is x86 only, but other archs can add
D: support as required.

arch/i386/Config.help +6 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/Config.help working-2.5.30-kprobe/arch/i386/Config.help
@@ -967,3 +967,9 @@ CONFIG_SOFTWARE_SUSPEND
   absence of features.
 
   For more information take a look at Documentation/swsusp.txt.
+
+CONFIG_KPROBES
+  Kprobes allows you to trap at almost any kernel address, using
+  register_kprobe(), and providing a callback function.  This is useful
+  for kernel debugging, non-intrusive instrumentation and testing.  If
+  in doubt, say "N".
arch/i386/config.in +1 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/config.in working-2.5.30-kprobe/arch/i386/config.in
@@ -415,6 +415,7 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; th
    if [ "$CONFIG_HIGHMEM" = "y" ]; then
       bool '  Highmem debugging' CONFIG_DEBUG_HIGHMEM
    fi
+   bool '  Probes' CONFIG_KPROBES
 fi
 
 endmenu
arch/i386/kernel/entry.S +18 -4
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/kernel/entry.S working-2.5.30-kprobe/arch/i386/kernel/entry.S
@@ -430,9 +430,16 @@ device_not_available_emulate:
 	jmp ret_from_exception
 
 ENTRY(debug)
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
 	pushl $0
-	pushl $do_debug
-	jmp error_code
+	pushl %edx
+	call do_debug
+	addl $8,%esp
+	testl %eax,%eax 
+	jnz restore_all
+	jmp ret_from_exception
 
 ENTRY(nmi)
 	pushl %eax
@@ -445,9 +452,16 @@ ENTRY(nmi)
 	RESTORE_ALL
 
 ENTRY(int3)
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
 	pushl $0
-	pushl $do_int3
-	jmp error_code
+	pushl %edx
+	call do_int3
+	addl $8,%esp
+	cmpl $0,%eax 
+	jnz restore_all
+	jmp ret_from_exception
 
 ENTRY(overflow)
 	pushl $0
arch/i386/kernel/traps.c +181 -7

273 lines not on this page · raw message

arch/i386/mm/fault.c +4 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/mm/fault.c working-2.5.30-kprobe/arch/i386/mm/fault.c
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <linux/tty.h>
 #include <linux/vt_kern.h>		/* For unblank_screen() */
+#include <linux/kprobes.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -154,6 +155,9 @@ asmlinkage void do_page_fault(struct pt_
 
 	/* get the address */
 	__asm__("movl %%cr2,%0":"=r" (address));
+
+	if (kprobe_fault(regs, 14))
+		return;
 
 	/* It's safe to allow irq's after cr2 has been saved */
 	if (regs->eflags & X86_EFLAGS_IF)
include/asm-i386/kprobes.h +29 -0
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/include/asm-i386/kprobes.h working-2.5.30-kprobe/include/asm-i386/kprobes.h
@@ -0,0 +1,29 @@
+#ifndef _ASM_KPROBES_H
+#define _ASM_KPROBES_H
+/*
+ *  Dynamic Probes (kprobes) support
+ *  	Vamsi Krishna S <[email protected]>, July, 2002
+ *	Mailing list: [email protected]
+ */
+#include <linux/smp.h>
+#include <linux/types.h>
+
+struct pt_regs;
+
+typedef u8 kprobe_opcode_t;
+
+#ifdef CONFIG_KPROBES
+
+#define BREAKPOINT_INSTRUCTION	0xcc
+
+extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
+
+/* kprobe_running() not defined yet, so this is a macro. */
+#define kprobe_fault(regs, trapnr)					\
+	(kprobe_running() && kprobe_fault_handler(regs, trapnr))
+
+#else /* !CONFIG_KPROBES */
+static inline int kprobe_fault(struct pt_regs *regs, int trapnr) { return 0; }
+#endif
+
+#endif /* _ASM_KPROBES_H */
include/linux/kprobes.h +54 -0

54 lines not on this page · raw message

kernel/Makefile +2 -1
diff -urNp -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/kernel/Makefile working-2.5.30-kprobe/kernel/Makefile
@@ -10,7 +10,7 @@
 O_TARGET := kernel.o
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o platform.o suspend.o
+		printk.o platform.o suspend.o kprobes.o
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
@@ -23,6 +23,7 @@ obj-$(CONFIG_MODULES) += ksyms.o
 obj-$(CONFIG_PM) += pm.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
+obj-$(CONFIG_KPROBES) += kprobes.o futex.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/kprobes.c +97 -0

97 lines not on this page · raw message

#6 lore raw
Quoted 3 lines · Rusty Russell

In testing, I came up against the "spin_unlock() causes schedule() inside interrupt" problem.

It shouldn't cause a schedule, it should cause a big warning (with complete trace) to be printed out. Or did you mean something else?

Maybe the warning should be changed to

Warning, kernel is mixing metaphors. "It's not rocket surgery".

to make it clear why it's a bad idea.

Linus

#7 lore raw

In message <[email protected]> you wri te:

Quoted 8 lines · Rusty Russell
Quoted 3 lines

In testing, I came up against the "spin_unlock() causes schedule() inside interrupt" problem.

It shouldn't cause a schedule, it should cause a big warning (with complete trace) to be printed out. Or did you mean something else?

Yes, that's what I meant.

Quoted 5 lines

Maybe the warning should be changed to

Warning, kernel is mixing metaphors. "It's not rocket surgery".

to make it clear why it's a bad idea.

Oh yes, that's *much* clearer!

I am reading from this that we *should* be explicitly disabling preemption in interrupt handlers if we rely on the cpu number not changing underneath us, even if it's (a) currently unneccessary, and
(b) arch-specific code.

Yes?
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#8 lore raw
Quoted 5 lines · Rusty Russell

I am reading from this that we *should* be explicitly disabling preemption in interrupt handlers if we rely on the cpu number not changing underneath us, even if it's (a) currently unneccessary, and
(b) arch-specific code.

But do_irq() already does that.

You mean _exception_ handlers. It's definitely not unnecessary. Exceptions can very much be preempted.

Linus

#9 lore raw

In message <[email protected]> you wri te:

Quoted 9 lines · Rusty Russell
Quoted 5 lines

I am reading from this that we *should* be explicitly disabling preemption in interrupt handlers if we rely on the cpu number not changing underneath us, even if it's (a) currently unneccessary, and
(b) arch-specific code.

But do_irq() already does that.

Right, that's what I wanted to check.

Quoted 2 lines

You mean _exception_ handlers. It's definitely not unnecessary. Exceptions can very much be preempted.

The patch changes traps 1 and 3 (debug & int3) to interrupt gates though.

In fact, the removal of the #ifdef CONFIG_KPROBES around that change introduced a bug: we didn't reenable interrupts like the older code expects.

Vamsi, what do you think of this patch? Is it neccessary to restore interrupts before handle_vm86_trap (the original patch didn't do this either, not sure if it's required).

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Kprobes for i386
Author: Vamsi Krishna S
Status: Experimental

D: This patch allows trapping at almost any kernel address, useful for
D: various kernel-hacking tasks, and building on for more
D: infrastructure. This patch is x86 only, but other archs can add
D: support as required.

arch/i386/Config.help +6 -0
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/Config.help working-2.5.30-kprobes/arch/i386/Config.help
@@ -967,3 +967,9 @@ CONFIG_SOFTWARE_SUSPEND
   absence of features.
 
   For more information take a look at Documentation/swsusp.txt.
+
+CONFIG_KPROBES
+  Kprobes allows you to trap at almost any kernel address, using
+  register_kprobe(), and providing a callback function.  This is useful
+  for kernel debugging, non-intrusive instrumentation and testing.  If
+  in doubt, say "N".
arch/i386/config.in +1 -0
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/config.in working-2.5.30-kprobes/arch/i386/config.in
@@ -415,6 +415,7 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; th
    if [ "$CONFIG_HIGHMEM" = "y" ]; then
       bool '  Highmem debugging' CONFIG_DEBUG_HIGHMEM
    fi
+   bool '  Probes' CONFIG_KPROBES
 fi
 
 endmenu
arch/i386/kernel/entry.S +18 -4
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/kernel/entry.S working-2.5.30-kprobes/arch/i386/kernel/entry.S
@@ -430,9 +430,16 @@ device_not_available_emulate:
 	jmp ret_from_exception
 
 ENTRY(debug)
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
 	pushl $0
-	pushl $do_debug
-	jmp error_code
+	pushl %edx
+	call do_debug
+	addl $8,%esp
+	testl %eax,%eax 
+	jnz restore_all
+	jmp ret_from_exception
 
 ENTRY(nmi)
 	pushl %eax
@@ -445,9 +452,16 @@ ENTRY(nmi)
 	RESTORE_ALL
 
 ENTRY(int3)
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
 	pushl $0
-	pushl $do_int3
-	jmp error_code
+	pushl %edx
+	call do_int3
+	addl $8,%esp
+	cmpl $0,%eax 
+	jnz restore_all
+	jmp ret_from_exception
 
 ENTRY(overflow)
 	pushl $0
arch/i386/kernel/traps.c +189 -8

288 lines not on this page · raw message

arch/i386/mm/fault.c +4 -0
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/arch/i386/mm/fault.c working-2.5.30-kprobes/arch/i386/mm/fault.c
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <linux/tty.h>
 #include <linux/vt_kern.h>		/* For unblank_screen() */
+#include <linux/kprobes.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -154,6 +155,9 @@ asmlinkage void do_page_fault(struct pt_
 
 	/* get the address */
 	__asm__("movl %%cr2,%0":"=r" (address));
+
+	if (kprobe_running() && kprobe_fault_handler(regs, 14))
+		return;
 
 	/* It's safe to allow irq's after cr2 has been saved */
 	if (regs->eflags & X86_EFLAGS_IF)
include/asm-i386/kprobes.h +20 -0
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/include/asm-i386/kprobes.h working-2.5.30-kprobes/include/asm-i386/kprobes.h
@@ -0,0 +1,20 @@
+#ifndef _ASM_KPROBES_H
+#define _ASM_KPROBES_H
+/*
+ *  Dynamic Probes (kprobes) support
+ *  	Vamsi Krishna S <[email protected]>, July, 2002
+ *	Mailing list: [email protected]
+ */
+#include <linux/smp.h>
+#include <linux/types.h>
+
+struct pt_regs;
+
+typedef u8 kprobe_opcode_t;
+
+/* Doesn't exist if !CONFIG_KPROBES, but calls optimized out. */
+extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
+
+#define BREAKPOINT_INSTRUCTION	0xcc
+
+#endif /* _ASM_KPROBES_H */
include/linux/kprobes.h +54 -0

54 lines not on this page · raw message

kernel/Makefile +2 -1
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.30/kernel/Makefile working-2.5.30-kprobes/kernel/Makefile
@@ -10,7 +10,7 @@
 O_TARGET := kernel.o
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o platform.o suspend.o
+		printk.o platform.o suspend.o kprobes.o
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
@@ -23,6 +23,7 @@ obj-$(CONFIG_MODULES) += ksyms.o
 obj-$(CONFIG_PM) += pm.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
+obj-$(CONFIG_KPROBES) += kprobes.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/kprobes.c +94 -0

94 lines not on this page · raw message

#10 lore raw
Quoted 3 lines · Rusty Russell

Vamsi, what do you think of this patch? Is it neccessary to restore interrupts before handle_vm86_trap (the original patch didn't do this either, not sure if it's required).

Any chance you could split the i386-specific kprobes code into arch/i386/kernel/kprobes.c instead of bloating traps.c?

#11 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Rusty Russell

Vamsi, what do you think of this patch? Is it neccessary to restore interrupts before handle_vm86_trap (the original patch didn't do this either, not sure if it's required).

Any chance you could split the i386-specific kprobes code into arch/i386/kernel/kprobes.c instead of bloating traps.c?

Agreed. Please see the latest patch.

Signature · 5 lines
Vamsi Krishna S.
Linux Technology Center,
IBM Software Lab, Bangalore.
Ph: +91 80 5044959
Internet: [email protected]
#12 lore raw
In reply to Rusty Russell

Hi Rusty,

Quoted 7 lines · Rusty Russell
Quoted 3 lines

You mean _exception_ handlers. It's definitely not unnecessary. Exceptions can very much be preempted.

The patch changes traps 1 and 3 (debug & int3) to interrupt gates though.

Quoted 8 lines

In fact, the removal of the #ifdef CONFIG_KPROBES around that change introduced a bug: we didn't reenable interrupts like the older code expects.

Vamsi, what do you think of this patch? Is it neccessary to restore interrupts before handle_vm86_trap (the original patch didn't do this either, not sure if it's required).

Yes. It is necessary to restore interrupts before any of the normal do_int3/do_debug code is executed. However, it could be done in a less intrusive way. Please see the patch below, which does:

- move kprobes code from traps.c to kprobes.c in arch/i386/kernel (per Christoph Hellwig)

- restore interrupts in all cases before returning to execute do_int3/do_debug from kprobe_handler and post_kprobe_handler. This brings down the size of the diff, keeps do_int3 and do_debug in traps.c clean.

- move trap1 and trap3 interrupt gates only under CONFIG_KPROBES. Please note that if we don't do this, we need to call restore_interrupts() from the dummy (post_)kprobe_handler() in include/asm-i386/kprobes.h when CONFIG_KPROBES is off. I didn't like this subtle side effect. hence the #ifdef CONFIG_KPROBES around _set_trap_gate. Still, the calling conventions of do_debug and do_int3 remain independent of CONFIG_KPROBES.

Comments?

Thanks,
--Vamsi

Signature · 6 lines
Vamsi Krishna S.
Linux Technology Center,
IBM Software Lab, Bangalore.
Ph: +91 80 5044959
Internet: [email protected]
--
Quoted 10 lines

Name: Kprobes for i386
Author: Vamsi Krishna S
Status: Experimental

D: This patch allows trapping at almost any kernel address, useful for
D: various kernel-hacking tasks, and building on for more
D: infrastructure. This patch is x86 only, but other archs can add
D: support as required.

arch/i386/Config.help renamed from usr/src/30-pure/arch/i386/Config.help +6 -0
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/arch/i386/Config.help 30-dp/arch/i386/Config.help
@@ -967,3 +967,9 @@
   absence of features.
 
   For more information take a look at Documentation/swsusp.txt.
+
+CONFIG_KPROBES
+  Kprobes allows you to trap at almost any kernel address, using
+  register_kprobe(), and providing a callback function.  This is useful
+  for kernel debugging, non-intrusive instrumentation and testing.  If
+  in doubt, say "N".
arch/i386/config.in renamed from usr/src/30-pure/arch/i386/config.in +1 -0
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/arch/i386/config.in 30-dp/arch/i386/config.in
@@ -415,6 +415,7 @@
    if [ "$CONFIG_HIGHMEM" = "y" ]; then
       bool '  Highmem debugging' CONFIG_DEBUG_HIGHMEM
    fi
+   bool '  Probes' CONFIG_KPROBES
 fi
 
 endmenu
arch/i386/kernel/entry.S renamed from usr/src/30-pure/arch/i386/kernel/entry.S +18 -4
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/arch/i386/kernel/entry.S 30-dp/arch/i386/kernel/entry.S
@@ -430,9 +430,16 @@
 	jmp ret_from_exception
 
 ENTRY(debug)
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
 	pushl $0
-	pushl $do_debug
-	jmp error_code
+	pushl %edx
+	call do_debug
+	addl $8,%esp
+	testl %eax,%eax 
+	jnz restore_all
+	jmp ret_from_exception
 
 ENTRY(nmi)
 	pushl %eax
@@ -445,9 +452,16 @@
 	RESTORE_ALL
 
 ENTRY(int3)
+	pushl %eax
+	SAVE_ALL
+	movl %esp,%edx
 	pushl $0
-	pushl $do_int3
-	jmp error_code
+	pushl %edx
+	call do_int3
+	addl $8,%esp
+	cmpl $0,%eax 
+	jnz restore_all
+	jmp ret_from_exception
 
 ENTRY(overflow)
 	pushl $0
arch/i386/kernel/kprobes.c renamed from usr/src/30-pure/arch/i386/kernel/kprobes.c +172 -0

172 lines not on this page · raw message

arch/i386/kernel/Makefile renamed from usr/src/30-pure/arch/i386/kernel/Makefile +1 -0
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/arch/i386/kernel/Makefile 30-dp/arch/i386/kernel/Makefile
@@ -26,6 +26,7 @@
 obj-$(CONFIG_X86_LOCAL_APIC)	+= mpparse.o apic.o nmi.o
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= suspend.o
+obj-$(CONFIG_KPROBES)		+= kprobes.o
 ifdef CONFIG_VISWS
 obj-y += setup-visws.o
 obj-$(CONFIG_X86_VISWS_APIC)	+= visws_apic.o
arch/i386/kernel/traps.c renamed from usr/src/30-pure/arch/i386/kernel/traps.c +30 -7
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/arch/i386/kernel/traps.c 30-dp/arch/i386/kernel/traps.c
@@ -24,6 +24,7 @@
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
 #include <linux/highmem.h>
+#include <linux/kprobes.h>
 
 #ifdef CONFIG_EISA
 #include <linux/ioport.h>
@@ -326,6 +327,8 @@
 		panic("do_trap: can't hit this");
 	}
 #endif	
+	if (kprobe_running() && kprobe_fault_handler(regs, trapnr))
+		return;
 
 	if (!(regs->xcs & 3))
 		goto kernel_trap;
@@ -392,7 +395,6 @@
 }
 
 DO_VM86_ERROR_INFO( 0, SIGFPE,  "divide error", divide_error, FPE_INTDIV, regs->eip)
-DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
 DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
 DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds)
 DO_ERROR_INFO( 6, SIGILL,  "invalid operand", invalid_op, ILL_ILLOPN, regs->eip)
@@ -408,6 +410,9 @@
 {
 	if (regs->eflags & VM_MASK)
 		goto gp_in_vm86;
+	
+	if (kprobe_running() && kprobe_fault_handler(regs, 13))
+		return;
 
 	if (!(regs->xcs & 3))
 		goto gp_in_kernel;
@@ -508,6 +513,14 @@
 	inb(0x71);		/* dummy */
 }
 
+asmlinkage int do_int3(struct pt_regs *regs, long error_code)
+{
+	if (kprobe_handler(regs))
+		return 1;
+	do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
+	return 0;
+}
+
 /*
  * Our handling of the processor debug registers is non-trivial.
  * We do not clear them on entry and exit from the kernel. Therefore
@@ -530,7 +543,7 @@
  * find every occurrence of the TF bit that could be saved away even
  * by user code)
  */
-asmlinkage void do_debug(struct pt_regs * regs, long error_code)
+asmlinkage int do_debug(struct pt_regs * regs, long error_code)
 {
 	unsigned int condition;
 	struct task_struct *tsk = current;
@@ -538,6 +551,9 @@
 
 	__asm__ __volatile__("movl %%db6,%0" : "=r" (condition));
 
+	if (post_kprobe_handler(regs))
+		return 1;
+
 	/* Mask out spurious debug traps due to lazy DR7 setting */
 	if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
 		if (!tsk->thread.debugreg[7])
@@ -588,15 +604,15 @@
 	__asm__("movl %0,%%db7"
 		: /* no output */
 		: "r" (0));
-	return;
+	return 0;
 
 debug_vm86:
 	handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
-	return;
+	return 0;
 
 clear_TF:
 	regs->eflags &= ~TF_MASK;
-	return;
+	return 0;
 }
 
 /*
@@ -760,6 +776,8 @@
 	struct task_struct *tsk = current;
 	clts();		/* Allow maths ops (or we recurse) */
 
+	if (kprobe_running() && kprobe_fault_handler(&regs, 7))
+		return;
 	if (!tsk->used_math)
 		init_fpu(tsk);
 	restore_fpu(tsk);
@@ -943,9 +961,14 @@
 #endif
 
 	set_trap_gate(0,&divide_error);
-	set_trap_gate(1,&debug);
 	set_intr_gate(2,&nmi);
-	set_system_gate(3,&int3);	/* int3-5 can be called from all */
+#ifdef CONFIG_KPROBES
+	_set_gate(idt_table+1,14,3,&debug);
+	_set_gate(idt_table+3,14,3,&int3);
+#else
+ 	set_trap_gate(1,&debug);
+ 	set_system_gate(3,&int3);	/* int3-5 can be called from all */
+#endif
 	set_system_gate(4,&overflow);
 	set_system_gate(5,&bounds);
 	set_trap_gate(6,&invalid_op);
arch/i386/mm/fault.c renamed from usr/src/30-pure/arch/i386/mm/fault.c +4 -0
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/arch/i386/mm/fault.c 30-dp/arch/i386/mm/fault.c
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <linux/tty.h>
 #include <linux/vt_kern.h>		/* For unblank_screen() */
+#include <linux/kprobes.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -155,6 +156,9 @@
 	/* get the address */
 	__asm__("movl %%cr2,%0":"=r" (address));
 
+	if (kprobe_running() && kprobe_fault_handler(regs, 14))
+		return;
+
 	/* It's safe to allow irq's after cr2 has been saved */
 	if (regs->eflags & X86_EFLAGS_IF)
 		local_irq_enable();
include/asm-i386/kprobes.h renamed from usr/src/30-pure/include/asm-i386/kprobes.h +24 -0
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/include/asm-i386/kprobes.h 30-dp/include/asm-i386/kprobes.h
@@ -0,0 +1,24 @@
+#ifndef _ASM_KPROBES_H
+#define _ASM_KPROBES_H
+/*
+ *  Dynamic Probes (kprobes) support
+ *  	Vamsi Krishna S <[email protected]>, July, 2002
+ *	Mailing list: [email protected]
+ */
+#include <linux/types.h>
+
+struct pt_regs;
+
+typedef u8 kprobe_opcode_t;
+#define BREAKPOINT_INSTRUCTION	0xcc
+
+#ifdef CONFIG_KPROBES
+extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
+extern int post_kprobe_handler(struct pt_regs *regs);
+extern int kprobe_handler(struct pt_regs *regs);
+#else /* !CONFIG_KPROBES */
+static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) { return 0; }
+static inline int post_kprobe_handler(struct pt_regs *regs) { return 0; }
+static inline int kprobe_handler(struct pt_regs *regs) { return 0; }
+#endif
+#endif /* _ASM_KPROBES_H */
include/linux/kprobes.h renamed from usr/src/30-pure/include/linux/kprobes.h +54 -0

54 lines not on this page · raw message

kernel/kprobes.c renamed from usr/src/30-pure/kernel/kprobes.c +94 -0

94 lines not on this page · raw message

kernel/Makefile renamed from usr/src/30-pure/kernel/Makefile +2 -1
diff -urN -X /home/vamsi/.dontdiff /usr/src/30-pure/kernel/Makefile 30-dp/kernel/Makefile
@@ -10,7 +10,7 @@
 O_TARGET := kernel.o
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o platform.o suspend.o
+		printk.o platform.o suspend.o kprobes.o
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
@@ -23,6 +23,7 @@
 obj-$(CONFIG_PM) += pm.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
+obj-$(CONFIG_KPROBES) += kprobes.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
#15 lore raw
In reply to Rusty Russell
Quoted 6 lines · Rusty Russell
Quoted 3 lines

You mean _exception_ handlers. It's definitely not unnecessary. Exceptions can very much be preempted.

The patch changes traps 1 and 3 (debug & int3) to interrupt gates though.

Yes, but then it enables interrupts at one point.

And I'm not saying that is wrong - I'm saying that the warning is really because you didn't tell the kernel that it was _not_ wrong. The warning is a "I got called with interrupts disabled, not nobody actually told me that I shouldn't reschedule. I will refuse to reschedule (exactly because interrupts weren't enabled), but I don't like the fact that somebody apparently did things behind my back".

Think of the kernel as a grumpy girlfriend that you just stood up, and bring flowers next time.

Linus

#13 lore raw
In reply to Vamsi Krishna S .

In message <[email protected]> you write:

Quoted 6 lines

- move trap1 and trap3 interrupt gates only under CONFIG_KPROBES. Please note that if we don't do this, we need to call restore_interrupts() from the dummy (post_)kprobe_handler() in include/asm-i386/kprobes.h when CONFIG_KPROBES is off. I didn't like this subtle side effect. hence the #ifdef CONFIG_KPROBES around _set_trap_gate. Still, the calling conventions of do_debug and do_int3 remain independent of CONFIG_KPROBES.

Hmm, I thought about this but then decided against it. Your way is pretty subtle too: I think I prefer the restore_interrupts() explicitly after the (failed) call to kprobe_handler, ie (on top of your patch, which looks excellent):

arch/i386/kernel/traps.c +8 -7
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal working-2.5.30-kprobes-vamsi/arch/i386/kernel/traps.c working-2.5.30-kprobes/arch/i386/kernel/traps.c
@@ -517,6 +517,9 @@ asmlinkage int do_int3(struct pt_regs *r
 {
 	if (kprobe_handler(regs))
 		return 1;
+	/* This is an interrupt gate, because kprobes wants interrupts
+           disabled.  Normal trap handlers don't. */
+	restore_interrupts(regs);
 	do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
 	return 0;
 }
@@ -554,6 +557,9 @@ asmlinkage int do_debug(struct pt_regs *
 	if (post_kprobe_handler(regs))
 		return 1;
 
+	/* Interrupts not disabled for normal trap handling. */
+	restore_interrupts(regs);
+
 	/* Mask out spurious debug traps due to lazy DR7 setting */
 	if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
 		if (!tsk->thread.debugreg[7])
@@ -961,14 +967,9 @@ void __init trap_init(void)
 #endif
 
 	set_trap_gate(0,&divide_error);
+	_set_gate(idt_table+1,14,3,&debug); /* debug trap for kprobes */
 	set_intr_gate(2,&nmi);
-#ifdef CONFIG_KPROBES
-	_set_gate(idt_table+1,14,3,&debug);
-	_set_gate(idt_table+3,14,3,&int3);
-#else
- 	set_trap_gate(1,&debug);
- 	set_system_gate(3,&int3);	/* int3-5 can be called from all */
-#endif
+	_set_gate(idt_table+3,14,3,&int3); /* int3-5 can be called from all */
 	set_system_gate(4,&overflow);
 	set_system_gate(5,&bounds);
 	set_trap_gate(6,&invalid_op);
arch/i386/kernel/kprobes.c +2 -7
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal working-2.5.30-kprobes-vamsi/arch/i386/kernel/kprobes.c working-2.5.30-kprobes/arch/i386/kernel/kprobes.c
@@ -102,7 +102,6 @@ int kprobe_handler(struct pt_regs *regs)
 
 no_kprobe:
 	preempt_enable_no_resched();
-	restore_interrupts(regs);
 	return ret;
 }
 
@@ -119,7 +118,7 @@ static void rearm_kprobe(struct kprobe *
 int post_kprobe_handler(struct pt_regs *regs)
 {
 	if (!kprobe_running())
-		goto no_kprobe;
+		return 0;
 
 	if (current_kprobe->post_handler)
 		current_kprobe->post_handler(current_kprobe, regs, 0);
@@ -145,13 +144,9 @@ int post_kprobe_handler(struct pt_regs *
 	 * of do_debug, as if this is not a probe hit.
 	 */
 	if (regs->eflags & TF_MASK)
-		goto no_kprobe;
+		return 0;
 
 	return 1;
-
-no_kprobe:
-	restore_interrupts(regs);
-	return 0;
 }
 
 /* Interrupts disabled, kprobe_lock held. */

--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#14 lore raw

Hi Rusty,

Quoted 8 lines · Rusty Russell

In message <[email protected]> you write:

Quoted 6 lines

- move trap1 and trap3 interrupt gates only under CONFIG_KPROBES. Please note that if we don't do this, we need to call restore_interrupts() from the dummy (post_)kprobe_handler() in include/asm-i386/kprobes.h when CONFIG_KPROBES is off. I didn't like this subtle side effect. hence the #ifdef CONFIG_KPROBES around _set_trap_gate. Still, the calling conventions of do_debug and do_int3 remain independent of CONFIG_KPROBES.

Quoted 4 lines

Hmm, I thought about this but then decided against it. Your way is pretty subtle too: I think I prefer the restore_interrupts() explicitly after the (failed) call to kprobe_handler, ie (on top of your patch, which looks excellent):

I agree this one is even better.

Thanks,
Vamsi.

Quoted 1 line

<snip patch>

Signature · 5 lines
Vamsi Krishna S.
Linux Technology Center,
IBM Software Lab, Bangalore.
Ph: +91 80 5044959
Internet: [email protected]