vfb: use fb_sys_read() and fb_sys_write()
[powerpc.git] / drivers / kvm / kvm_main.c
index cdf0b17..c8b8cfa 100644 (file)
@@ -1186,6 +1186,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
        int r;
        int cs_db, cs_l;
 
+       vcpu->mmio_fault_cr2 = cr2;
        kvm_arch_ops->cache_regs(vcpu);
 
        kvm_arch_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
@@ -1236,8 +1237,10 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
        kvm_arch_ops->decache_regs(vcpu);
        kvm_arch_ops->set_rflags(vcpu, emulate_ctxt.eflags);
 
-       if (vcpu->mmio_is_write)
+       if (vcpu->mmio_is_write) {
+               vcpu->mmio_needed = 0;
                return EMULATE_DO_MMIO;
+       }
 
        return EMULATE_DONE;
 }
@@ -1691,8 +1694,6 @@ static int complete_pio(struct kvm_vcpu *vcpu)
                        vcpu->regs[VCPU_REGS_RSI] += delta;
        }
 
-       vcpu->run->io_completed = 0;
-
        kvm_arch_ops->decache_regs(vcpu);
 
        io->count -= io->cur_count;
@@ -1799,18 +1800,27 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
        /* re-sync apic's tpr */
        vcpu->cr8 = kvm_run->cr8;
 
-       if (kvm_run->io_completed) {
-               if (vcpu->pio.cur_count) {
-                       r = complete_pio(vcpu);
-                       if (r)
-                               goto out;
-               } else {
-                       memcpy(vcpu->mmio_data, kvm_run->mmio.data, 8);
-                       vcpu->mmio_read_completed = 1;
-               }
+       if (vcpu->pio.cur_count) {
+               r = complete_pio(vcpu);
+               if (r)
+                       goto out;
        }
 
-       vcpu->mmio_needed = 0;
+       if (vcpu->mmio_needed) {
+               memcpy(vcpu->mmio_data, kvm_run->mmio.data, 8);
+               vcpu->mmio_read_completed = 1;
+               vcpu->mmio_needed = 0;
+               r = emulate_instruction(vcpu, kvm_run,
+                                       vcpu->mmio_fault_cr2, 0);
+               if (r == EMULATE_DO_MMIO) {
+                       /*
+                        * Read-modify-write.  Back to userspace.
+                        */
+                       kvm_run->exit_reason = KVM_EXIT_MMIO;
+                       r = 0;
+                       goto out;
+               }
+       }
 
        if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL) {
                kvm_arch_ops->cache_regs(vcpu);