Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp598132imm; Fri, 13 Jul 2018 03:06:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc9U8YyQiCsmjMMZ9SM+NSxs9Del32KDMKSlLPCocGy18Dc/r+ercng//dt/BczYu8FITgj X-Received: by 2002:a62:229a:: with SMTP id p26-v6mr6389876pfj.53.1531476385564; Fri, 13 Jul 2018 03:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531476385; cv=none; d=google.com; s=arc-20160816; b=TPjmIoOInCzUQ4YtqF2bs7SIjzlR7YogU37U6CCQjmfsVO5nRaCrZ1ZbeK6f0zR/cO cNJlXpKzBom47tKJTs8smzSBKDNX3YLHiQIwCvn6ibNUllyXPlxrwNJrl8wpUqBFsy5O vpsQDoK2So1ZSgxsyY9e7EUmw719Y/7ji4FYS5b/bcKaUTFZewUjQKGf+54+8Ofj3wfr NJ9RM7OLVUmeEPMXwAzgXA/b9Bj8ghvkpfvH9p98nPbO65zxZ5KLG4aE+ZYA27nRFFWt 3UuD6begLKefT3xI8iFiNosqLJuFpuOzUStHzVslcv6rCkB9vmHVU/bi9Qz5h9E7blEn RVgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=1EXJTcAJMyv+cbXEFZdu4gt9u4vwO2fNKkAYQ0qZAS8=; b=K3OBBqVdopbczkqcltfbdQLENzgNV3u9O6W+4UZtD0DZeKUc45+TmWjvg8++3XI8O4 0o4Bp01lz7AdZ/BXnt3mh1f5jrmagW00US0VpFiitCWVuChQvgVng5tTkF9do2gtHU3c wJpp3pX1uTLzfTvpycpguLwyiWu0YQfSOOAkJ1l7eIv3TrWNBcWtV0llshfwkBSI7SY7 lixCVFzLG3+uI9clGrndlhSQIv3Gny1jXVpFuoUoGxONOQd3SiPfpafQ+pRwA7aP6M7X 3m9b/R9F4ZsYTaSebi/gBrIy5YSt8OTkslA1rls7eR3jplvC+bvJ83ZJfPAeoAiBPyca 7cHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=Var1Hvgh; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si23920267pgx.310.2018.07.13.03.06.10; Fri, 13 Jul 2018 03:06:25 -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=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=Var1Hvgh; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728035AbeGMKT0 (ORCPT + 99 others); Fri, 13 Jul 2018 06:19:26 -0400 Received: from 8bytes.org ([81.169.241.247]:37494 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726789AbeGMKTZ (ORCPT ); Fri, 13 Jul 2018 06:19:25 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 73B8C377; Fri, 13 Jul 2018 12:05:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1531476326; bh=DOlvZFeh1F+vhRlWVLM8hY8/3suxRydPy3yJRKzFccE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Var1HvgheYnUAMThyWCOhmRNKcDVxgulKY7QmbTabaDKc5HOxRB1Jp7spJlHe+gg5 PUXydAGVg87eaDEVDMluDl/aSKo2KOWmZmxLUjK6geGgRJ7+st7T7y6O1rIH56p9gT jQt9Qa5w+dLoWE5dJj57sNH/Wy16u9HqVFKQxpP3IUDjqOZb8ILGnr8lkufK4zr1Zw tBUXm1RyUJRGXldiElSes6OKhr6kTnatb9MW2eRZH10HfTf9MNHjeqbkyro38R2ZJY Gg/QnyUGY+vcop6x+Mpzs63iEbwgaNV7bS1C78Jg0aIDW99li6hlyJwn8803KBWMnJ 9/6NeNrHnanJA== Date: Fri, 13 Jul 2018 12:05:19 +0200 From: Joerg Roedel To: Andy Lutomirski Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, 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 , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, Andrea Arcangeli , Waiman Long , Pavel Machek , "David H . Gutteridge" , jroedel@suse.de Subject: Re: [PATCH 05/39] x86/entry/32: Unshare NMI return path Message-ID: <20180713100519.pn7ium7a4ga24dys@8bytes.org> References: <1531308586-29340-1-git-send-email-joro@8bytes.org> <1531308586-29340-6-git-send-email-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Regards, Joerg