linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kmemcheck: move hook before preempt_conditional_sti()
@ 2009-06-07 16:26 Vegard Nossum
  2009-06-07 16:45 ` Ingo Molnar
  2009-06-08  6:41 ` Ananth N Mavinakayanahalli
  0 siblings, 2 replies; 6+ messages in thread
From: Vegard Nossum @ 2009-06-07 16:26 UTC (permalink / raw)
  Cc: linux-kernel, Vegard Nossum, Alexander van Heukelum, K.Prasad,
	Alan Stern, Frederic Weisbecker, Pekka Enberg

There are actually two problems here:

1. We absolutely cannot enable IRQs in case the fault was caused by
   kmemcheck.

2. We cannot enable preemption and then return from the debug handler
   without disabling preemption afterwards.

The problem seems to be a merge fallout between three commits:

commit 3d2a71a596bd9c761c8487a2178e95f8a61da083
Author: Alexander van Heukelum <heukelum@fastmail.fm>
Date:   Tue Sep 30 18:41:37 2008 +0200

    x86, traps: converge do_debug handlers

commit 08d68323d1f0c34452e614263b212ca556dae47f
Author: K.Prasad <prasad@linux.vnet.ibm.com>
Date:   Mon Jun 1 23:44:08 2009 +0530

    hw-breakpoints: modifying generic debug exception to use thread-specific deb

commit 787ecfaa503dc63ff1831ddc74b15dad49bace1d
Author: Vegard Nossum <vegard.nossum@gmail.com>
Date:   Fri Apr 4 00:53:23 2008 +0200

    x86: add hooks for kmemcheck

I encourage the kprobe developers to check whether their code is correct
as it stands in current tip/master. Also, comments on this particular
change is welcome.

Reported-by: Ingo Molnar <mingo@elte.hu>
Cc: Alexander van Heukelum <heukelum@fastmail.fm>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
---
 arch/x86/kernel/traps.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index c8a7f87..a898c6b 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -550,6 +550,10 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
 							SIGTRAP) == NOTIFY_STOP)
 		return;
 
+	/* Catch kmemcheck conditions first of all! */
+	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
+		return;
+
 	/* It's safe to allow irq's after DR6 has been saved */
 	preempt_conditional_sti(regs);
 
@@ -559,10 +563,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
 		return;
 	}
 
