Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61f4e13f authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Ingo Molnar
Browse files

kprobes: Separate kprobe optimizing code from optimizer



Separate kprobe optimizing code from optimizer, this
will make easy to introducing unoptimizing code in
optimizer.

Signed-off-by: default avatarMasami 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: <20101203095403.2961.91201.stgit@ltc236.sdl.hitachi.co.jp>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 6f0f1dd7
Loading
Loading
Loading
Loading
+26 −17
Original line number Diff line number Diff line
@@ -427,25 +427,13 @@ static void kprobe_optimizer(struct work_struct *work);
static DECLARE_DELAYED_WORK(optimizing_work, kprobe_optimizer);
#define OPTIMIZE_DELAY 5

/* Kprobe jump optimizer */
static __kprobes void kprobe_optimizer(struct work_struct *work)
{
	struct optimized_kprobe *op, *tmp;

	/* Lock modules while optimizing kprobes */
	mutex_lock(&module_mutex);
	mutex_lock(&kprobe_mutex);
	if (kprobes_all_disarmed || !kprobes_allow_optimization)
		goto end;

/*
	 * Wait for quiesence period to ensure all running interrupts
	 * are done. Because optprobe may modify multiple instructions
	 * there is a chance that Nth instruction is interrupted. In that
	 * case, running interrupt can return to 2nd-Nth byte of jump
	 * instruction. This wait is for avoiding it.
 * Optimize (replace a breakpoint with a jump) kprobes listed on
 * optimizing_list.
 */
	synchronize_sched();
static __kprobes void do_optimize_kprobes(void)
{
	struct optimized_kprobe *op, *tmp;

	/*
	 * The optimization/unoptimization refers online_cpus via
@@ -467,6 +455,27 @@ static __kprobes void kprobe_optimizer(struct work_struct *work)
	}
	mutex_unlock(&text_mutex);
	put_online_cpus();
}

/* Kprobe jump optimizer */
static __kprobes void kprobe_optimizer(struct work_struct *work)
{
	/* Lock modules while optimizing kprobes */
	mutex_lock(&module_mutex);
	mutex_lock(&kprobe_mutex);
	if (kprobes_all_disarmed || !kprobes_allow_optimization)
		goto end;

	/*
	 * Wait for quiesence period to ensure all running interrupts
	 * are done. Because optprobe may modify multiple instructions
	 * there is a chance that Nth instruction is interrupted. In that
	 * case, running interrupt can return to 2nd-Nth byte of jump
	 * instruction. This wait is for avoiding it.
	 */
	synchronize_sched();

	do_optimize_kprobes();
end:
	mutex_unlock(&kprobe_mutex);
	mutex_unlock(&module_mutex);