KVM: prevent spurious exit to userspace during task switch emulation.
authorGleb Natapov <gleb@redhat.com>
Thu, 15 Apr 2010 18:03:50 +0000 (21:03 +0300)
committerAvi Kivity <avi@redhat.com>
Mon, 17 May 2010 09:17:55 +0000 (12:17 +0300)
If kvm_task_switch() fails code exits to userspace without specifying
exit reason, so the previous exit reason is reused by userspace. Fix
this by specifying exit reason correctly.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c

index 78af52222fd2d9f58ecb2e42b061702100e2dbca..ab78eb8ba899e59281a58b9df37a40c63ec68e80 100644 (file)
@@ -2266,8 +2266,14 @@ static int task_switch_interception(struct vcpu_svm *svm)
             (int_vec == OF_VECTOR || int_vec == BP_VECTOR)))
                skip_emulated_instruction(&svm->vcpu);
 
-       return kvm_task_switch(&svm->vcpu, tss_selector, reason,
-                              has_error_code, error_code);
+       if (kvm_task_switch(&svm->vcpu, tss_selector, reason,
+                               has_error_code, error_code) == EMULATE_FAIL) {
+               svm->vcpu.run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+               svm->vcpu.run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
+               svm->vcpu.run->internal.ndata = 0;
+               return 0;
+       }
+       return 1;
 }
 
 static int cpuid_interception(struct vcpu_svm *svm)
index 1b38d8a88cf70fc7360560f6ece12fb43238c75f..6e5e75e0d7d3eabf0d930d1d79587acd8e05a44c 100644 (file)
@@ -3316,9 +3316,13 @@ static int handle_task_switch(struct kvm_vcpu *vcpu)
                       type != INTR_TYPE_NMI_INTR))
                skip_emulated_instruction(vcpu);
 
-       if (!kvm_task_switch(vcpu, tss_selector, reason, has_error_code,
-                            error_code))
+       if (kvm_task_switch(vcpu, tss_selector, reason,
+                               has_error_code, error_code) == EMULATE_FAIL) {
+               vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+               vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
+               vcpu->run->internal.ndata = 0;
                return 0;
+       }
 
        /* clear all local breakpoint enable flags */
        vmcs_writel(GUEST_DR7, vmcs_readl(GUEST_DR7) & ~55);