Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754427AbdCJCoX (ORCPT ); Thu, 9 Mar 2017 21:44:23 -0500 Received: from mail-ua0-f173.google.com ([209.85.217.173]:34092 "EHLO mail-ua0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751013AbdCJCoV (ORCPT ); Thu, 9 Mar 2017 21:44:21 -0500 MIME-Version: 1.0 In-Reply-To: <20170309224447.852428776@goodmis.org> References: <20170309224204.066497548@goodmis.org> <20170309224447.852428776@goodmis.org> From: Andy Lutomirski Date: Thu, 9 Mar 2017 18:43:59 -0800 Message-ID: Subject: Re: [PATCH 2/2] x86/nmi: Fix and optimize the NMI stack check code To: Steven Rostedt Cc: "linux-kernel@vger.kernel.org" , Linus Torvalds , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Andrew Morton 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: 1129 Lines: 36 On Thu, Mar 9, 2017 at 2:42 PM, Steven Rostedt wrote: > From: "Steven Rostedt (Red Hat)" > > Andy Lutomirski reported an off by one in the NMI stack check > for the nested NMI code, where if the stack pointer was one above > the actual stack (stack start + STACK_SIZE) it would trigger a false > positive. This is not that big of a deal because the stack pointer > should never be that. Even if a stack was using the pages just > above the NMI stack, it would require the stack about to overflow > for this to trigger, which is a much bigger bug than this is fixing. > > Also, Linus Torvalds pointed out that doing two compares can be > accomplish with a single compare. That is: > > ("reg" is top of stack we are comparing "stack" to) > > cmpq reg, stack > jae label // note, code had one off "ja" instead of "jae" > subq size, reg > cmpq reg, stack > jb label > > Is the same as: > > subq $1, reg > subq stack, reg > cmpq size, reg > jae label > > The subq $1 was added into the leaq by doing: > > leaq 5*8+7(%rsp), %rdx > > Added more comments as well. Nice.