LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH -tip/urgent  0/2]kprobes bugfixes around optprobe
@ 2015-01-23  6:42 Masami Hiramatsu
  2015-01-23  6:42 ` [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization Masami Hiramatsu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2015-01-23  6:42 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: tixy, Wang Nan, linux, Linux Kernel Mailing List, lizefan,
	linux-arm-kernel

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@hitachi.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization.
  2015-01-23  6:42 [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Masami Hiramatsu
@ 2015-01-23  6:42 ` Masami Hiramatsu
  2015-02-05 22:49   ` Andrew Morton
  2015-01-23  6:42 ` [PATCH -tip/urgent 2/2] [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes Masami Hiramatsu
  2015-01-26  5:38 ` [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Wang Nan
  2 siblings, 1 reply; 7+ messages in thread
From: Masami Hiramatsu @ 2015-01-23  6:42 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: tixy, Wang Nan, linux, Linux Kernel Mailing List, lizefan,
	linux-arm-kernel

From: Wang Nan <wangnan0@huawei.com>

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.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 kernel/kprobes.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 06f5830..9471710 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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:


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH -tip/urgent 2/2] [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes.
  2015-01-23  6:42 [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Masami Hiramatsu
  2015-01-23  6:42 ` [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization Masami Hiramatsu
@ 2015-01-23  6:42 ` Masami Hiramatsu
  2015-01-26  5:38 ` [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Wang Nan
  2 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2015-01-23  6:42 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: tixy, Wang Nan, linux, Linux Kernel Mailing List, lizefan,
	linux-arm-kernel

From: Wang Nan <wangnan0@huawei.com>

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.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 kernel/kprobes.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 9471710..fb995ef 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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;
 		}
 	}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip/urgent  0/2]kprobes bugfixes around optprobe
  2015-01-23  6:42 [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Masami Hiramatsu
  2015-01-23  6:42 ` [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization Masami Hiramatsu
  2015-01-23  6:42 ` [PATCH -tip/urgent 2/2] [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes Masami Hiramatsu
@ 2015-01-26  5:38 ` Wang Nan
  2015-02-04 11:01   ` Wang Nan
  2 siblings, 1 reply; 7+ messages in thread
From: Wang Nan @ 2015-01-26  5:38 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Masami Hiramatsu, tixy, linux, Linux Kernel Mailing List,
	lizefan, linux-arm-kernel

Hi Ingo,

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

Thank you.

On 2015/1/23 14:42, Masami Hiramatsu wrote:
> 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@hitachi.com
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip/urgent  0/2]kprobes bugfixes around optprobe
  2015-01-26  5:38 ` [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Wang Nan
@ 2015-02-04 11:01   ` Wang Nan
  2015-02-05  1:59     ` Wang Nan
  0 siblings, 1 reply; 7+ messages in thread
From: Wang Nan @ 2015-02-04 11:01 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: tixy, linux, Linux Kernel Mailing List, lizefan,
	Masami Hiramatsu, linux-arm-kernel

Hi Ingo (and others),

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

Thanks!

On 2015/1/26 13:38, Wang Nan wrote:
> Hi Ingo,
> 
> Is there any problem on these patches? I'm unable to find them in upstream kernel
> and -tip repository.
> 
> Thank you.
> 
> On 2015/1/23 14:42, Masami Hiramatsu wrote:
>> 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@hitachi.com
>>
> 
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip/urgent  0/2]kprobes bugfixes around optprobe
  2015-02-04 11:01   ` Wang Nan
@ 2015-02-05  1:59     ` Wang Nan
  0 siblings, 0 replies; 7+ messages in thread
From: Wang Nan @ 2015-02-05  1:59 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Ingo Molnar, tixy, linux, Linux Kernel Mailing List, lizefan,
	Masami Hiramatsu, linux-arm-kernel

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.

On 2015/2/4 19:01, Wang Nan wrote:
> Hi Ingo (and others),
> 
> These 2 bugs still exist in mainline kernel. Could you please have a look at them?
> 
> Thanks!
> 
> On 2015/1/26 13:38, Wang Nan wrote:
>> Hi Ingo,
>>
>> Is there any problem on these patches? I'm unable to find them in upstream kernel
>> and -tip repository.
>>
>> Thank you.
>>
>> On 2015/1/23 14:42, Masami Hiramatsu wrote:
>>> 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@hitachi.com
>>>
>>
>>
>>
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@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@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization.
  2015-01-23  6:42 ` [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization Masami Hiramatsu
@ 2015-02-05 22:49   ` Andrew Morton
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2015-02-05 22:49 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, tixy, Wang Nan, linux, Linux Kernel Mailing List,
	lizefan, linux-arm-kernel

On Fri, 23 Jan 2015 15:42:24 +0900 Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> wrote:

> From: Wang Nan <wangnan0@huawei.com>
> 
> 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.
> 
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-02-05 22:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23  6:42 [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Masami Hiramatsu
2015-01-23  6:42 ` [PATCH -tip/urgent 1/2] [BUGFIX]kprobes: set kprobes_all_disarmed earlier to enable re-optimization Masami Hiramatsu
2015-02-05 22:49   ` Andrew Morton
2015-01-23  6:42 ` [PATCH -tip/urgent 2/2] [BUGFIX]kprobes: makes kprobes/enabled works correctly for optimized kprobes Masami Hiramatsu
2015-01-26  5:38 ` [PATCH -tip/urgent 0/2]kprobes bugfixes around optprobe Wang Nan
2015-02-04 11:01   ` Wang Nan
2015-02-05  1:59     ` Wang Nan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).