Skip to content

Commit 0490cd1

Browse files
mhiramathitachiIngo Molnar
authored andcommitted
kprobes: Reuse unused kprobe
Reuse unused (waiting for unoptimizing and no user handler) kprobe on given address instead of returning -EBUSY for registering a new kprobe. Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Cc: Jason Baron <jbaron@redhat.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: 2nddept-manager@sdl.hitachi.co.jp LKML-Reference: <20101203095416.2961.39080.stgit@ltc236.sdl.hitachi.co.jp> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 6274de4 commit 0490cd1

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

‎kernel/kprobes.c‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,27 @@ static __kprobes void unoptimize_kprobe(struct kprobe *p, bool force)
692692
}
693693
}
694694

695+
/* Cancel unoptimizing for reusing */
696+
static void reuse_unused_kprobe(struct kprobe *ap)
697+
{
698+
struct optimized_kprobe *op;
699+
700+
BUG_ON(!kprobe_unused(ap));
701+
/*
702+
* Unused kprobe MUST be on the way of delayed unoptimizing (means
703+
* there is still a relative jump) and disabled.
704+
*/
705+
op = container_of(ap, struct optimized_kprobe, kp);
706+
if (unlikely(list_empty(&op->list)))
707+
printk(KERN_WARNING "Warning: found a stray unused "
708+
"aggrprobe@%p\n", ap->addr);
709+
/* Enable the probe again */
710+
ap->flags &= ~KPROBE_FLAG_DISABLED;
711+
/* Optimize it again (remove from op->list) */
712+
BUG_ON(!kprobe_optready(ap));
713+
optimize_kprobe(ap);
714+
}
715+
695716
/* Remove optimized instructions */
696717
static void __kprobes kill_optimized_kprobe(struct kprobe *p)
697718
{
@@ -872,6 +893,13 @@ static void __kprobes __disarm_kprobe(struct kprobe *p, bool reopt)
872893
#define kprobe_disarmed(p) kprobe_disabled(p)
873894
#define wait_for_kprobe_optimizer() do {} while (0)
874895

896+
/* There should be no unused kprobes can be reused without optimization */
897+
static void reuse_unused_kprobe(struct kprobe *ap)
898+
{
899+
printk(KERN_ERR "Error: There should be no unused kprobe here.\n");
900+
BUG_ON(kprobe_unused(ap));
901+
}
902+
875903
static __kprobes void free_aggr_kprobe(struct kprobe *p)
876904
{
877905
arch_remove_kprobe(p);
@@ -1173,8 +1201,8 @@ static int __kprobes register_aggr_kprobe(struct kprobe *orig_p,
11731201
return -ENOMEM;
11741202
init_aggr_kprobe(ap, orig_p);
11751203
} else if (kprobe_unused(ap))
1176-
/* Busy to die */
1177-
return -EBUSY;
1204+
/* This probe is going to die. Rescue it */
1205+
reuse_unused_kprobe(ap);
11781206

11791207
if (kprobe_gone(ap)) {
11801208
/*

0 commit comments

Comments
 (0)