Skip to contentSkip to conversation

KVM: MMU: Disassociate direct maps from guest levels

PATCH In review Avi Kivity 3 participants 6 messages Mar 14, 2010 – Mar 23, 2010

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 KVM: MMU: Disassociate direct maps from guest levels

Direct maps are linear translations for a section of memory, used for real mode or with large pages. As such, they are independent of the guest levels.

Teach the mmu about this by making page->role.glevels = 0 for direct maps. This allows direct maps to be shared among real mode and the various paging modes.

---
 arch/x86/kvm/mmu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/mmu.c +2 -0
index b137515..a984bc1 100644
@@ -1328,6 +1328,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
 	role = vcpu->arch.mmu.base_role;
 	role.level = level;
 	role.direct = direct;
+	if (role.direct)
+		role.glevels = 0;
 	role.access = access;
 	if (vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
 		quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
Signature · 1 line
1.7.0.2
#1 lore raw
Quoted 28 lines · Avi Kivity

Direct maps are linear translations for a section of memory, used for real mode or with large pages. As such, they are independent of the guest levels.

Teach the mmu about this by making page->role.glevels = 0 for direct maps. This allows direct maps to be shared among real mode and the various paging modes.

---
 arch/x86/kvm/mmu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/mmu.c +2 -0
index b137515..a984bc1 100644
@@ -1328,6 +1328,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
 	role = vcpu->arch.mmu.base_role;
 	role.level = level;
 	role.direct = direct;
+	if (role.direct)
+		role.glevels = 0;
 	role.access = access;
 	if (vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
 		quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
Signature · 1 line
1.7.0.2

Isnt this what happens already, since for tdp base_role.glevels is not initialized?

author
#2 lore raw
Quoted 10 lines · Marcelo Tosatti
Quoted 8 lines · Avi Kivity

Direct maps are linear translations for a section of memory, used for real mode or with large pages. As such, they are independent of the guest levels.

Teach the mmu about this by making page->role.glevels = 0 for direct maps. This allows direct maps to be shared among real mode and the various paging modes.

Quoted 15 lines
Quoted 12 lines
arch/x86/kvm/mmu.c +2 -0
@@ -1328,6 +1328,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
  	role = vcpu->arch.mmu.base_role;
  	role.level = level;
  	role.direct = direct;
+	if (role.direct)
+		role.glevels = 0;
  	role.access = access;
  	if (vcpu->arch.mmu.root_level<= PT32_ROOT_LEVEL) {
  		quadrant = gaddr>>  (PAGE_SHIFT + (PT64_PT_BITS * level));
Signature · 1 line
1.7.0.2

Isnt this what happens already, since for tdp base_role.glevels is not initialized?

Correct. I was thinking about the nested npt case, which will use role.glevels. Joerg, please incorporate this into your nnpt patchset.

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw
Quoted 27 lines · Avi Kivity
Quoted 10 lines · Marcelo Tosatti
Quoted 8 lines · Avi Kivity

Direct maps are linear translations for a section of memory, used for real mode or with large pages. As such, they are independent of the guest levels.

Teach the mmu about this by making page->role.glevels = 0 for direct maps. This allows direct maps to be shared among real mode and the various paging modes.

Quoted 15 lines
Quoted 12 lines
arch/x86/kvm/mmu.c +2 -0
@@ -1328,6 +1328,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
  	role = vcpu->arch.mmu.base_role;
  	role.level = level;
  	role.direct = direct;
+	if (role.direct)
+		role.glevels = 0;
  	role.access = access;
  	if (vcpu->arch.mmu.root_level<= PT32_ROOT_LEVEL) {
  		quadrant = gaddr>>  (PAGE_SHIFT + (PT64_PT_BITS * level));
Signature · 1 line
1.7.0.2

Isnt this what happens already, since for tdp base_role.glevels is not initialized?

Quoted 2 lines

Correct. I was thinking about the nested npt case, which will use role.glevels. Joerg, please incorporate this into your nnpt patchset.

Yes will do. I am currently out-of-office until April 6th. Expect a re-send of the patch-set some time after that :-)

Joerg

author
#4 lore raw
In reply to Avi Kivity
Quoted 25 lines · Avi Kivity
Quoted 9 lines · Marcelo Tosatti
Quoted 8 lines · Avi Kivity

Direct maps are linear translations for a section of memory, used for real mode or with large pages. As such, they are independent of the guest levels.

Teach the mmu about this by making page->role.glevels = 0 for direct maps. This allows direct maps to be shared among real mode and the various paging modes.

Quoted 14 lines
Quoted 9 lines
arch/x86/kvm/mmu.c +2 -0
@@ -1328,6 +1328,8 @@ static struct kvm_mmu_page 
 *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
      role = vcpu->arch.mmu.base_role;
      role.level = level;
      role.direct = direct;
+    if (role.direct)
+        role.glevels = 0;
      role.access = access;
      if (vcpu->arch.mmu.root_level<= PT32_ROOT_LEVEL) {
Quoted 3 lines
          quadrant = gaddr>>  (PAGE_SHIFT + (PT64_PT_BITS * level));
Signature · 1 line
1.7.0.2

Isnt this what happens already, since for tdp base_role.glevels is not initialized?

Quoted 2 lines

Correct. I was thinking about the nested npt case, which will use role.glevels. Joerg, please incorporate this into your nnpt patchset.

Actually, incorrect. This patch is also applicable to non-tdp (which is the same case as nnpt). It will allow reusing real-mode direct maps and large page mappings from the various modes. It won't make any performance difference, it's more a documentation aid that direct maps aren't dependent on the guest at all, except for permissions.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw
Quoted 34 lines · Avi Kivity
Quoted 28 lines · Avi Kivity
Quoted 12 lines · Marcelo Tosatti
Quoted 11 lines · Avi Kivity

Direct maps are linear translations for a section of memory, used for real mode or with large pages. As such, they are independent of the guest
levels.

Teach the mmu about this by making page->role.glevels = 0 for direct maps.
This allows direct maps to be shared among real mode and the various paging
modes.

Quoted 14 lines
Quoted 9 lines
arch/x86/kvm/mmu.c +2 -0
@@ -1328,6 +1328,8 @@ static struct kvm_mmu_page
 *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
     role = vcpu->arch.mmu.base_role;
     role.level = level;
     role.direct = direct;
+    if (role.direct)
+        role.glevels = 0;
     role.access = access;
     if (vcpu->arch.mmu.root_level<= PT32_ROOT_LEVEL) {
Quoted 3 lines
         quadrant = gaddr>>  (PAGE_SHIFT + (PT64_PT_BITS * level));
Signature · 1 line
1.7.0.2

Isnt this what happens already, since for tdp base_role.glevels is not initialized?

Quoted 4 lines

Correct. I was thinking about the nested npt case, which will use role.glevels. Joerg, please incorporate this into your nnpt patchset.

Quoted 6 lines

Actually, incorrect. This patch is also applicable to non-tdp (which is the same case as nnpt). It will allow reusing real-mode direct maps and large page mappings from the various modes. It won't make any performance difference, it's more a documentation aid that direct maps aren't dependent on the guest at all, except for permissions.

Sure, makes sense.