Skip to contentSkip to conversation

KVM: MMU: record maximum physical address width in kvm_mmu_extended_role

PATCH Applied Yu Zhang 3 participants 5 messages Jan 31, 2019 – Feb 22, 2019

Subsystems (3)
lore
Share & tools
lore

Yu Zhang

author
#0 lore raw

PATCH 1/1 KVM: MMU: record maximum physical address width in kvm_mmu_extended_role

Previously, commit 7dcd57552008 ("x86/kvm/mmu: check if tdp/shadow MMU reconfiguration is needed") offered some optimization to avoid the unnecessary reconfiguration. Yet one scenario is broken - when cpuid changes VM's maximum physical address width, reconfiguration is needed to reset the reserved bits. Also, the TDP may need to reset its shadow_root_level when this value is changed.

To fix this, a new field, maxphyaddr, is introduced in the extended role structure to keep track of the configured guest physical address width.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/mmu.c              | 1 +
 2 files changed, 2 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index 4660ce9..be87f71 100644
@@ -299,6 +299,7 @@ struct kvm_mmu_memory_cache {
 		unsigned int cr4_smap:1;
 		unsigned int cr4_smep:1;
 		unsigned int cr4_la57:1;
+		unsigned int maxphyaddr:6;
 	};
 };
 
arch/x86/kvm/mmu.c +1 -0
index ce770b4..2b74505 100644
@@ -4769,6 +4769,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu)
 	ext.cr4_pse = !!is_pse(vcpu);
 	ext.cr4_pke = !!kvm_read_cr4_bits(vcpu, X86_CR4_PKE);
 	ext.cr4_la57 = !!kvm_read_cr4_bits(vcpu, X86_CR4_LA57);
+	ext.maxphyaddr = cpuid_maxphyaddr(vcpu);
 
 	ext.valid = 1;
 
Signature · 1 line
1.9.1
author
#1 lore raw

Hi Paolo, any comments on this patch? And the other one(kvm: x86: Return LA57 feature based on hardware capability )? :-)

Quoted 52 lines · Yu Zhang

Previously, commit 7dcd57552008 ("x86/kvm/mmu: check if tdp/shadow MMU reconfiguration is needed") offered some optimization to avoid the unnecessary reconfiguration. Yet one scenario is broken - when cpuid changes VM's maximum physical address width, reconfiguration is needed to reset the reserved bits. Also, the TDP may need to reset its shadow_root_level when this value is changed.

To fix this, a new field, maxphyaddr, is introduced in the extended role structure to keep track of the configured guest physical address width.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/mmu.c              | 1 +
 2 files changed, 2 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index 4660ce9..be87f71 100644
@@ -299,6 +299,7 @@ struct kvm_mmu_memory_cache {
 		unsigned int cr4_smap:1;
 		unsigned int cr4_smep:1;
 		unsigned int cr4_la57:1;
+		unsigned int maxphyaddr:6;
 	};
 };
 
arch/x86/kvm/mmu.c +1 -0
index ce770b4..2b74505 100644
@@ -4769,6 +4769,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu)
 	ext.cr4_pse = !!is_pse(vcpu);
 	ext.cr4_pke = !!kvm_read_cr4_bits(vcpu, X86_CR4_PKE);
 	ext.cr4_la57 = !!kvm_read_cr4_bits(vcpu, X86_CR4_LA57);
+	ext.maxphyaddr = cpuid_maxphyaddr(vcpu);
 
 	ext.valid = 1;
 
Signature · 1 line
1.9.1

Thanks
Yu

maintainer Applied
#2 lore raw
Quoted 2 lines · Yu Zhang

Hi Paolo, any comments on this patch? And the other one(kvm: x86: Return LA57 feature based on hardware capability )? :-)

Queued both, thanks.

Paolo

Quoted 57 lines · Yu Zhang
Quoted 52 lines

Previously, commit 7dcd57552008 ("x86/kvm/mmu: check if tdp/shadow MMU reconfiguration is needed") offered some optimization to avoid the unnecessary reconfiguration. Yet one scenario is broken - when cpuid changes VM's maximum physical address width, reconfiguration is needed to reset the reserved bits. Also, the TDP may need to reset its shadow_root_level when this value is changed.

To fix this, a new field, maxphyaddr, is introduced in the extended role structure to keep track of the configured guest physical address width.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/mmu.c              | 1 +
 2 files changed, 2 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index 4660ce9..be87f71 100644
