Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751587AbdFIHPC (ORCPT ); Fri, 9 Jun 2017 03:15:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42424 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751528AbdFIHPA (ORCPT ); Fri, 9 Jun 2017 03:15:00 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 54C5E80C06 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 54C5E80C06 Subject: Re: Speeding up VMX with GDT fixmap trickery? To: Andy Lutomirski , X86 ML , "linux-kernel@vger.kernel.org" , kvm list , Borislav Petkov , Thomas Garnier , Juergen Gross , Andrew Cooper , Boris Ostrovsky References: From: Paolo Bonzini Message-ID: Date: Fri, 9 Jun 2017 09:14:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 09 Jun 2017 07:14:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1606 Lines: 47 On 09/06/2017 03:13, Andy Lutomirski wrote: > Hi all- > > As promised when Thomas did his GDT fixmap work, here is a draft patch > to speed up KVM by extending it. > > The downside of this patch is that it makes the fixmap significantly > larger on 64-bit systems if NR_CPUS is large (it adds 15 more pages > per CPU). I don't know if we care at all. It also bloats the kernel > image by 4k and wastes 4k of RAM for the entire time the system is > booted. We could avoid the latter bit (sort of) by not mapping the > extra fixmap pages at all and handling the resulting faults somehow. > That would scare me -- now we have IRET generating #PF when running > malicious , and that way lies utter madness. > > The upside is that we don't need to do LGDT after a vmexit on VMX. > LGDT is slooooooooooow. But no, I haven't benchmarked this yet. > > What do you all think? > > https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/commit/?h=x86/kvm&id=e249a09787d6956b52d8260b2326d8f12f768799 Not sure I understand this completely, but: /* Get the fixmap index for a specific processor */ static inline unsigned int get_cpu_gdt_ro_index(int cpu) { - return FIX_GDT_REMAP_BEGIN + cpu; + return FIX_GDT_REMAP_END - cpu * PAGES_PER_GDT; } isn't this off by one. I think it should be FIX_GDT_REMAP_END + 1 - cpu * PAGES_PER_GDT or just FIX_GDT_REMAP_BEGIN + cpu * PAGES_PER_GDT? That is for example: FIX_GDT_REMAP_BEGIN = 100 get_cpu_gdt_ro_index(0) = 100 get_cpu_gdt_ro_index(1) = 116 get_cpu_gdt_ro_index(2) = 132 get_cpu_gdt_ro_index(3) = 148 FIX_GDT_REMAP_END = 163 Paolo