From patchwork Thu Jun 11 15:07:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 29595 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5BFEnwQ029212 for ; Thu, 11 Jun 2009 15:14:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758254AbZFKPOq (ORCPT ); Thu, 11 Jun 2009 11:14:46 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758766AbZFKPOp (ORCPT ); Thu, 11 Jun 2009 11:14:45 -0400 Received: from mx2.redhat.com ([66.187.237.31]:49748 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756947AbZFKPOo (ORCPT ); Thu, 11 Jun 2009 11:14:44 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5BFElDO014150 for ; Thu, 11 Jun 2009 11:14:47 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5BFEfl6016892; Thu, 11 Jun 2009 11:14:41 -0400 Received: from amt.cnet (vpn-10-91.str.redhat.com [10.32.10.91]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5BFEdqj002929; Thu, 11 Jun 2009 11:14:40 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 6639A67421F; Thu, 11 Jun 2009 12:14:35 -0300 (BRT) Received: (from root@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n5BFEYg2006656; Thu, 11 Jun 2009 12:14:34 -0300 Message-Id: <20090611150846.088951658@localhost.localdomain> References: <20090611150739.140947079@localhost.localdomain> In-Reply-To: <4A311529.3070907@redhat.com> User-Agent: quilt/0.46-1 Date: Thu, 11 Jun 2009 12:07:44 -0300 From: Marcelo Tosatti To: avi@redhat.com Cc: kvm@vger.kernel.org, Marcelo Tosatti Subject: [patch 5/5] KVM: VMX: conditionally disable 2M pages Content-Disposition: inline; filename=disable-2m-pages-vmx X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Disable usage of 2M pages if VMX_EPT_2MB_PAGE_BIT (bit 16) is clear in MSR_IA32_VMX_EPT_VPID_CAP and EPT is enabled. Signed-off-by: Marcelo Tosatti Index: kvm/arch/x86/kvm/vmx.c =================================================================== --- kvm.orig/arch/x86/kvm/vmx.c +++ kvm/arch/x86/kvm/vmx.c @@ -1393,6 +1393,9 @@ static __init int hardware_setup(void) if (!cpu_has_vmx_tpr_shadow()) kvm_x86_ops->update_cr8_intercept = NULL; + if (enable_ept && !cpu_has_vmx_ept_2m_page()) + kvm_disable_largepages(); + return alloc_kvm_area(); } Index: kvm/include/linux/kvm_host.h =================================================================== --- kvm.orig/include/linux/kvm_host.h +++ kvm/include/linux/kvm_host.h @@ -219,6 +219,7 @@ int kvm_arch_set_memory_region(struct kv struct kvm_userspace_memory_region *mem, struct kvm_memory_slot old, int user_alloc); +void kvm_disable_largepages(void); void kvm_arch_flush_shadow(struct kvm *kvm); gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn); struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn); Index: kvm/virt/kvm/kvm_main.c =================================================================== --- kvm.orig/virt/kvm/kvm_main.c +++ kvm/virt/kvm/kvm_main.c @@ -85,6 +85,8 @@ static long kvm_vcpu_ioctl(struct file * static bool kvm_rebooting; +static bool largepages_disabled = false; + #ifdef KVM_CAP_DEVICE_ASSIGNMENT static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head, int assigned_dev_id) @@ -1171,9 +1173,11 @@ int __kvm_set_memory_region(struct kvm * ugfn = new.userspace_addr >> PAGE_SHIFT; /* * If the gfn and userspace address are not aligned wrt each - * other, disable large page support for this slot + * other, or if explicitly asked to, disable large page + * support for this slot */ - if ((base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE - 1)) + if ((base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE - 1) || + largepages_disabled) for (i = 0; i < largepages; ++i) new.lpage_info[i].write_count = 1; } @@ -1286,6 +1290,12 @@ out: return r; } +void kvm_disable_largepages(void) +{ + largepages_disabled = true; +} +EXPORT_SYMBOL_GPL(kvm_disable_largepages); + int is_error_page(struct page *page) { return page == bad_page;