public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
	mathieu.desnoyers@efficios.com, rusty@rustcorp.com.au,
	ananth@in.ibm.com, masami.hiramatsu.pt@hitachi.com,
	fweisbec@gmail.com, tglx@linutronix.de, jbaron@redhat.com,
	mingo@elte.hu
Subject: [tip:perf/core] kprobes: Reuse unused kprobe
Date: Mon, 6 Dec 2010 18:17:12 GMT	[thread overview]
Message-ID: <tip-0490cd1f9d99569d3bd64e17adc88db06a5007be@git.kernel.org> (raw)
In-Reply-To: <20101203095416.2961.39080.stgit@ltc236.sdl.hitachi.co.jp>

Commit-ID:  0490cd1f9d99569d3bd64e17adc88db06a5007be
Gitweb:     http://git.kernel.org/tip/0490cd1f9d99569d3bd64e17adc88db06a5007be
Author:     Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
AuthorDate: Fri, 3 Dec 2010 18:54:16 +0900
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 6 Dec 2010 17:59:31 +0100

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>
---
 kernel/kprobes.c |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index ba4d4c0..134754d 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -692,6 +692,27 @@ static __kprobes void unoptimize_kprobe(struct kprobe *p, bool force)
 	}
 }
 
+/* Cancel unoptimizing for reusing */
+static void reuse_unused_kprobe(struct kprobe *ap)
+{
+	struct optimized_kprobe *op;
+
+	BUG_ON(!kprobe_unused(ap));
+	/*
+	 * Unused kprobe MUST be on the way of delayed unoptimizing (means
+	 * there is still a relative jump) and disabled.
+	 */
+	op = container_of(ap, struct optimized_kprobe, kp);
+	if (unlikely(list_empty(&op->list)))
+		printk(KERN_WARNING "Warning: found a stray unused "
+			"aggrprobe@%p\n", ap->addr);
+	/* Enable the probe again */
+	ap->flags &= ~KPROBE_FLAG_DISABLED;
+	/* Optimize it again (remove from op->list) */
+	BUG_ON(!kprobe_optready(ap));
+	optimize_kprobe(ap);
+}
+
 /* Remove optimized instructions */
 static void __kprobes kill_optimized_kprobe(struct kprobe *p)
 {
@@ -872,6 +893,13 @@ static void __kprobes __disarm_kprobe(struct kprobe *p, bool reopt)
 #define kprobe_disarmed(p)			kprobe_disabled(p)
 #define wait_for_kprobe_optimizer()		do {} while (0)
 
+/* There should be no unused kprobes can be reused without optimization */
+static void reuse_unused_kprobe(struct kprobe *ap)
+{
+	printk(KERN_ERR "Error: There should be no unused kprobe here.\n");
+	BUG_ON(kprobe_unused(ap));
+}
+
 static __kprobes void free_aggr_kprobe(struct kprobe *p)
 {
 	arch_remove_kprobe(p);
@@ -1173,8 +1201,8 @@ static int __kprobes register_aggr_kprobe(struct kprobe *orig_p,
 			return -ENOMEM;
 		init_aggr_kprobe(ap, orig_p);
 	} else if (kprobe_unused(ap))
-		/* Busy to die */
-		return -EBUSY;
+		/* This probe is going to die. Rescue it */
+		reuse_unused_kprobe(ap);
 
 	if (kprobe_gone(ap)) {
 		/*

  reply	other threads:[~2010-12-06 18:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-03  9:53 [PATCH -tip v5 0/8] Kprobes/x86: Batch optimization support Masami Hiramatsu
2010-12-03  9:53 ` [PATCH -tip v5 1/8] [CLEANUP] kprobes: Rename old_p to more appropriate name Masami Hiramatsu
2010-12-06 18:15   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-12-03  9:53 ` [PATCH -tip v5 2/8] [CLEANUP]kprobes: Cleanup disabling and unregistering path Masami Hiramatsu
2010-12-06 18:16   ` [tip:perf/core] kprobes: " tip-bot for Masami Hiramatsu
2010-12-03  9:54 ` [PATCH -tip v5 3/8] [CLEANUP]kprobes: Separate kprobe optimizing code from optimizer Masami Hiramatsu
2010-12-06 18:16   ` [tip:perf/core] kprobes: " tip-bot for Masami Hiramatsu
2010-12-03  9:54 ` [PATCH -tip v5 4/8] kprobes: Support delayed unoptimizing Masami Hiramatsu
2010-12-06 18:16   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-12-03  9:54 ` [PATCH -tip v5 5/8] kprobes: Reuse unused kprobe Masami Hiramatsu
2010-12-06 18:17   ` tip-bot for Masami Hiramatsu [this message]
2010-12-03  9:54 ` [PATCH -tip v5 6/8] x86: Introduce text_poke_smp_batch() for batch-code modifying Masami Hiramatsu
2010-12-03 14:44   ` Steven Rostedt
2010-12-06 18:17   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2011-02-11 21:07     ` Peter Zijlstra
2011-02-12  1:36       ` [tip:perf/urgent] x86: Fix text_poke_smp_batch() deadlock tip-bot for Peter Zijlstra
2011-02-14  1:25       ` [tip:perf/core] x86: Introduce text_poke_smp_batch() for batch-code modifying Masami Hiramatsu
2010-12-03  9:54 ` [PATCH -tip v5 7/8] kprobes: Use text_poke_smp_batch for optimizing Masami Hiramatsu
2010-12-06 18:17   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2010-12-03  9:54 ` [PATCH -tip v5 8/8] kprobes: Use text_poke_smp_batch for unoptimizing Masami Hiramatsu
2010-12-06 18:18   ` [tip:perf/core] " tip-bot for Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-0490cd1f9d99569d3bd64e17adc88db06a5007be@git.kernel.org \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=ananth@in.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jbaron@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox