Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1042706imm; Fri, 13 Jul 2018 10:27:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf2d94Y35+ZOScXrSr0xEniBTL5Gy9dFu45uwNnMpVRtQrTF29+3vF+EI8fiMeu/Z2bcB8O X-Received: by 2002:a63:6604:: with SMTP id a4-v6mr6816297pgc.404.1531502864113; Fri, 13 Jul 2018 10:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531502864; cv=none; d=google.com; s=arc-20160816; b=QX7ZGWGDRKeZDjTQYB/Obj+ECGCto8LtsuQ+DKEOddvmtVTCu32vNhn7ta/5LkOeE8 Dp0WPDjLnKbr7uYLIF4xLXwGMcj72EKPACMOPs8MaIKK3iWYzB5ZW20FZ9tyib+QSIqf L+HPBhkfJHYVzZj3GFqUCiIBVHgO7eNfKj474EZDmwmpKUomzn2dL4yq5n03YNbDnovK VXnEmWrJWYY9/FI0waCxoMjZO/8rNoIu6S1a+l1TuiR7+dW/Yn/grPO1v25Dhfl60GVu ZNpO43Y5915Bh/d/qSW5h8BN/zmBdiG6JI6Ow6+IoxAkdJywCon6UMCQK2P+pvtePqvu 5NWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=cF9exWOBSiSYKDSlAAL3RrSktGF792+4hkmWV8Z7a7g=; b=Sb9H0PDk7eKn0HL+0UWfEdW9CKjIYQiKEauP8cqj1Q4izyBxHZo5NVP+DXszN1z8MF e3w1WspgTHcnm815Jjiz+AiiB41wj+1FsFDSRzc9Gn4/Il3D8scc357s4j/7AhaD3Qkb QvymrpofkVWpA0IX+hNRK3oAMMy/acHox60Jo+16ixlpt6F2o2S/nrVqJbX9uIlufiT2 QgU2EIjFQKkHjLNUZa8o6QZpqFHMoV8ree+bVPH2HyHK72Y2rB/1Jue2UKJfAIr0YZeW L5Qwd8wdPCAvVFpnnw5lhjGYAdVV7PfAsCdMttyS7zVs+Sm26vRjlnoh5Hy6SNkvWMa0 2dHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=UXgccndh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6-v6si25485756pfa.217.2018.07.13.10.27.28; Fri, 13 Jul 2018 10:27:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=UXgccndh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731329AbeGMRm0 (ORCPT + 99 others); Fri, 13 Jul 2018 13:42:26 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:40011 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729924AbeGMRm0 (ORCPT ); Fri, 13 Jul 2018 13:42:26 -0400 Received: by mail-wm0-f66.google.com with SMTP id z13-v6so10106119wma.5 for ; Fri, 13 Jul 2018 10:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=cF9exWOBSiSYKDSlAAL3RrSktGF792+4hkmWV8Z7a7g=; b=UXgccndhMJFiwLp3AGbabwjGyQPo1aaDO+ACOLm1xFBYczxp+qGgD5dXpqo2Tg0HXy 8Ofhxe2Wi8Cifedf3s86YYnV9RCmKt5xc+/gOiG88fFX3QtTsrU80T558yzXd51JUl/R baXOXNsilwm0jGvtn4IqddyYOTOJzUhpycYDzCkY73oNyGYWLYf+QlXw1sCcbefqOopX WammAe50nhHqOXfKqrnqg52ki7vOQ7QCij6OX2l/SfAHKyHbrt8+Aiw9xJC3aIYKMiL1 nGH4SHdRsNtlhN0nyWEHspoiJig+M3JYrTCKd4+GwujO25VpXTjP+MgAqDs12ZqTSqG6 mvtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=cF9exWOBSiSYKDSlAAL3RrSktGF792+4hkmWV8Z7a7g=; b=GsWilr5tbYT3lUR8Oy0Yn0AaNYUVO16qAp5kdQKYt/AwDosmMWPQPKQqe/VbTEiDzi H25mncsAc4PJ559bFxUR3KhyEMCQPL3sqg2AD6mPluVcdeV3ziS808UqdFJhy1GBcVCK SC4Cb639Z9VtIoqlHXfiE9unu2QNiE9ByCcFwcOlF8QBSSMe8oT6yLA+TdXPwB3z1kvF Jrjf42WzCNLPBOrv3YoGWpqcbMRgKnz3u68YzaginRPq2pOXCPWGraOcDkm0+EOknuTx tdDy5BLvhtkYFg4rz7m928qzwyJrXW98vJUoVBjRhhliMmizEOSl5fpoKrhu59pbnakR 5EEg== X-Gm-Message-State: AOUpUlEOtGLslvIBYweysyEcaO2GmQHVOxo0T9R0C5OGUvZiFH1QOqdf m2LMHdc1xcBbbJNZ3PNTFoXWeu6THwtwlxpPj5/OLA== X-Received: by 2002:a1c:f902:: with SMTP id x2-v6mr4225801wmh.116.1531502811434; Fri, 13 Jul 2018 10:26:51 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:d548:0:0:0:0:0 with HTTP; Fri, 13 Jul 2018 10:26:30 -0700 (PDT) In-Reply-To: <20180713100519.pn7ium7a4ga24dys@8bytes.org> References: <1531308586-29340-1-git-send-email-joro@8bytes.org> <1531308586-29340-6-git-send-email-joro@8bytes.org> <20180713100519.pn7ium7a4ga24dys@8bytes.org> From: Andy Lutomirski Date: Fri, 13 Jul 2018 10:26:30 -0700 Message-ID: Subject: Re: [PATCH 05/39] x86/entry/32: Unshare NMI return path To: Joerg Roedel Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , X86 ML , LKML , Linux-MM , Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , "Liguori, Anthony" , Daniel Gruss , Hugh Dickins , Kees Cook , Andrea Arcangeli , Waiman Long , Pavel Machek , "David H . Gutteridge" , Joerg Roedel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 13, 2018 at 3:05 AM, Joerg Roedel wrote: > On Thu, Jul 12, 2018 at 01:53:19PM -0700, Andy Lutomirski wrote: >> > On Jul 11, 2018, at 4:29 AM, Joerg Roedel wrote: >> > NMI will no longer use most of the shared return path, >> > because NMI needs special handling when the CR3 switches for >> > PTI are added. >> >> Why? What would go wrong? >> >> How many return-to-usermode paths will we have? 64-bit has only one. > > In the non-NMI return path we make a decission on whether we return to > user-space or kernel-space and do different things based on that. For > example, when returning to user-space we call > prepare_exit_to_usermode(). With the CR3 switches added later we also > unconditionally switch to user-cr3 when we are in the return-to-user > path. > > The NMI return path does not need any of that, as it doesn't call > prepare_exit_to_usermode() even when it returns to user-space. It > doesn't even care where it returns to. It just remembers stack and cr3 > on entry in callee-safed registers and restores that on exit. This works > in the NMI path because it is pretty simple and doesn't do any fancy > work on exit. > > While working on a previous version I also tried to store stack and cr3 > in a callee-safed register and restore that on exit again, but it didn't > work, most likley because something in-between overwrote one of the > registers. I also found it a bit fragile to make make two registers > untouchable in the whole entry-code. It doesn't make future changes > simpler or more robust. > > So long story short, the NMI path can be simpler wrt. stack and cr3 > handling as the other entry/exit points, and therefore it is handled > differently. > > We used to do it this way on 64-bit, but I had to change it because of a nasty case where we *fail* the return to user mode when we're returning from an NMI. In theory this can't happen any more due to a bunch of tightening up of the way we handle segmentation, but it's still quite nasty. The whole situation on 32-bit isn't quite as fragile because espfix32 is much more robust than espfix64. So I suppose this is okay, but I wouldn't be totally shocked if we need to redo it down the road.