From patchwork Tue Jan 5 10:12:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 70957 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o05AEdXG029546 for ; Tue, 5 Jan 2010 10:14:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753636Ab0AEKOg (ORCPT ); Tue, 5 Jan 2010 05:14:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751396Ab0AEKOf (ORCPT ); Tue, 5 Jan 2010 05:14:35 -0500 Received: from mga02.intel.com ([134.134.136.20]:40499 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753663Ab0AEKOc (ORCPT ); Tue, 5 Jan 2010 05:14:32 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 05 Jan 2010 02:14:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.47,504,1257148800"; d="scan'208";a="584395118" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.36.76]) by orsmga001.jf.intel.com with ESMTP; 05 Jan 2010 02:14:04 -0800 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1NS6P9-00032B-0T; Tue, 05 Jan 2010 18:12:47 +0800 From: Sheng Yang To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, Sheng Yang Subject: [PATCH 3/3] KVM: VMX: Enable EPT 1GB page support Date: Tue, 5 Jan 2010 18:12:41 +0800 Message-Id: <1262686361-11630-4-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1262686361-11630-1-git-send-email-sheng@linux.intel.com> References: <1262686361-11630-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 713ed9a..43f1e9b 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -364,6 +364,7 @@ enum vmcs_field { #define VMX_EPTP_UC_BIT (1ull << 8) #define VMX_EPTP_WB_BIT (1ull << 14) #define VMX_EPT_2MB_PAGE_BIT (1ull << 16) +#define VMX_EPT_1GB_PAGE_BIT (1ull << 17) #define VMX_EPT_EXTENT_INDIVIDUAL_BIT (1ull << 24) #define VMX_EPT_EXTENT_CONTEXT_BIT (1ull << 25) #define VMX_EPT_EXTENT_GLOBAL_BIT (1ull << 26) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 4f499d7..3cfd204 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -503,8 +503,7 @@ out: static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) { struct kvm_memory_slot *slot; - int host_level; - int level = PT_PAGE_TABLE_LEVEL; + int host_level, level, max_level; slot = gfn_to_memslot(vcpu->kvm, large_gfn); if (slot && slot->dirty_bitmap) @@ -515,7 +514,10 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) if (host_level == PT_PAGE_TABLE_LEVEL) return host_level; - for (level = PT_DIRECTORY_LEVEL; level <= host_level; ++level) + max_level = kvm_x86_ops->get_lpage_level() < host_level ? + kvm_x86_ops->get_lpage_level() : host_level; + + for (level = PT_DIRECTORY_LEVEL; level <= max_level; ++level) if (has_wrprotected_page(vcpu->kvm, large_gfn, level)) break; diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index c5b5ff6..a6f72b5 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -318,6 +318,11 @@ static inline bool cpu_has_vmx_ept_2m_page(void) return !!(vmx_capability.ept & VMX_EPT_2MB_PAGE_BIT); } +static inline bool cpu_has_vmx_ept_1g_page(void) +{ + return !!(vmx_capability.ept & VMX_EPT_1GB_PAGE_BIT); +} + static inline int cpu_has_vmx_invept_individual_addr(void) { return !!(vmx_capability.ept & VMX_EPT_EXTENT_INDIVIDUAL_BIT); @@ -4013,7 +4018,11 @@ static const struct trace_print_flags vmx_exit_reasons_str[] = { static int vmx_get_lpage_level(void) { - return 2; /* PT_DIRECTORY_LEVEL */ + if (enable_ept && !cpu_has_vmx_ept_1g_page()) + return 2; /* PT_DIRECTORY_LEVEL */ + else + /* For shadow and EPT supported 1GB page */ + return 3; /* PT_PDPE_LEVEL */ } static inline u32 bit(int bitno)