Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754553AbbGXSl5 (ORCPT ); Fri, 24 Jul 2015 14:41:57 -0400 Received: from mail-ig0-f180.google.com ([209.85.213.180]:37524 "EHLO mail-ig0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750934AbbGXSl4 (ORCPT ); Fri, 24 Jul 2015 14:41:56 -0400 MIME-Version: 1.0 In-Reply-To: References: <20150724081326.GO25159@twins.programming.kicks-ass.net> <20150724075841.40f209f4@gandalf.local.home> <20150724124304.GH19282@twins.programming.kicks-ass.net> <20150724090342.6d11e16d@gandalf.local.home> <20150724132128.GA3612@1wt.eu> <20150724103127.3c3f4693@gandalf.local.home> <20150724145901.GB3612@1wt.eu> <20150724111621.34713023@gandalf.local.home> <20150724152637.GC3612@1wt.eu> <20150724153054.GK19282@twins.programming.kicks-ass.net> Date: Fri, 24 Jul 2015 11:41:55 -0700 X-Google-Sender-Auth: 3-jZUpHhnmUp3oo8c1UmGA4N2GI Message-ID: Subject: Re: Dealing with the NMI mess From: Linus Torvalds To: Peter Zijlstra Cc: Willy Tarreau , Steven Rostedt , Andy Lutomirski , X86 ML , "linux-kernel@vger.kernel.org" , Borislav Petkov , Thomas Gleixner , Brian Gerst Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1709 Lines: 48 On Fri, Jul 24, 2015 at 11:29 AM, Linus Torvalds wrote: > > So in the #DB handler, we would basically only clear instruction > breakpoints, and only when they trigger. If we have a data breakpoint > that triggers (even in kernel mode, and with interrupts disabled), let > it trigger and return with "ret" anyway. No biggie. So we'd not only look at "which breakpoint triggered", we'd also look at the actual debug register and check that "R/Wn == 0", and only disable it for that case. So you'd read %dr6 and %dr7, and then iterate 0..3 and check whether it triggerd (bit #n in %dr6), and that R/Wn (bits 16-17+n*4 of %dr7) is zero, and if so, clear LGn bits (bits 0-1+n*2) in %dr7. Something like unsigned long mask = 0; unsigned int dr6 = debug_read(6); unsigned int dr7 = debug_read(7) int i; for (i = 0; i < 4; i++) { if ((dr6 >> i) & 1) { if (!((dr7 >> (4*i+16)) & 3)) mask |= 3 << (i*2); } } if (mask) debug_write(dr7 & ~mask, 7); (yeah, I could easily have screwed that up) But the above should only clear bits in dr7 that are actually associated with the instruction breakpoint that triggered, and since it's a _kernel_ instruction breakpoint, not a user one, we can clear it and forget it. No need to re-enable at all. Hmm? Linus -- 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/