-	/* Catch kmemcheck conditions first of all! */
-	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
-		return;
-
 	/*
 	 * Single-stepping through system calls: ignore any exceptions in
 	 * kernel space, but re-enable TF when returning to user mode.
-- 
1.6.0.6


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

* Re: [PATCH] kmemcheck: move hook before preempt_conditional_sti()
  2009-06-07 16:26 [PATCH] kmemcheck: move hook before preempt_conditional_sti() Vegard Nossum
@ 2009-06-07 16:45 ` Ingo Molnar
  2009-06-07 17:25   ` Vegard Nossum
  2009-06-08  6:41 ` Ananth N Mavinakayanahalli
  1 sibling, 1 reply; 6+ messages in thread
From: Ingo Molnar @ 2009-06-07 16:45 UTC (permalink / raw)
  To: Vegard Nossum
  Cc: linux-kernel, Alexander van Heukelum, K.Prasad, Alan Stern,
	Frederic Weisbecker, Pekka Enberg


* Vegard Nossum <vegard.nossum@gmail.com> wrote:

> There are actually two problems here:
> 
> 1. We absolutely cannot enable IRQs in case the fault was caused by
>    kmemcheck.
> 
> 2. We cannot enable preemption and then return from the debug handler
>    without disabling preemption afterwards.
> 
> The problem seems to be a merge fallout between three commits:
> 
> commit 3d2a71a596bd9c761c8487a2178e95f8a61da083
> Author: Alexander van Heukelum <heukelum@fastmail.fm>
> Date:   Tue Sep 30 18:41:37 2008 +0200
> 
>     x86, traps: converge do_debug handlers
> 
> commit 08d68323d1f0c34452e614263b212ca556dae47f
> Author: K.Prasad <prasad@linux.vnet.ibm.com>
> Date:   Mon Jun 1 23:44:08 2009 +0530
> 
>     hw-breakpoints: modifying generic debug exception to use thread-specific deb
> 
> commit 787ecfaa503dc63ff1831ddc74b15dad49bace1d
> Author: Vegard Nossum <vegard.nossum@gmail.com>
> Date:   Fri Apr 4 00:53:23 2008 +0200
> 
>     x86: add hooks for kmemcheck
> 
> I encourage the kprobe developers to check whether their code is correct
> as it stands in current tip/master. Also, comments on this particular
> change is welcome.
> 
> Reported-by: Ingo Molnar <mingo@elte.hu>
> Cc: Alexander van Heukelum <heukelum@fastmail.fm>
> Cc: K.Prasad <prasad@linux.vnet.ibm.com>
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Pekka Enberg <penberg@cs.helsinki.fi>
> Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> ---
>  arch/x86/kernel/traps.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)

> 
> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> index c8a7f87..a898c6b 100644
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -550,6 +550,10 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
>  							SIGTRAP) == NOTIFY_STOP)
>  		return;
>  
> +	/* Catch kmemcheck conditions first of all! */
> +	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
> +		return;
> +
>  	/* It's safe to allow irq's after DR6 has been saved */
>  	preempt_conditional_sti(regs);
>  
> @@ -559,10 +563,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
>  		return;
>  	}
>  
> -	/* Catch kmemcheck conditions first of all! */
> -	if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
> -		return;
> -
>  	/*
>  	 * Single-stepping through system calls: ignore any exceptions in
>  	 * kernel space, but re-enable TF when returning to user mode.

Yeah - this could solve the crash i saw. Mind sending a pull request 
too?

	Ingo

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

* Re: [PATCH] kmemcheck: move hook before preempt_conditional_sti()
  2009-06-07 16:45 ` Ingo Molnar
@ 2009-06-07 17:25   ` Vegard Nossum
  2009-06-07 17:52     ` Ingo Molnar
  0 siblings, 1 reply; 6+ messages in thread
From: Vegard Nossum @ 2009-06-07 17:25 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Alexander van Heukelum, K.Prasad, Alan Stern,
	Frederic Weisbecker, Pekka Enberg

2009/6/7 Ingo Molnar <mingo@elte.hu>:
>
> * Vegard Nossum <vegard.nossum@gmail.com> wrote:
>
>> There are actually two problems here:
>>
>> 1. We absolutely cannot enable IRQs in case the fault was caused by
>>    kmemcheck.
>>
>> 2. We cannot enable preemption and then return from the debug handler
>>    without disabling preemption afterwards.
>>
>> The problem seems to be a merge fallout between three commits:
>>
>> commit 3d2a71a596bd9c761c8487a2178e95f8a61da083
>> Author: Alexander van Heukelum <heukelum@fastmail.fm>
>> Date:   Tue Sep 30 18:41:37 2008 +0200
>>
>>     x86, traps: converge do_debug handlers
>>
>> commit 08d68323d1f0c34452e614263b212ca556dae47f
>> Author: K.Prasad <prasad@linux.vnet.ibm.com>
>> Date:   Mon Jun 1 23:44:08 2009 +0530
>>
>>     hw-breakpoints: modifying generic debug exception to use thread-specific deb
>>
>> commit 787ecfaa503dc63ff1831ddc74b15dad49bace1d
>> Author: Vegard Nossum <vegard.nossum@gmail.com>
>> Date:   Fri Apr 4 00:53:23 2008 +0200
>>
>>     x86: add hooks for kmemcheck
>>
>> I encourage the kprobe developers to check whether their code is correct
>> as it stands in current tip/master. Also, comments on this particular
>> change is welcome.
>>
>> Reported-by: Ingo Molnar <mingo@elte.hu>
>> Cc: Alexander van Heukelum <heukelum@fastmail.fm>
>> Cc: K.Prasad <prasad@linux.vnet.ibm.com>
>> Cc: Alan Stern <stern@rowland.harvard.edu>
>> Cc: Frederic Weisbecker <fweisbec@gmail.com>
>> Cc: Pekka Enberg <penberg@cs.helsinki.fi>
>> Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
>> ---
>>  arch/x86/kernel/traps.c |    8 ++++----
>>  1 files changed, 4 insertions(+), 4 deletions(-)
>
>>
>> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
>> index c8a7f87..a898c6b 100644
>> --- a/arch/x86/kernel/traps.c
>> +++ b/arch/x86/kernel/traps.c
>> @@ -550,6 +550,10 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
>>                                                       SIGTRAP) == NOTIFY_STOP)
>>               return;
>>
>> +     /* Catch kmemcheck conditions first of all! */
>> +     if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
>> +             return;
>> +
>>       /* It's safe to allow irq's after DR6 has been saved */
>>       preempt_conditional_sti(regs);
>>
>> @@ -559,10 +563,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
>>               return;
>>       }
>>
>> -     /* Catch kmemcheck conditions first of all! */
>> -     if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
>> -             return;
>> -
>>       /*
>>        * Single-stepping through system calls: ignore any exceptions in
>>        * kernel space, but re-enable TF when returning to user mode.
>
> Yeah - this could solve the crash i saw. Mind sending a pull request
> too?

It did solve it, I tested it :-D

This patch was against tip/master; tip/kmemcheck does not have the
problem. I think it might have been introduced in this merge:

commit 85b9b2801e46a147330b8a0f321bc40342ff5b4c
Merge: bf8d9b3... 7387400...
Author: Ingo Molnar <mingo@elte.hu>
Date:   Thu Jun 4 13:56:43 2009 +0200

    Merge branch 'tracing/hw-breakpoints'

    Conflicts:
        arch/x86/Kconfig
        arch/x86/kernel/traps.c
        kernel/Makefile


Vegard

-- 
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036

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

* Re: [PATCH] kmemcheck: move hook before preempt_conditional_sti()
  2009-06-07 17:25   ` Vegard Nossum
@ 2009-06-07 17:52     ` Ingo Molnar
  0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2009-06-07 17:52 UTC (permalink / raw)
  To: Vegard Nossum
  Cc: linux-kernel, Alexander van Heukelum, K.Prasad, Alan Stern,
	Frederic Weisbecker, Pekka Enberg


* Vegard Nossum <vegard.nossum@gmail.com> wrote:

> 2009/6/7 Ingo Molnar <mingo@elte.hu>:
> >
> > * Vegard Nossum <vegard.nossum@gmail.com> wrote:
> >
> >> There are actually two problems here:
> >>
> >> 1. We absolutely cannot enable IRQs in case the fault was caused by
> >>    kmemcheck.
> >>
> >> 2. We cannot enable preemption and then return from the debug handler
> >>    without disabling preemption afterwards.
> >>
> >> The problem seems to be a merge fallout between three commits:
> >>
> >> commit 3d2a71a596bd9c761c8487a2178e95f8a61da083
> >> Author: Alexander van Heukelum <heukelum@fastmail.fm>
> >> Date:   Tue Sep 30 18:41:37 2008 +0200
> >>
> >>     x86, traps: converge do_debug handlers
> >>
> >> commit 08d68323d1f0c34452e614263b212ca556dae47f
> >> Author: K.Prasad <prasad@linux.vnet.ibm.com>
> >> Date:   Mon Jun 1 23:44:08 2009 +0530
> >>
> >>     hw-breakpoints: modifying generic debug exception to use thread-specific deb
> >>
> >> commit 787ecfaa503dc63ff1831ddc74b15dad49bace1d
> >> Author: Vegard Nossum <vegard.nossum@gmail.com>
> >> Date:   Fri Apr 4 00:53:23 2008 +0200
> >>
> >>     x86: add hooks for kmemcheck
> >>
> >> I encourage the kprobe developers to check whether their code is correct
> >> as it stands in current tip/master. Also, comments on this particular
> >> change is welcome.
> >>
> >> Reported-by: Ingo Molnar <mingo@elte.hu>
> >> Cc: Alexander van Heukelum <heukelum@fastmail.fm>
> >> Cc: K.Prasad <prasad@linux.vnet.ibm.com>
> >> Cc: Alan Stern <stern@rowland.harvard.edu>
> >> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> >> Cc: Pekka Enberg <penberg@cs.helsinki.fi>
> >> Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> >> ---
> >>  arch/x86/kernel/traps.c |    8 ++++----
> >>  1 files changed, 4 insertions(+), 4 deletions(-)
> >
> >>
> >> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> >> index c8a7f87..a898c6b 100644
> >> --- a/arch/x86/kernel/traps.c
> >> +++ b/arch/x86/kernel/traps.c
> >> @@ -550,6 +550,10 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
> >>                                                       SIGTRAP) == NOTIFY_STOP)
> >>               return;
> >>
> >> +     /* Catch kmemcheck conditions first of all! */
> >> +     if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
> >> +             return;
> >> +
> >>       /* It's safe to allow irq's after DR6 has been saved */
> >>       preempt_conditional_sti(regs);
> >>
> >> @@ -559,10 +563,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
> >>               return;
> >>       }
> >>
> >> -     /* Catch kmemcheck conditions first of all! */
> >> -     if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
> >> -             return;
> >> -
> >>       /*
> >>        * Single-stepping through system calls: ignore any exceptions in
> >>        * kernel space, but re-enable TF when returning to user mode.
> >
> > Yeah - this could solve the crash i saw. Mind sending a pull request
> > too?
> 
> It did solve it, I tested it :-D
> 
> This patch was against tip/master; tip/kmemcheck does not have the
> problem. I think it might have been introduced in this merge:
> 
> commit 85b9b2801e46a147330b8a0f321bc40342ff5b4c
> Merge: bf8d9b3... 7387400...
> Author: Ingo Molnar <mingo@elte.hu>
> Date:   Thu Jun 4 13:56:43 2009 +0200
> 
>     Merge branch 'tracing/hw-breakpoints'
> 
>     Conflicts:
>         arch/x86/Kconfig
>         arch/x86/kernel/traps.c
>         kernel/Makefile

Ah. kmemcheck + hw-breakpoints interaction. Fun.

	Ingo

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

* Re: [PATCH] kmemcheck: move hook before preempt_conditional_sti()
  2009-06-07 16:26 [PATCH] kmemcheck: move hook before preempt_conditional_sti() Vegard Nossum
  2009-06-07 16:45 ` Ingo Molnar
@ 2009-06-08  6:41 ` Ananth N Mavinakayanahalli
  2009-06-08 19:46   ` Masami Hiramatsu
  1 sibling, 1 reply; 6+ messages in thread
From: Ananth N Mavinakayanahalli @ 2009-06-08  6:41 UTC (permalink / raw)
  To: Vegard Nossum
  Cc: linux-kernel, Alexander van Heukelum, K.Prasad, Alan Stern,
	Frederic Weisbecker, Pekka Enberg, Masami Hiramatsu

On Sun, Jun 07, 2009 at 06:26:52PM +0200, Vegard Nossum wrote:
> There are actually two problems here:
> 
> 1. We absolutely cannot enable IRQs in case the fault was caused by
>    kmemcheck.
> 
> 2. We cannot enable preemption and then return from the debug handler
>    without disabling preemption afterwards.
> 
> The problem seems to be a merge fallout between three commits:
> 
> commit 3d2a71a596bd9c761c8487a2178e95f8a61da083
> Author: Alexander van Heukelum <heukelum@fastmail.fm>
> Date:   Tue Sep 30 18:41:37 2008 +0200
> 
>     x86, traps: converge do_debug handlers
> 
> commit 08d68323d1f0c34452e614263b212ca556dae47f
> Author: K.Prasad <prasad@linux.vnet.ibm.com>
> Date:   Mon Jun 1 23:44:08 2009 +0530
> 
>     hw-breakpoints: modifying generic debug exception to use thread-specific deb
> 
> commit 787ecfaa503dc63ff1831ddc74b15dad49bace1d
> Author: Vegard Nossum <vegard.nossum@gmail.com>
> Date:   Fri Apr 4 00:53:23 2008 +0200
> 
>     x86: add hooks for kmemcheck
> 
> I encourage the kprobe developers to check whether their code is correct
> as it stands in current tip/master. Also, comments on this particular
> change is welcome.

I see no problem with this change wrt kprobes, since the changes happen
after the notify_die, by which time, kprobes would've returned
NOTIFY_DONE since the per-cpu current_kprobe == NULL.

Ananth

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

* Re: [PATCH] kmemcheck: move hook before preempt_conditional_sti()
  2009-06-08  6:41 ` Ananth N Mavinakayanahalli
@ 2009-06-08 19:46   ` Masami Hiramatsu
  0 siblings, 0 replies; 6+ messages in thread
From: Masami Hiramatsu @ 2009-06-08 19:46 UTC (permalink / raw)
  To: ananth, Vegard Nossum
  Cc: linux-kernel, Alexander van Heukelum, K.Prasad, Alan Stern,
	Frederic Weisbecker, Pekka Enberg

Ananth N Mavinakayanahalli wrote:
> On Sun, Jun 07, 2009 at 06:26:52PM +0200, Vegard Nossum wrote:
>> commit 787ecfaa503dc63ff1831ddc74b15dad49bace1d
>> Author: Vegard Nossum <vegard.nossum@gmail.com>
>> Date:   Fri Apr 4 00:53:23 2008 +0200
>>
>>     x86: add hooks for kmemcheck
>>
>> I encourage the kprobe developers to check whether their code is correct
>> as it stands in current tip/master. Also, comments on this particular
>> change is welcome.
> 
> I see no problem with this change wrt kprobes, since the changes happen
> after the notify_die, by which time, kprobes would've returned
> NOTIFY_DONE since the per-cpu current_kprobe == NULL.

BTW, what will happen if kmemchecked page is accessed from
kprobe's single-stepping instruction? :-)

If a pagefault occurs before (kprobe's)single-step is done,
may kmemcheck's single-step handler be ignored by kprobe's
single-step handler? If it's true, I think kmemcheck hook
should be done before notify_die. (and add __kprobes to some
kmemcheck functions)

Thank you,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com


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

end of thread, other threads:[~2009-06-08 19:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-07 16:26 [PATCH] kmemcheck: move hook before preempt_conditional_sti() Vegard Nossum
2009-06-07 16:45 ` Ingo Molnar
2009-06-07 17:25   ` Vegard Nossum
2009-06-07 17:52     ` Ingo Molnar
2009-06-08  6:41 ` Ananth N Mavinakayanahalli
2009-06-08 19:46   ` Masami Hiramatsu

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).