Skip to contentSkip to conversation

EPT 1GB page support

PATCH Superseded Sheng Yang 2 participants 6 messages Jan 5, 2010

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/3 KVM: x86: Rename gb_page_enable() to get_lpage_level() in kvm_x86_ops

Then the callback can provide the maximum supported large page level, which is more flexible.

Also move the gb page support into x86_64 specific.

---
 arch/x86/include/asm/kvm_host.h |    2 +-
 arch/x86/kvm/svm.c              |    6 +++---
 arch/x86/kvm/vmx.c              |    6 +++---
 arch/x86/kvm/x86.c              |    5 ++++-
 4 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
index fe4df46..31b986f 100644
@@ -520,7 +520,7 @@ struct kvm_x86_ops {
 	int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
 	int (*get_tdp_level)(void);
 	u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio);
-	bool (*gb_page_enable)(void);
+	int (*get_lpage_level)(void);
 	bool (*rdtscp_supported)(void);
 
 	const struct trace_print_flags *exit_reasons_str;
arch/x86/kvm/svm.c +3 -3
index b373ae6..c0153de 100644
@@ -2911,9 +2911,9 @@ static const struct trace_print_flags svm_exit_reasons_str[] = {
 	{ -1, NULL }
 };
 
-static bool svm_gb_page_enable(void)
+static int svm_get_lpage_level(void)
 {
-	return true;
+	return 3; /* PT_PDPE_LEVEL */
 }
 
 static bool svm_rdtscp_supported(void)
@@ -2986,7 +2986,7 @@ static struct kvm_x86_ops svm_x86_ops = {
 	.get_mt_mask = svm_get_mt_mask,
 
 	.exit_reasons_str = svm_exit_reasons_str,
-	.gb_page_enable = svm_gb_page_enable,
+	.get_lpage_level = svm_get_lpage_level,
 
 	.cpuid_update = svm_cpuid_update,
 
arch/x86/kvm/vmx.c +3 -3
index 2cc9b7e..c5b5ff6 100644
@@ -4011,9 +4011,9 @@ static const struct trace_print_flags vmx_exit_reasons_str[] = {
 	{ -1, NULL }
 };
 
-static bool vmx_gb_page_enable(void)
+static int vmx_get_lpage_level(void)
 {
-	return false;
+	return 2; /* PT_DIRECTORY_LEVEL */
 }
 
 static inline u32 bit(int bitno)
@@ -4106,7 +4106,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
 	.get_mt_mask = vmx_get_mt_mask,
 
 	.exit_reasons_str = vmx_exit_reasons_str,
-	.gb_page_enable = vmx_gb_page_enable,
+	.get_lpage_level = vmx_get_lpage_level,
 
 	.cpuid_update = vmx_cpuid_update,
 
arch/x86/kvm/x86.c +4 -1
index fd6e1a5..2968dd0 100644
@@ -1641,10 +1641,13 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
 			 u32 index, int *nent, int maxnent)
 {
 	unsigned f_nx = is_efer_nx() ? F(NX) : 0;
-	unsigned f_gbpages = kvm_x86_ops->gb_page_enable() ? F(GBPAGES) : 0;
 #ifdef CONFIG_X86_64
+	/* PT_PDPE_LEVEL (mapping 1GB page) is 3 */
+	unsigned f_gbpages = (kvm_x86_ops->get_lpage_level() == 3) ?
+				F(GBPAGES) : 0;
 	unsigned f_lm = F(LM);
 #else
+	unsigned f_gbpages = 0;
 	unsigned f_lm = 0;
 #endif
 	unsigned f_rdtscp = kvm_x86_ops->rdtscp_supported() ? F(RDTSCP) : 0;
Signature · 1 line
1.5.4.5
author
#2 lore raw

PATCH 2/3 KVM: x86: Fix host_mapping_level()

In reply to Sheng Yang

When found a error hva, should not return PAGE_SIZE but the level...

Also clean up the coding style of the following loop.

---
 arch/x86/kvm/mmu.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu.c +2 -4
index c43c2ab..4f499d7 100644
@@ -477,7 +477,7 @@ static int host_mapping_level(struct kvm *kvm, gfn_t gfn)
 
 	addr = gfn_to_hva(kvm, gfn);
 	if (kvm_is_error_hva(addr))
-		return page_size;
+		return PT_PAGE_TABLE_LEVEL;
 
 	down_read(&current->mm->mmap_sem);
 	vma = find_vma(current->mm, addr);
@@ -515,11 +515,9 @@ 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) {
-
+	for (level = PT_DIRECTORY_LEVEL; level <= host_level; ++level)
 		if (has_wrprotected_page(vcpu->kvm, large_gfn, level))
 			break;
-	}
 
 	return level - 1;
 }
