Skip to contentSkip to conversation

kvm mmu: optimizations when tdp is in use

PATCH In review Gui Jianfeng 3 participants 4 messages May 27, 2010 – May 28, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm mmu: optimizations when tdp is in use

In case of using tdp, checking write protected page isn't needed and quadrant also no need to be calculated.

---
 arch/x86/kvm/mmu.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu.c +5 -2
index 0bb9f17..ce4bbd3 100644
@@ -495,10 +495,13 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)
 	max_level = kvm_x86_ops->get_lpage_level() < host_level ?
 		kvm_x86_ops->get_lpage_level() : host_level;
 
+	if (tdp_enabled)
+		goto done;
+
 	for (level = PT_DIRECTORY_LEVEL; level <= max_level; ++level)
 		if (has_wrprotected_page(vcpu->kvm, large_gfn, level))
 			break;
-
+done:
 	return level - 1;
 }
 
@@ -1346,7 +1349,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
 	if (role.direct)
 		role.cr4_pae = 0;
 	role.access = access;
-	if (vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
+	if (!tdp_enabled && vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
 		quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
 		quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
 		role.quadrant = quadrant;
Signature · 1 line
1.6.5.2
#1 lore raw
Quoted 18 lines · Gui Jianfeng

In case of using tdp, checking write protected page isn't needed and quadrant also no need to be calculated.

---
  arch/x86/kvm/mmu.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu.c +1 -0
index 0bb9f17..ce4bbd3 100644
@@ -495,10 +495,13 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)
  	max_level = kvm_x86_ops->get_lpage_level()<  host_level ?
  		kvm_x86_ops->get_lpage_level() : host_level;
 
+	if (tdp_enabled)

arch/x86/kvm/mmu.c static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) · line 507

Quoted 10 lines
arch/x86/kvm/mmu.c +3 -1
+		goto done;
+
  	for (level = PT_DIRECTORY_LEVEL; level<= max_level; ++level)
  		if (has_wrprotected_page(vcpu->kvm, large_gfn, level))
  			break;
-
+done:
  	return level - 1;
  }
 

We also use ->write_count to prevent mapping the end of a non-large-page-aligned memslot with a large spte.

Undocumented in mmu.txt, I'll post a patch.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
In reply to Gui Jianfeng
Quoted 13 lines · Gui Jianfeng

In case of using tdp, checking write protected page isn't needed and quadrant also no need to be calculated.

---
 arch/x86/kvm/mmu.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu.c +0 -0
index 0bb9f17..ce4bbd3 100644

arch/x86/kvm/mmu.c static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) · line 500

Quoted 6 lines
arch/x86/kvm/mmu.c +3 -0
@@ -495,10 +495,13 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)
 	max_level = kvm_x86_ops->get_lpage_level() < host_level ?
 		kvm_x86_ops->get_lpage_level() : host_level;
 
+	if (tdp_enabled)
+		goto done;
+

This is wrong. write_count is initialized for alignment purposes, not only write protected pages. See __kvm_set_memory_region in virt/kvm/kvm_main.c.

Quoted 23 lines
arch/x86/kvm/mmu.c +2 -2
 	for (level = PT_DIRECTORY_LEVEL; level <= max_level; ++level)
 		if (has_wrprotected_page(vcpu->kvm, large_gfn, level))
 			break;
-
+done:
 	return level - 1;
 }
 
@@ -1346,7 +1349,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
 	if (role.direct)
 		role.cr4_pae = 0;
 	role.access = access;
-	if (vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
+	if (!tdp_enabled && vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
 		quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
 		quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
 		role.quadrant = quadrant;
Signature · 5 lines
1.6.5.2
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 17 lines · Marcelo Tosatti
Quoted 16 lines · Gui Jianfeng

In case of using tdp, checking write protected page isn't needed and quadrant also no need to be calculated.

---
 arch/x86/kvm/mmu.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu.c +0 -0
index 0bb9f17..ce4bbd3 100644
@@ -495,10 +495,13 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)
 	max_level = kvm_x86_ops->get_lpage_level() < host_level ?
 		kvm_x86_ops->get_lpage_level() : host_level;
 
Quoted 7 lines

arch/x86/kvm/mmu.c static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) · line 500

Quoted 3 lines
arch/x86/kvm/mmu.c +3 -0
+	if (tdp_enabled)
+		goto done;
+

This is wrong. write_count is initialized for alignment purposes, not only write protected pages. See __kvm_set_memory_region in virt/kvm/kvm_main.c.

thanks, avi also pointed this out.

Gui

Quoted 26 lines
Quoted 24 lines
arch/x86/kvm/mmu.c +2 -2
 	for (level = PT_DIRECTORY_LEVEL; level <= max_level; ++level)
 		if (has_wrprotected_page(vcpu->kvm, large_gfn, level))
 			break;
-
+done:
 	return level - 1;
 }
 
@@ -1346,7 +1349,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
 	if (role.direct)
 		role.cr4_pae = 0;
 	role.access = access;
-	if (vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
+	if (!tdp_enabled && vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
 		quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
 		quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
 		role.quadrant = quadrant;
Signature · 5 lines
1.6.5.2
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Regards
Gui Jianfeng