From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965808AbcCJLEI (ORCPT ); Thu, 10 Mar 2016 06:04:08 -0500 Received: from torg.zytor.com ([198.137.202.12]:38064 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965356AbcCJLDw (ORCPT ); Thu, 10 Mar 2016 06:03:52 -0500 Date: Thu, 10 Mar 2016 03:02:41 -0800 From: tip-bot for Andy Lutomirski Message-ID: Cc: hpa@zytor.com, brgerst@gmail.com, torvalds@linux-foundation.org, dvlasenk@redhat.com, mingo@kernel.org, bp@alien8.de, andrew.cooper3@citrix.com, peterz@infradead.org, luto@kernel.org, luto@amacapital.net, tglx@linutronix.de, oleg@redhat.com, linux-kernel@vger.kernel.org Reply-To: oleg@redhat.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, luto@kernel.org, luto@amacapital.net, andrew.cooper3@citrix.com, peterz@infradead.org, hpa@zytor.com, brgerst@gmail.com, bp@alien8.de, dvlasenk@redhat.com, mingo@kernel.org, torvalds@linux-foundation.org In-Reply-To: <3857676e1be8fb27db4b89bbb1e2052b7f435ff4.1457578375.git.luto@kernel.org> References: <3857676e1be8fb27db4b89bbb1e2052b7f435ff4.1457578375.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86/entry/traps: Clear DR6 early in do_debug() and improve the comment Git-Commit-ID: 8bb5643686d2898bec181c407651cf84e77d413f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 8bb5643686d2898bec181c407651cf84e77d413f Gitweb: http://git.kernel.org/tip/8bb5643686d2898bec181c407651cf84e77d413f Author: Andy Lutomirski AuthorDate: Wed, 9 Mar 2016 19:00:29 -0800 Committer: Ingo Molnar CommitDate: Thu, 10 Mar 2016 09:48:13 +0100 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 Cc: Andrew Cooper Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/3857676e1be8fb27db4b89bbb1e2052b7f435ff4.1457578375.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/kernel/traps.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 1af5621..7394be8 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) ist_enter(regs); get_debugreg(dr6, 6); + /* + * The Intel SDM says: + * + * Certain debug exceptions may clear bits 0-3. The remaining + * contents of the DR6 register are never cleared by the + * processor. To avoid confusion in identifying debug + * exceptions, debug handlers should clear the register before + * returning to the interrupted task. + * + * Keep it simple: clear DR6 immediately. + */ + set_debugreg(0, 6); /* Filter out all the reserved bits which are preset to 1 */ dr6 &= ~DR6_RESERVED; @@ -616,9 +628,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code) if ((dr6 & DR_STEP) && kmemcheck_trap(regs)) goto exit; - /* DR6 may or may not be cleared by the CPU */ - set_debugreg(0, 6); - /* Store the virtualized DR6 value */ tsk->thread.debugreg6 = dr6;