@@ -299,6 +299,7 @@ struct kvm_mmu_memory_cache {
 		unsigned int cr4_smap:1;
 		unsigned int cr4_smep:1;
 		unsigned int cr4_la57:1;
+		unsigned int maxphyaddr:6;
 	};
 };
 
arch/x86/kvm/mmu.c +1 -0
index ce770b4..2b74505 100644
@@ -4769,6 +4769,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu)
 	ext.cr4_pse = !!is_pse(vcpu);
 	ext.cr4_pke = !!kvm_read_cr4_bits(vcpu, X86_CR4_PKE);
 	ext.cr4_la57 = !!kvm_read_cr4_bits(vcpu, X86_CR4_LA57);
+	ext.maxphyaddr = cpuid_maxphyaddr(vcpu);
 
 	ext.valid = 1;
 
Signature · 1 line
1.9.1

Thanks
Yu

Reviewed-by on v1 1/1
#3 lore raw
In reply to Yu Zhang
Quoted 42 lines · Yu Zhang

Previously, commit 7dcd57552008 ("x86/kvm/mmu: check if tdp/shadow MMU reconfiguration is needed") offered some optimization to avoid the unnecessary reconfiguration. Yet one scenario is broken - when cpuid changes VM's maximum physical address width, reconfiguration is needed to reset the reserved bits. Also, the TDP may need to reset its shadow_root_level when this value is changed.

To fix this, a new field, maxphyaddr, is introduced in the extended role structure to keep track of the configured guest physical address width.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/mmu.c              | 1 +
 2 files changed, 2 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index 4660ce9..be87f71 100644
@@ -299,6 +299,7 @@ struct kvm_mmu_memory_cache {
 		unsigned int cr4_smap:1;
 		unsigned int cr4_smep:1;
 		unsigned int cr4_la57:1;
+		unsigned int maxphyaddr:6;
 	};
 };
 
arch/x86/kvm/mmu.c +0 -0
index ce770b4..2b74505 100644

arch/x86/kvm/mmu.c static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu) · line 4774

Quoted 6 lines
arch/x86/kvm/mmu.c +1 -0
@@ -4769,6 +4769,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu)
 	ext.cr4_pse = !!is_pse(vcpu);
 	ext.cr4_pke = !!kvm_read_cr4_bits(vcpu, X86_CR4_PKE);
 	ext.cr4_la57 = !!kvm_read_cr4_bits(vcpu, X86_CR4_LA57);
+	ext.maxphyaddr = cpuid_maxphyaddr(vcpu);
 
 	ext.valid = 1;

It seems that we can now drop 'valid' from role_ext as maxphyaddr can't be 0.

Signature · 1 line
Vitaly
author
#4 lore raw
Quoted 49 lines · Vitaly Kuznetsov
Quoted 47 lines · Yu Zhang

Previously, commit 7dcd57552008 ("x86/kvm/mmu: check if tdp/shadow MMU reconfiguration is needed") offered some optimization to avoid the unnecessary reconfiguration. Yet one scenario is broken - when cpuid changes VM's maximum physical address width, reconfiguration is needed to reset the reserved bits. Also, the TDP may need to reset its shadow_root_level when this value is changed.

To fix this, a new field, maxphyaddr, is introduced in the extended role structure to keep track of the configured guest physical address width.

---
Cc: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/mmu.c              | 1 +
 2 files changed, 2 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
index 4660ce9..be87f71 100644
@@ -299,6 +299,7 @@ struct kvm_mmu_memory_cache {
 		unsigned int cr4_smap:1;
 		unsigned int cr4_smep:1;
 		unsigned int cr4_la57:1;
+		unsigned int maxphyaddr:6;
 	};
 };
 
arch/x86/kvm/mmu.c +1 -0
index ce770b4..2b74505 100644
@@ -4769,6 +4769,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu)
 	ext.cr4_pse = !!is_pse(vcpu);
 	ext.cr4_pke = !!kvm_read_cr4_bits(vcpu, X86_CR4_PKE);
 	ext.cr4_la57 = !!kvm_read_cr4_bits(vcpu, X86_CR4_LA57);
+	ext.maxphyaddr = cpuid_maxphyaddr(vcpu);
 
Quoted 4 lines

arch/x86/kvm/mmu.c static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu) · line 4774

Quoted 1 line
arch/x86/kvm/mmu.c +0 -0
 	ext.valid = 1;

It seems that we can now drop 'valid' from role_ext as maxphyaddr can't be 0.

Thanks, Vitaly. Yes, we can drop this field. :)

Quoted 6 lines
Signature · 1 line
Vitaly

B.R.
Yu