Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756506Ab0GNTVd (ORCPT ); Wed, 14 Jul 2010 15:21:33 -0400 Received: from eddie.linux-mips.org ([78.24.191.182]:39706 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751822Ab0GNTVc (ORCPT ); Wed, 14 Jul 2010 15:21:32 -0400 Date: Wed, 14 Jul 2010 20:21:30 +0100 (BST) From: "Maciej W. Rozycki" To: Mathieu Desnoyers cc: LKML , Linus Torvalds , Andrew Morton , Ingo Molnar , Peter Zijlstra , Steven Rostedt , Steven Rostedt , Frederic Weisbecker , Thomas Gleixner , Christoph Hellwig , Li Zefan , Lai Jiangshan , Johannes Berg , Masami Hiramatsu , Arnaldo Carvalho de Melo , Tom Zanussi , KOSAKI Motohiro , Andi Kleen , akpm@osdl.org, "H. Peter Anvin" , Jeremy Fitzhardinge , "Frank Ch. Eigler" Subject: Re: [patch 2/2] x86 NMI-safe INT3 and Page Fault In-Reply-To: <20100714181220.GA32279@Krystal> Message-ID: References: <20100714154923.947138065@efficios.com> <20100714155804.252253097@efficios.com> <20100714181220.GA32279@Krystal> User-Agent: Alpine 2.00 (LFD 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1980 Lines: 44 On Wed, 14 Jul 2010, Mathieu Desnoyers wrote: > > How about only using the special return path when a nested exception is > > about to return to the NMI handler? You'd avoid all the odd cases then > > that do not happen in the NMI context. > > This is exactly what this patch does :-) Ah, OK then -- I understood you actually tested the value of TF in the image to be restored. > It selects the return path with > > + testl $NMI_MASK,TI_preempt_count(%ebp) > + jz resume_kernel /* Not nested over NMI ? */ > > In addition, about int3 breakpoints use in the kernel, AFAIK the handler does > not explicitly set the RF flag, and the breakpoint instruction (int3) appears > not to set it. (from my understanding of Intel's > Intel Architecture Software Developer’s Manual Volume 3: System Programming > 15.3.1.1. INSTRUCTION-BREAKPOINT EXCEPTION C) The CPU only sets RF itself in the image saved in certain cases -- you'd see it set in the page fault handler for example, so that once the handler has finished any instruction breakpoint does not hit (presumably again, because the instruction breakpoint debug exception has the highest priority). You mentioned the need to handle these faults. > So it should be safe to set a int3 breakpoint in a NMI handler with this patch. > > It's just the "single-stepping" feature of kprobes which is problematic. > Luckily, only int3 is needed for code patching bypass. Actually the breakpoint exception handler should actually probably set RF explicitly, but that depends on the exact debugging scenario, so I can't comment on it further. I don't know how INT3 is used in this context, so I'm just noting this may be a danger zone. Maciej -- 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/