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]

Re: [PATCH]Kprobes: fix kprobes reentrancy


On Mon, May 07, 2007 at 09:30:46PM -0700, Keshavamurthy, Anil S wrote:
> On Mon, May 07, 2007 at 10:30:52PM -0400, Frank Ch. Eigler wrote:
> > 
> > > > [PATCH]Kprobes: fix kprobes reentrancy
> > > > From: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
> > > > Date: 2006-12-12
> > > 
> > > This patch still hasn't made it upstream.  Can someone nag akpm etc.?
> > 
> > Can someone advise whether this patch is still worthwhile to push
> > upstream and/or backport into RHEL?
> This patch is not required for i386 and x86_64(as interrupts are
> disabled when int3 exception handler is called) but requied for
> IA64 and for powerpc.
> 
> > 
> > http://sourceware.org/ml/systemtap/2006-q4/msg00659.html
> 
> I will refresh this patch for ia64 and work with Ananth for getting powerpc
> patch worked out and will post the patch before end of this week.

As promised, here is a simple version of the above patch for 
IA64(lightly tested by running the test case attached to BZ 2071
and found no issues with the patch).
A similar patch is required for PPC64 too I think.


Here is the patch, please review.

---
 arch/ia64/kernel/kprobes.c |   12 ++++++++----
 include/asm-ia64/kprobes.h |    4 +++-
 2 files changed, 11 insertions(+), 5 deletions(-)

Index: work/arch/ia64/kernel/kprobes.c
===================================================================
--- work.orig/arch/ia64/kernel/kprobes.c	2007-02-04 10:44:54.000000000 -0800
+++ work/arch/ia64/kernel/kprobes.c	2007-05-08 13:47:34.000000000 -0700
@@ -370,14 +370,18 @@
 
 static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
 {
-	kcb->prev_kprobe.kp = kprobe_running();
-	kcb->prev_kprobe.status = kcb->kprobe_status;
+	unsigned int i;
+	i = atomic_add_return(1, &kcb->prev_kprobe_index);
+	kcb->prev_kprobe[i-1].kp = kprobe_running();
+	kcb->prev_kprobe[i-1].status = kcb->kprobe_status;
 }
 
 static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
 {
-	__get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
-	kcb->kprobe_status = kcb->prev_kprobe.status;
+	unsigned int i;
+	i = atomic_sub_return(1, &kcb->prev_kprobe_index);
+	__get_cpu_var(current_kprobe) = kcb->prev_kprobe[i].kp;
+	kcb->kprobe_status = kcb->prev_kprobe[i].status;
 }
 
 static void __kprobes set_current_kprobe(struct kprobe *p,
Index: work/include/asm-ia64/kprobes.h
===================================================================
--- work.orig/include/asm-ia64/kprobes.h	2007-02-04 10:44:54.000000000 -0800
+++ work/include/asm-ia64/kprobes.h	2007-05-08 13:30:43.000000000 -0700
@@ -71,13 +71,15 @@
 
 #define	MAX_PARAM_RSE_SIZE	(0x60+0x60/0x3f)
 /* per-cpu kprobe control block */
+#define ARCH_PREV_KPROBE_SZ 2
 struct kprobe_ctlblk {
 	unsigned long kprobe_status;
 	struct pt_regs jprobe_saved_regs;
 	unsigned long jprobes_saved_stacked_regs[MAX_PARAM_RSE_SIZE];
 	unsigned long *bsp;
 	unsigned long cfm;
-	struct prev_kprobe prev_kprobe;
+	atomic_t prev_kprobe_index;
+	struct prev_kprobe prev_kprobe[ARCH_PREV_KPROBE_SZ];
 };
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry


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