[PATCH] kprobes: increment kprobe missed count for multiprobes
authorKeshavamurthy Anil S <anil.s.keshavamurthy@intel.com>
Mon, 12 Dec 2005 08:37:34 +0000 (00:37 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 12 Dec 2005 16:57:45 +0000 (08:57 -0800)
When multiple probes are registered at the same address and if due to some
recursion (probe getting triggered within a probe handler), we skip calling
pre_handlers and just increment nmissed field.

The below patch make sure it walks the list for multiple probes case.
Without the below patch we get incorrect results of nmissed count for
multiple probe case.

Signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
arch/i386/kernel/kprobes.c
arch/ia64/kernel/kprobes.c
arch/powerpc/kernel/kprobes.c
arch/sparc64/kernel/kprobes.c
arch/x86_64/kernel/kprobes.c
include/linux/kprobes.h
kernel/kprobes.c

index 32b0c24ab9a6dcca721414a7027635aa06d2c828..19edcd526ba4800f9c71c66ef7ad18da5eb1b7bc 100644 (file)
@@ -191,7 +191,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
                         */
                        save_previous_kprobe(kcb);
                        set_current_kprobe(p, regs, kcb);
-                       p->nmissed++;
+                       kprobes_inc_nmissed_count(p);
                        prepare_singlestep(p, regs);
                        kcb->kprobe_status = KPROBE_REENTER;
                        return 1;
index 2895d6e6062f72df56f7f064fe8057077496c9d1..89a70400c4f638efa3ed6face511777cf90bb5b4 100644 (file)
@@ -630,7 +630,7 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
                         */
                        save_previous_kprobe(kcb);
                        set_current_kprobe(p, kcb);
-                       p->nmissed++;
+                       kprobes_inc_nmissed_count(p);
                        prepare_ss(p, regs);
                        kcb->kprobe_status = KPROBE_REENTER;
                        return 1;
index 511af54e6230ca13eeba65dd7765dcb9f7c8947c..5368f9c2e6bff7707c040812f1260c8269d1373d 100644 (file)
@@ -177,7 +177,7 @@ static inline int kprobe_handler(struct pt_regs *regs)
                        save_previous_kprobe(kcb);
                        set_current_kprobe(p, regs, kcb);
                        kcb->kprobe_saved_msr = regs->msr;
-                       p->nmissed++;
+                       kprobes_inc_nmissed_count(p);
                        prepare_singlestep(p, regs);
                        kcb->kprobe_status = KPROBE_REENTER;
                        return 1;
index 96bd09b098f431876c87778594983f0bf514f85d..a97b0f0727ab15be8ee7678848b5d81ebf282ded 100644 (file)
@@ -138,7 +138,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
                         */
                        save_previous_kprobe(kcb);
                        set_current_kprobe(p, regs, kcb);
-                       p->nmissed++;
+                       kprobes_inc_nmissed_count(p);
                        kcb->kprobe_status = KPROBE_REENTER;
                        prepare_singlestep(p, regs, kcb);
                        return 1;
index dddeb678b440df5782af858f8db64100082c6f8a..afe11f4fbd1d49d068e7bc3fb64f6d759c342ef1 100644 (file)
@@ -329,7 +329,7 @@ int __kprobes kprobe_handler(struct pt_regs *regs)
                                 */
                                save_previous_kprobe(kcb);
                                set_current_kprobe(p, regs, kcb);
-                               p->nmissed++;
+                               kprobes_inc_nmissed_count(p);
                                prepare_singlestep(p, regs);
                                kcb->kprobe_status = KPROBE_REENTER;
                                return 1;
index 434ecfd7cf489d921213e8294da13e3180c6b102..c03f2dc933de04a7503d75f2cacb9fa68963ca13 100644 (file)
@@ -158,6 +158,7 @@ extern int arch_init_kprobes(void);
 extern void show_registers(struct pt_regs *regs);
 extern kprobe_opcode_t *get_insn_slot(void);
 extern void free_insn_slot(kprobe_opcode_t *slot);
+extern void kprobes_inc_nmissed_count(struct kprobe *p);
 
 /* Get the kprobe at this addr (if any) - called with preemption disabled */
 struct kprobe *get_kprobe(void *addr);
index e4f0fc62bd3ecb428b1aef5377557f3e44314d51..3bb71e63a37e0bfa47217c99b2b5e6dbe0a8f2d5 100644 (file)
@@ -246,6 +246,19 @@ static int __kprobes aggr_break_handler(struct kprobe *p, struct pt_regs *regs)
        return ret;
 }
 
+/* Walks the list and increments nmissed count for multiprobe case */
+void __kprobes kprobes_inc_nmissed_count(struct kprobe *p)
+{
+       struct kprobe *kp;
+       if (p->pre_handler != aggr_pre_handler) {
+               p->nmissed++;
+       } else {
+               list_for_each_entry_rcu(kp, &p->list, list)
+                       kp->nmissed++;
+       }
+       return;
+}
+
 /* Called with kretprobe_lock held */
 struct kretprobe_instance __kprobes *get_free_rp_inst(struct kretprobe *rp)
 {