Add run support.
authorRonald G. Minnich <rminnich@google.com>
Mon, 13 Jan 2014 01:50:05 +0000 (17:50 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jan 2014 22:57:12 +0000 (14:57 -0800)
Signed-off-by: Ronald G. Minnich <rminnich@google.com>
kern/arch/x86/vm.h
kern/arch/x86/vmx.c
kern/drivers/dev/vm.c

index 53d166b..b573ab6 100644 (file)
@@ -578,5 +578,5 @@ int vmx_create_vcpu(struct litevm *litevm, int n);
 int vmx_init(void);
 int vm_set_memory_region(struct litevm *litevm,
                         struct litevm_memory_region *mem);
-
+int vm_run(struct litevm *litevm, struct litevm_run *litevm_run);
 #endif
index 8192e4d..5272b64 100644 (file)
@@ -408,9 +408,12 @@ static struct litevm_vcpu *__vcpu_load(struct litevm_vcpu *vcpu)
                currentcpu->vmcs = vcpu->vmcs;
                asm volatile ("vmptrld %1; setna %0"
                               : "=m"(error) : "m"(phys_addr) : "cc" );
-               if (error)
+               if (error){
                        printk("litevm: vmptrld %p/%llx fail\n",
                               vcpu->vmcs, phys_addr);
+                       error("litevm: vmptrld %p/%llx fail\n",
+                              vcpu->vmcs, phys_addr);
+               }
        }
 
        if (vcpu->cpu != cpu) {
@@ -442,7 +445,7 @@ static struct litevm_vcpu *vcpu_load(struct litevm *litevm, int vcpu_slot)
        qlock(&vcpu->mutex);
        if (!vcpu->vmcs) {
                qunlock(&vcpu->mutex);
-               return 0;
+               error("vcpu->vmcs is NULL");
        }
        return __vcpu_load(vcpu);
 }
@@ -2618,11 +2621,12 @@ int vm_run(struct litevm *litevm, struct litevm_run *litevm_run)
        int fs_gs_ldt_reload_needed;
 
        if (litevm_run->vcpu < 0 || litevm_run->vcpu >= LITEVM_MAX_VCPUS)
-               return -EINVAL;
+               error("vcpu is %d but must be in the range %d..%d\n",
+                     litevm_run->vcpu, LITEVM_MAX_VCPUS);
 
        vcpu = vcpu_load(litevm, litevm_run->vcpu);
        if (!vcpu)
-               return -ENOENT;
+               error("vcpu_load failed");
 
        if (litevm_run->emulated) {
                skip_emulated_instruction(vcpu);
@@ -2791,7 +2795,7 @@ again:
              : "cc", "memory" );
 
        ++litevm_stat.exits;
-
+       printk("vm_run exits");
        save_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
        load_msrs(vcpu->host_msrs, NR_BAD_MSRS);
 
@@ -2843,6 +2847,7 @@ again:
        }
 
        vcpu_put(vcpu);
+       printk("vm_run returns\n");
        return 0;
 }
 
index f7adb98..15eb463 100644 (file)
@@ -362,8 +362,18 @@ static long vmwrite(struct chan *c, void *ubuf, long n, int64_t unused)
                        kfree(cb);
                        nexterror();
                }
-               if (!strcmp(cb->f[0], "start")) {
-                       error("can't run a vm yet");
+               if (!strcmp(cb->f[0], "run")) {
+                       int ret;
+                       if (cb->nf != 4)
+                               error("usage: run vcpu emulated mmio_completed");
+                       litevm = vm->archvm;
+                       struct litevm_run vmr;
+                       vmr.vcpu = strtoul(cb->f[1], NULL, 0);
+                       vmr.emulated = strtoul(cb->f[2], NULL, 0);
+                       vmr.mmio_completed = strtoul(cb->f[3], NULL, 0);
+                       ret = vm_run(litevm, &vmr);
+                       printk("vm_run returns %d\n", ret);
+                       return ret;
                } else if (!strcmp(cb->f[0], "stop")) {
                        error("can't stop a vm yet");
                } else if (!strcmp(cb->f[0], "fillmem")) {