Received: by 10.223.176.46 with SMTP id f43csp793075wra; Fri, 19 Jan 2018 01:57:41 -0800 (PST) X-Google-Smtp-Source: ACJfBotuHAnnz9MZxPOpsxaOuYk/8n9Y1qkToFN1NrpMTlRWqXsZcrneE0scacY+u4tMoff0+kf/ X-Received: by 10.101.64.4 with SMTP id f4mr38962435pgp.200.1516355860921; Fri, 19 Jan 2018 01:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516355860; cv=none; d=google.com; s=arc-20160816; b=h9Ow5LTH73g8YPjbu1E9ndX5jo59kXqw/D6xhlG6N8NkdEMZdCLNvhuwvVT+nEaJ+i JWgSxpbRh0aKgwEghAts8RuOa6FZJ8h9KUUo6DVb4pZ1ehf+TaC1gY66qgNkcs8MfGub mNVjlE2s1tUcP15iqkihW99AuARejdxTlkoM3QbOb+IHYMCvOBtnXzAUrKJ4PB1mF0SX J5M3ZRcf44+ewSiwik7D99i45ZJsSmvBCess16QLwC/zU7uK0yY3Xa2YmKvCi8Ov4FVS yP6TmxhcGzY7/HS271HUA9EZU/BIYPYdHyS9c4qZLq7e30tCMY7UjKjxK8PBXujdjBDE fJxQ== 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=WCvyRMFFhQfC22TyOKDUHXiPjAg0F0VKvWDrZ6PmTZY=; b=P7X3TkpQB7n9QJwJvWooGQDhIyFA3Pr4x810GcemQ+t/sVCx2tUkvFcVI3PBN7BJFv ivFsPfZIx9jPCyMTxZxe9y02Oyo1pX355bGztPKe44UaB4Zr51qP/BftVmTXI258Wiq7 MEk+GE7Pn7AFvlXnrrQhov3gCS03f0PrHEdjM3x4Hur6djkE20KiCpR6qeq4q0U3/z+W mJKL4I9nht7Ve/HetREADloyNuYp4rIvIf6hdc9dPr69oc+u+DjqU2/QuDNHZoDDeLhj agm+Q1nai477+aOKTlRuW3C8aCywqZp24xGWhp7YzmE+d13HiqwkIg6Iqd8rDJfoEPLz 31ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=I6a9vpxp; 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 n24si2069650pgd.735.2018.01.19.01.57.26; Fri, 19 Jan 2018 01:57:40 -0800 (PST) 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=I6a9vpxp; 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 S1755360AbeASJza (ORCPT + 99 others); Fri, 19 Jan 2018 04:55:30 -0500 Received: from 8bytes.org ([81.169.241.247]:55622 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754699AbeASJzZ (ORCPT ); Fri, 19 Jan 2018 04:55:25 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id C6B531FD; Fri, 19 Jan 2018 10:55:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1516355723; bh=bdrw2UB5WA0Pyte/82iHtwlzhnBVo4PgRjaYcpMgtBU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I6a9vpxpdXof7+3H29wvZ1Lyy6B7cqGpQn33ov21N+3Koq9ChhdS7U5UOynAG17zQ dmuFBJ4K7PUUE29KMnksmpHyF1xuHRK3KRZU41/k731uonElzr8vwPvOhbyHsHJFub 1iETUNEaBCS+dUGV3GwHG4gn/KI6ZGBKMrfKe6Ydi8qoHkBF8k/RdW/gVKeI6N9Bip nKMit36zmOPw1Bi0e4CxM+Pzu30Mr5egPu24CnGglJtX2oJQI+1RWR8GN3XKewsusk ILC3diuakKqPUng4YqqRdjacVeBm9vAYSsjkxAG3AxlVFvjgrqJ0Yhz2BEuumajUP4 yksCLodTq7QcQ== Date: Fri, 19 Jan 2018 10:55:23 +0100 From: Joerg Roedel To: Andy Lutomirski Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , X86 ML , LKML , linux-mm@kvack.org, Linus Torvalds , 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 , Joerg Roedel Subject: Re: [PATCH 02/16] x86/entry/32: Enter the kernel via trampoline stack Message-ID: <20180119095523.GY28161@8bytes.org> References: <1516120619-1159-1-git-send-email-joro@8bytes.org> <1516120619-1159-3-git-send-email-joro@8bytes.org> <20180117091853.GI28161@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hey Andy, On Wed, Jan 17, 2018 at 10:10:23AM -0800, Andy Lutomirski wrote: > On Wed, Jan 17, 2018 at 1:18 AM, Joerg Roedel wrote: > > Just read up on vm86 mode control transfers and the stack layout then. > > Looks like I need to check for eflags.vm=1 and copy four more registers > > from/to the entry stack. Thanks for pointing that out. > > You could just copy those slots unconditionally. After all, you're > slowing down entries by an epic amount due to writing CR3 on with PCID > off, so four words copied should be entirely lost in the noise. OTOH, > checking for VM86 mode is just a single bt against EFLAGS. > > With the modern (rewritten a year or two ago by Brian Gerst) vm86 > code, all the slots (those actually in pt_regs) are in the same > location regardless of whether we're in VM86 mode or not, but we're > still fiddling with the bottom of the stack. Since you're controlling > the switch to the kernel thread stack, you can easily just write the > frame to the correct location, so you should not need to context > switch sp1 -- you can do it sanely and leave sp1 as the actual bottom > of the kernel stack no matter what. In fact, you could probably avoid > context switching sp0, either, which would be a nice cleanup. I am not sure what you mean by "not context switching sp0/sp1" ... > So I recommend the following. Keep sp0 as the bottom of the sysenter > stack no matter what. Then do: > > bt $X86_EFLAGS_VM_BIT > jc .Lfrom_vm_\@ > > push 5 regs to real stack, starting at four-word offset (so they're in > the right place) > update %esp > ... > .Lupdate_esp_\@ > > .Lfrom_vm_\@: > push 9 regs to real stack, starting at the bottom > jmp .Lupdate_esp_\@ > > Does that seem reasonable? It's arguably much nicer than what we have > now. But that looks like a good idea. Having a consistent stack with and without vm86 is certainly a nice cleanup. Regards, Joerg