aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@kernel.org>2016-03-09 22:00:29 -0500
committerIngo Molnar <mingo@kernel.org>2016-03-10 03:48:13 -0500
commit8bb5643686d2898bec181c407651cf84e77d413f (patch)
treefffaba109deef6957634a64d7830c2214b9d652d /arch/x86/kernel
parent81edd9f69a6fd214fdbe66b43de6aa1610c84c63 (diff)
x86/entry/traps: Clear DR6 early in do_debug() and improve the comment
Leaving any bits set in DR6 on return from a debug exception is asking for trouble. Prevent it by writing zero right away and clarify the comment. Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Andrew Cooper <andrew.cooper3@citrix.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/3857676e1be8fb27db4b89bbb1e2052b7f435ff4.1457578375.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r--arch/x86/kernel/traps.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 1af56217fb5d..7394be8b1a66 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -593,6 +593,18 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
593 ist_enter(regs); 593 ist_enter(regs);
594 594
595 get_debugreg(dr6, 6); 595 get_debugreg(dr6, 6);
596 /*
597 * The Intel SDM says:
598 *
599 * Certain debug exceptions may clear bits 0-3. The remaining
600 * contents of the DR6 register are never cleared by the
601 * processor. To avoid confusion in identifying debug
602 * exceptions, debug handlers should clear the register before
603 * returning to the interrupted task.
604 *
605 * Keep it simple: clear DR6 immediately.
606 */
607 set_debugreg(0, 6);
596 608
597 /* Filter out all the reserved bits which are preset to 1 */ 609 /* Filter out all the reserved bits which are preset to 1 */
598 dr6 &= ~DR6_RESERVED; 610 dr6 &= ~DR6_RESERVED;
@@ -616,9 +628,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
616 if ((dr6 & DR_STEP) && kmemcheck_trap(regs)) 628 if ((dr6 & DR_STEP) && kmemcheck_trap(regs))
617 goto exit; 629 goto exit;
618 630
619 /* DR6 may or may not be cleared by the CPU */
620 set_debugreg(0, 6);
621
622 /* Store the virtualized DR6 value */ 631 /* Store the virtualized DR6 value */
623 tsk->thread.debugreg6 = dr6; 632 tsk->thread.debugreg6 = dr6;
624 633