Signature · 1 line
1.5.4.5
author
#3 lore raw

PATCH 3/3 KVM: VMX: Enable EPT 1GB page support

In reply to Sheng Yang
---
 arch/x86/include/asm/vmx.h |    1 +
 arch/x86/kvm/mmu.c         |    8 +++++---
 arch/x86/kvm/vmx.c         |   11 ++++++++++-
 3 files changed, 16 insertions(+), 4 deletions(-)
arch/x86/include/asm/vmx.h +1 -0
index 713ed9a..43f1e9b 100644
@@ -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)
arch/x86/kvm/mmu.c +5 -3
index 4f499d7..3cfd204 100644
@@ -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;
 
arch/x86/kvm/vmx.c +10 -1
index c5b5ff6..a6f72b5 100644
@@ -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)
Signature · 1 line
1.5.4.5
#4 lore raw

Re: [PATCH 3/3] KVM: VMX: Enable EPT 1GB page support

Quoted 12 lines · Sheng Yang
---
  arch/x86/include/asm/vmx.h |    1 +
  arch/x86/kvm/mmu.c         |    8 +++++---
  arch/x86/kvm/vmx.c         |   11 ++++++++++-
  3 files changed, 16 insertions(+), 4 deletions(-)
arch/x86/include/asm/vmx.h +0 -0
index 713ed9a..43f1e9b 100644

arch/x86/include/asm/vmx.h enum vmcs_field { · line 368

Quoted 5 lines
arch/x86/include/asm/vmx.h +1 -0
@@ -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)
 

Can you share when this feature will be available in hardware?

arch/x86/include/asm/vmx.h enum vmcs_field {

Quoted 11 lines
arch/x86/include/asm/vmx.h +5 -1
  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 */
  }

Why not use the defines instead of numbers? It will reduce change when we change PT_*_LEVEL to be zero based instead of one based.

Patchset looks good; second patch should go into .33 and stable, no?

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#5 lore raw

Re: [PATCH 3/3] KVM: VMX: Enable EPT 1GB page support

Quoted 8 lines · On Tuesday 05 January 2010 18:43:21 Avi Kivity wrote:
Quoted 7 lines · Sheng Yang
---
  arch/x86/include/asm/vmx.h |    1 +
  arch/x86/kvm/mmu.c         |    8 +++++---
  arch/x86/kvm/vmx.c         |   11 ++++++++++-
  3 files changed, 16 insertions(+), 4 deletions(-)
Quoted 11 lines

arch/x86/include/asm/vmx.h enum vmcs_field { · line 367

Quoted 9 lines
arch/x86/include/asm/vmx.h +1 -0
index 713ed9a..43f1e9b 100644
@@ -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)

Can you share when this feature will be available in hardware?

I think it should be with the 32nm Core i7 (at least highend server edition), slated for early 2010 release.

Quoted 13 lines

arch/x86/include/asm/vmx.h enum vmcs_field {

Quoted 10 lines
arch/x86/include/asm/vmx.h +5 -1
  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 */
  }

Why not use the defines instead of numbers? It will reduce change when we change PT_*_LEVEL to be zero based instead of one based.

Oh, sure (caused by a little chaos in mind...). Patch 1 is also affected(cpuid). Would resent the patchset soon.

Quoted 3 lines

Patchset looks good; second patch should go into .33 and stable, no?

Sure. I would cc stable later.

Signature · 2 lines
regards
Yang, Sheng