aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/vmx.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kvm/vmx.c')
-rw-r--r--arch/x86/kvm/vmx.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 141956ebf794..1896cada805f 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -180,6 +180,7 @@ static int init_rmode(struct kvm *kvm);
180static u64 construct_eptp(unsigned long root_hpa); 180static u64 construct_eptp(unsigned long root_hpa);
181static void kvm_cpu_vmxon(u64 addr); 181static void kvm_cpu_vmxon(u64 addr);
182static void kvm_cpu_vmxoff(void); 182static void kvm_cpu_vmxoff(void);
183static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
183 184
184static DEFINE_PER_CPU(struct vmcs *, vmxarea); 185static DEFINE_PER_CPU(struct vmcs *, vmxarea);
185static DEFINE_PER_CPU(struct vmcs *, current_vmcs); 186static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -1866,6 +1867,13 @@ static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)
1866 vcpu->arch.cr0 |= vmcs_readl(GUEST_CR0) & cr0_guest_owned_bits; 1867 vcpu->arch.cr0 |= vmcs_readl(GUEST_CR0) & cr0_guest_owned_bits;
1867} 1868}
1868 1869
1870static void vmx_decache_cr3(struct kvm_vcpu *vcpu)
1871{
1872 if (enable_ept && is_paging(vcpu))
1873 vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
1874 __set_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail);
1875}
1876
1869static void vmx_decache_cr4_guest_bits(struct kvm_vcpu *vcpu) 1877static void vmx_decache_cr4_guest_bits(struct kvm_vcpu *vcpu)
1870{ 1878{
1871 ulong cr4_guest_owned_bits = vcpu->arch.cr4_guest_owned_bits; 1879 ulong cr4_guest_owned_bits = vcpu->arch.cr4_guest_owned_bits;
@@ -1909,6 +1917,7 @@ static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
1909 unsigned long cr0, 1917 unsigned long cr0,
1910 struct kvm_vcpu *vcpu) 1918 struct kvm_vcpu *vcpu)
1911{ 1919{
1920 vmx_decache_cr3(vcpu);
1912 if (!(cr0 & X86_CR0_PG)) { 1921 if (!(cr0 & X86_CR0_PG)) {
1913 /* From paging/starting to nonpaging */ 1922 /* From paging/starting to nonpaging */
1914 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, 1923 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
@@ -3756,11 +3765,6 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
3756 if (vmx->emulation_required && emulate_invalid_guest_state) 3765 if (vmx->emulation_required && emulate_invalid_guest_state)
3757 return handle_invalid_guest_state(vcpu); 3766 return handle_invalid_guest_state(vcpu);
3758 3767
3759 /* Access CR3 don't cause VMExit in paging mode, so we need
3760 * to sync with guest real CR3. */
3761 if (enable_ept && is_paging(vcpu))
3762 vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
3763
3764 if (exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) { 3768 if (exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) {
3765 vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY; 3769 vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
3766 vcpu->run->fail_entry.hardware_entry_failure_reason 3770 vcpu->run->fail_entry.hardware_entry_failure_reason
@@ -4077,7 +4081,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
4077 ); 4081 );
4078 4082
4079 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP) 4083 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
4080 | (1 << VCPU_EXREG_PDPTR)); 4084 | (1 << VCPU_EXREG_PDPTR)
4085 | (1 << VCPU_EXREG_CR3));
4081 vcpu->arch.regs_dirty = 0; 4086 vcpu->arch.regs_dirty = 0;
4082 4087
4083 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); 4088 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
@@ -4344,6 +4349,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
4344 .get_cpl = vmx_get_cpl, 4349 .get_cpl = vmx_get_cpl,
4345 .get_cs_db_l_bits = vmx_get_cs_db_l_bits, 4350 .get_cs_db_l_bits = vmx_get_cs_db_l_bits,
4346 .decache_cr0_guest_bits = vmx_decache_cr0_guest_bits, 4351 .decache_cr0_guest_bits = vmx_decache_cr0_guest_bits,
4352 .decache_cr3 = vmx_decache_cr3,
4347 .decache_cr4_guest_bits = vmx_decache_cr4_guest_bits, 4353 .decache_cr4_guest_bits = vmx_decache_cr4_guest_bits,
4348 .set_cr0 = vmx_set_cr0, 4354 .set_cr0 = vmx_set_cr0,
4349 .set_cr3 = vmx_set_cr3, 4355 .set_cr3 = vmx_set_cr3,