Skip to contentSkip to conversation

kprobes bugfixes around optprobe

PATCH In review Masami Hiramatsu 3 participants 7 messages Jan 23, 2015 – Feb 5, 2015 kprobes

lore
Share & tools
lore
#0 lore raw

cover kprobes bugfixes around optprobe

Hi Ingo,

Here are two patches for fixing bugs in kprobes, related to optprobe and enable/disable kprobe knob.

These are reported and fixed by Wang Nan.
https://lkml.org/lkml/2015/1/5/270
https://lkml.org/lkml/2015/1/19/680

Thank you,

---

Wang Nan (2):
[BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization. [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes.

 kernel/kprobes.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

--
Masami HIRAMATSU
Software Platform Research Dpt. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt at hitachi.com

#1 lore raw

PATCH 1/2 kprobes: set kprobes_all_disarmed earlier to enable re-optimization.

From: Wang Nan <[email protected]>

In original code, the probed instruction doesn't get optimized after

echo 0 > /sys/kernel/debug/kprobes/enabled
echo 1 > /sys/kernel/debug/kprobes/enabled

This is because original code checks kprobes_all_disarmed in optimize_kprobe(), but this flag is turned off after calling that function. Therefore, optimize_kprobe() will see kprobes_all_disarmed == true and doesn't do the optimization.

This patch simply turns off kprobes_all_disarmed earlier to enable optimization.

---
 kernel/kprobes.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/kprobes.c +6 -1
index 06f5830..9471710 100644
@@ -2320,6 +2320,12 @@ static void arm_all_kprobes(void)
 	if (!kprobes_all_disarmed)
 		goto already_enabled;
 
+	/*
+	 * optimize_kprobe() called by arm_kprobe() checks
+	 * kprobes_all_disarmed, so set kprobes_all_disarmed before
+	 * arm_kprobe.
+	 */
+	kprobes_all_disarmed = false;
 	/* Arming kprobes doesn't optimize kprobe itself */
 	for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
 		head = &kprobe_table[i];
@@ -2328,7 +2334,6 @@ static void arm_all_kprobes(void)
 				arm_kprobe(p);
 	}
 
-	kprobes_all_disarmed = false;
 	printk(KERN_INFO "Kprobes globally enabled\n");
 
 already_enabled:
#2 lore raw

Re: [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization.

Quoted 12 lines · On Fri, 23 Jan 2015 15:42:24 +0900 Masami Hiramatsu…

From: Wang Nan <[email protected]>

In original code, the probed instruction doesn't get optimized after

echo 0 > /sys/kernel/debug/kprobes/enabled
echo 1 > /sys/kernel/debug/kprobes/enabled

This is because original code checks kprobes_all_disarmed in optimize_kprobe(), but this flag is turned off after calling that function. Therefore, optimize_kprobe() will see kprobes_all_disarmed == true and doesn't do the optimization.

Quoted 5 lines

This patch simply turns off kprobes_all_disarmed earlier to enable optimization.

You sent the patches, so this should have been "Signed-off-by:". Documentation/SubmittingPatches section 12 has the details.

I have made that change to my copy of these two patches.

#3 lore raw

PATCH 2/2 kprobes: makes kprobes/enabled works correctly for optimized kprobes.

In reply to Masami Hiramatsu

From: Wang Nan <[email protected]>

debugfs/kprobes/enabled doesn't work correctly on optimized kprobes. Masami Hiramatsu has a test report on x86_64 platform:

https://lkml.org/lkml/2015/1/19/274

This patch forces it to unoptimize kprobe if kprobes_all_disarmed is set. It also checks the flag in unregistering path for skipping unneeded disarming process when kprobes globally disarmed.

---
 kernel/kprobes.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/kprobes.c +9 -2
index 9471710..fb995ef 100644
@@ -869,7 +869,8 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt)
 {
 	struct kprobe *_p;
 
-	unoptimize_kprobe(p, false);	/* Try to unoptimize */
+	/* Try to unoptimize */
+	unoptimize_kprobe(p, kprobes_all_disarmed);
 
 	if (!kprobe_queued(p)) {
 		arch_disarm_kprobe(p);
@@ -1571,7 +1572,13 @@ static struct kprobe *__disable_kprobe(struct kprobe *p)
 
 		/* Try to disarm and disable this/parent probe */
 		if (p == orig_p || aggr_kprobe_disabled(orig_p)) {
-			disarm_kprobe(orig_p, true);
+			/*
+			 * If kprobes_all_disarmed is set, orig_p
+			 * should have already been disarmed, so
+			 * skip unneed disarming process.
+			 */
+			if (!kprobes_all_disarmed)
+				disarm_kprobe(orig_p, true);
 			orig_p->flags |= KPROBE_FLAG_DISABLED;
 		}
 	}
#4 lore raw
In reply to Masami Hiramatsu

Hi Ingo,

Is there any problem on these patches? I'm unable to find them in upstream kernel and -tip repository.

Thank you.

Quoted 28 lines · Masami Hiramatsu

Hi Ingo,

Here are two patches for fixing bugs in kprobes, related to optprobe and enable/disable kprobe knob.

These are reported and fixed by Wang Nan.
https://lkml.org/lkml/2015/1/5/270
https://lkml.org/lkml/2015/1/19/680

Thank you,

---

Wang Nan (2):
[BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization. [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes.

 kernel/kprobes.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

--
Masami HIRAMATSU
Software Platform Research Dpt. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt at hitachi.com

#5 lore raw

Hi Ingo (and others),

These 2 bugs still exist in mainline kernel. Could you please have a look at them?

Thanks!

Quoted 44 lines · Wang Nan

Hi Ingo,

Is there any problem on these patches? I'm unable to find them in upstream kernel and -tip repository.

Thank you.

Quoted 19 lines · Masami Hiramatsu

Hi Ingo,

Here are two patches for fixing bugs in kprobes, related to optprobe and enable/disable kprobe knob.

These are reported and fixed by Wang Nan.
https://lkml.org/lkml/2015/1/5/270
https://lkml.org/lkml/2015/1/19/680

Thank you,

---

Wang Nan (2):
[BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization. [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes.

Quoted 9 lines
 kernel/kprobes.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

--
Masami HIRAMATSU
Software Platform Research Dpt. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt at hitachi.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw

Hi Andrew,

These 2 perf related bugfixs has been acked by Masami Hiramatsu and cc-ed to Ingo serval weeks ago, but he is not responsive. Could you please help us collect them into your tree?

Thank you.

Quoted 59 lines · Wang Nan

Hi Ingo (and others),

These 2 bugs still exist in mainline kernel. Could you please have a look at them?

Thanks!

Quoted 39 lines · Wang Nan

Hi Ingo,

Is there any problem on these patches? I'm unable to find them in upstream kernel and -tip repository.

Thank you.

Quoted 19 lines · Masami Hiramatsu

Hi Ingo,

Here are two patches for fixing bugs in kprobes, related to optprobe and enable/disable kprobe knob.

These are reported and fixed by Wang Nan.
https://lkml.org/lkml/2015/1/5/270
https://lkml.org/lkml/2015/1/19/680

Thank you,

---

Wang Nan (2):
[BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization. [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes.

Quoted 9 lines
 kernel/kprobes.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

--
Masami HIRAMATSU
Software Platform Research Dpt. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt at hitachi.com

Quoted 5 lines

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/