Re: [PATCH] kmemcheck: move hook before preempt_conditional_sti()

From: Vegard Nossum
Date: Sun Jun 07 2009 - 13:25:32 EST


2009/6/7 Ingo Molnar <mingo@xxxxxxx>:
>
> * Vegard Nossum <vegard.nossum@xxxxxxxxx> 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@xxxxxxxxxxx>
>> Date: Â Tue Sep 30 18:41:37 2008 +0200
>>
>> Â Â x86, traps: converge do_debug handlers
>>
>> commit 08d68323d1f0c34452e614263b212ca556dae47f
>> Author: K.Prasad <prasad@xxxxxxxxxxxxxxxxxx>
>> 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@xxxxxxxxx>
>> 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@xxxxxxx>
>> Cc: Alexander van Heukelum <heukelum@xxxxxxxxxxx>
>> Cc: K.Prasad <prasad@xxxxxxxxxxxxxxxxxx>
>> Cc: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
>> Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
>> Cc: Pekka Enberg <penberg@xxxxxxxxxxxxxx>
>> Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxx>
>> ---
>> Â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@xxxxxxx>
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/