* [PATCH][v2 1/3] KVM: x86: Check LMA bit before set_efer
2010-05-12 8:40 [PATCH][v2 0/3] Some MMU related fix/clean up Sheng Yang
@ 2010-05-12 8:40 ` Sheng Yang
2010-05-12 8:40 ` [PATCH][v2 2/3] KVM: Clean up duplicate assignment Sheng Yang
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Sheng Yang @ 2010-05-12 8:40 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang
kvm_x86_ops->set_efer() would execute vcpu->arch.efer = efer, so the
checking of LMA bit didn't work.
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
arch/x86/kvm/x86.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index cd8a606..2cae460 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -715,11 +715,11 @@ static int set_efer(struct kvm_vcpu *vcpu, u64 efer)
return 1;
}
- kvm_x86_ops->set_efer(vcpu, efer);
-
efer &= ~EFER_LMA;
efer |= vcpu->arch.efer & EFER_LMA;
+ kvm_x86_ops->set_efer(vcpu, efer);
+
vcpu->arch.efer = efer;
vcpu->arch.mmu.base_role.nxe = (efer & EFER_NX) && !tdp_enabled;
--
1.7.0.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH][v2 2/3] KVM: Clean up duplicate assignment
2010-05-12 8:40 [PATCH][v2 0/3] Some MMU related fix/clean up Sheng Yang
2010-05-12 8:40 ` [PATCH][v2 1/3] KVM: x86: Check LMA bit before set_efer Sheng Yang
@ 2010-05-12 8:40 ` Sheng Yang
2010-05-12 8:40 ` [PATCH][v2 3/3] VMX: x86: Only reset MMU when necessary Sheng Yang
2010-05-13 22:18 ` [PATCH][v2 0/3] Some MMU related fix/clean up Marcelo Tosatti
3 siblings, 0 replies; 7+ messages in thread
From: Sheng Yang @ 2010-05-12 8:40 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang
mmu.free() already set root_hpa to INVALID_PAGE, no need to do it again in the
destory_kvm_mmu().
kvm_x86_ops->set_cr4() and set_efer() already assign cr4/efer to
vcpu->arch.cr4/efer, no need to do it again later.
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
arch/x86/kvm/mmu.c | 5 ++---
arch/x86/kvm/x86.c | 4 +---
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 95bee9d..5412185 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2450,10 +2450,9 @@ static int init_kvm_mmu(struct kvm_vcpu *vcpu)
static void destroy_kvm_mmu(struct kvm_vcpu *vcpu)
{
ASSERT(vcpu);
- if (VALID_PAGE(vcpu->arch.mmu.root_hpa)) {
+ if (VALID_PAGE(vcpu->arch.mmu.root_hpa))
+ /* mmu.free() should set root_hpa = INVALID_PAGE */
vcpu->arch.mmu.free(vcpu);
- vcpu->arch.mmu.root_hpa = INVALID_PAGE;
- }
}
int kvm_mmu_reset_context(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2cae460..764f89b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -486,7 +486,7 @@ int __kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
return 1;
kvm_x86_ops->set_cr4(vcpu, cr4);
- vcpu->arch.cr4 = cr4;
+
kvm_mmu_reset_context(vcpu);
return 0;
@@ -720,8 +720,6 @@ static int set_efer(struct kvm_vcpu *vcpu, u64 efer)
kvm_x86_ops->set_efer(vcpu, efer);
- vcpu->arch.efer = efer;
-
vcpu->arch.mmu.base_role.nxe = (efer & EFER_NX) && !tdp_enabled;
kvm_mmu_reset_context(vcpu);
--
1.7.0.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH][v2 3/3] VMX: x86: Only reset MMU when necessary
2010-05-12 8:40 [PATCH][v2 0/3] Some MMU related fix/clean up Sheng Yang
2010-05-12 8:40 ` [PATCH][v2 1/3] KVM: x86: Check LMA bit before set_efer Sheng Yang
2010-05-12 8:40 ` [PATCH][v2 2/3] KVM: Clean up duplicate assignment Sheng Yang
@ 2010-05-12 8:40 ` Sheng Yang
2010-05-12 8:47 ` Avi Kivity
2010-05-13 22:18 ` [PATCH][v2 0/3] Some MMU related fix/clean up Marcelo Tosatti
3 siblings, 1 reply; 7+ messages in thread
From: Sheng Yang @ 2010-05-12 8:40 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang
Only modifying some bits of CR0/CR4 needs paging mode switch.
Modify EFER.NXE bit would result in reserved bit updates.
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
arch/x86/kvm/x86.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 764f89b..f442da2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -416,6 +416,10 @@ out:
static int __kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
{
+ unsigned long old_cr0 = kvm_read_cr0(vcpu);
+ unsigned long update_bits = X86_CR0_PG | X86_CR0_WP |
+ X86_CR0_CD | X86_CR0_NW;
+
cr0 |= X86_CR0_ET;
#ifdef CONFIG_X86_64
@@ -449,7 +453,8 @@ static int __kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
kvm_x86_ops->set_cr0(vcpu, cr0);
- kvm_mmu_reset_context(vcpu);
+ if ((cr0 ^ old_cr0) & update_bits)
+ kvm_mmu_reset_context(vcpu);
return 0;
}
@@ -487,7 +492,8 @@ int __kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
kvm_x86_ops->set_cr4(vcpu, cr4);
- kvm_mmu_reset_context(vcpu);
+ if ((cr4 ^ old_cr4) & pdptr_bits)
+ kvm_mmu_reset_context(vcpu);
return 0;
}
@@ -692,6 +698,8 @@ static u32 emulated_msrs[] = {
static int set_efer(struct kvm_vcpu *vcpu, u64 efer)
{
+ u64 old_efer = vcpu->arch.efer;
+
if (efer & efer_reserved_bits)
return 1;
@@ -723,6 +731,10 @@ static int set_efer(struct kvm_vcpu *vcpu, u64 efer)
vcpu->arch.mmu.base_role.nxe = (efer & EFER_NX) && !tdp_enabled;
kvm_mmu_reset_context(vcpu);
+ /* Update reserved bits */
+ if ((efer ^ old_efer) & EFER_NX)
+ kvm_mmu_reset_context(vcpu);
+
return 0;
}
--
1.7.0.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH][v2 3/3] VMX: x86: Only reset MMU when necessary
2010-05-12 8:40 ` [PATCH][v2 3/3] VMX: x86: Only reset MMU when necessary Sheng Yang
@ 2010-05-12 8:47 ` Avi Kivity
[not found] ` <201005121654.34980.sheng@linux.intel.com>
0 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2010-05-12 8:47 UTC (permalink / raw)
To: Sheng Yang; +Cc: Marcelo Tosatti, kvm
On 05/12/2010 11:40 AM, Sheng Yang wrote:
> Only modifying some bits of CR0/CR4 needs paging mode switch.
>
> Modify EFER.NXE bit would result in reserved bit updates.
>
> Signed-off-by: Sheng Yang<sheng@linux.intel.com>
> ---
> arch/x86/kvm/x86.c | 16 ++++++++++++++--
> 1 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 764f89b..f442da2 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -416,6 +416,10 @@ out:
>
> static int __kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
> {
> + unsigned long old_cr0 = kvm_read_cr0(vcpu);
> + unsigned long update_bits = X86_CR0_PG | X86_CR0_WP |
> + X86_CR0_CD | X86_CR0_NW;
> +
>
CR0_WP...
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][v2 0/3] Some MMU related fix/clean up
2010-05-12 8:40 [PATCH][v2 0/3] Some MMU related fix/clean up Sheng Yang
` (2 preceding siblings ...)
2010-05-12 8:40 ` [PATCH][v2 3/3] VMX: x86: Only reset MMU when necessary Sheng Yang
@ 2010-05-13 22:18 ` Marcelo Tosatti
3 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2010-05-13 22:18 UTC (permalink / raw)
To: Sheng Yang; +Cc: Avi Kivity, kvm
On Wed, May 12, 2010 at 04:40:39PM +0800, Sheng Yang wrote:
> Sheng Yang (3):
> KVM: x86: Check LMA bit before set_efer
> KVM: Clean up duplicate assignment
> VMX: x86: Only reset MMU when necessary
>
> arch/x86/kvm/mmu.c | 5 ++---
> arch/x86/kvm/x86.c | 22 ++++++++++++++++------
> 2 files changed, 18 insertions(+), 9 deletions(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread