Merge branches 'for-2639/i2c/i2c-ce4100-v6', 'for-2639/i2c/i2c-eg20t-v3' and 'for...
[pandora-kernel.git] / arch / x86 / kvm / vmx.c
index 3febb76..5b4cdcb 100644 (file)
@@ -180,6 +180,7 @@ static u64 construct_eptp(unsigned long root_hpa);
 static void kvm_cpu_vmxon(u64 addr);
 static void kvm_cpu_vmxoff(void);
 static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
+static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr);
 
 static DEFINE_PER_CPU(struct vmcs *, vmxarea);
 static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -1762,6 +1763,18 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
        vmx->emulation_required = 1;
        vmx->rmode.vm86_active = 1;
 
+       /*
+        * Very old userspace does not call KVM_SET_TSS_ADDR before entering
+        * vcpu. Call it here with phys address pointing 16M below 4G.
+        */
+       if (!vcpu->kvm->arch.tss_addr) {
+               printk_once(KERN_WARNING "kvm: KVM_SET_TSS_ADDR need to be "
+                            "called before entering vcpu\n");
+               srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
+               vmx_set_tss_addr(vcpu->kvm, 0xfeffd000);
+               vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
+       }
+
        vmx->rmode.tr.selector = vmcs_read16(GUEST_TR_SELECTOR);
        vmx->rmode.tr.base = vmcs_readl(GUEST_TR_BASE);
        vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm));
@@ -2397,11 +2410,12 @@ static bool guest_state_valid(struct kvm_vcpu *vcpu)
 
 static int init_rmode_tss(struct kvm *kvm)
 {
-       gfn_t fn = rmode_tss_base(kvm) >> PAGE_SHIFT;
+       gfn_t fn;
        u16 data = 0;
-       int ret = 0;
-       int r;
+       int r, idx, ret = 0;
 
+       idx = srcu_read_lock(&kvm->srcu);
+       fn = rmode_tss_base(kvm) >> PAGE_SHIFT;
        r = kvm_clear_guest_page(kvm, fn, 0, PAGE_SIZE);
        if (r < 0)
                goto out;
@@ -2425,12 +2439,13 @@ static int init_rmode_tss(struct kvm *kvm)
 
        ret = 1;
 out:
+       srcu_read_unlock(&kvm->srcu, idx);
        return ret;
 }
 
 static int init_rmode_identity_map(struct kvm *kvm)
 {
-       int i, r, ret;
+       int i, idx, r, ret;
        pfn_t identity_map_pfn;
        u32 tmp;
 
@@ -2445,6 +2460,7 @@ static int init_rmode_identity_map(struct kvm *kvm)
                return 1;
        ret = 0;
        identity_map_pfn = kvm->arch.ept_identity_map_addr >> PAGE_SHIFT;
+       idx = srcu_read_lock(&kvm->srcu);
        r = kvm_clear_guest_page(kvm, identity_map_pfn, 0, PAGE_SIZE);
        if (r < 0)
                goto out;
@@ -2460,6 +2476,7 @@ static int init_rmode_identity_map(struct kvm *kvm)
        kvm->arch.ept_identity_pagetable_done = true;
        ret = 1;
 out:
+       srcu_read_unlock(&kvm->srcu, idx);
        return ret;
 }