vmm: Use VMM_CTL to set VMM flags (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 8 Sep 2017 18:20:17 +0000 (14:20 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 14 Sep 2017 20:37:58 +0000 (16:37 -0400)
We had been setting the flags when we created the VM.  This lets us change
them on the fly - even if it's just a debugging flag.

I mostly wanted to separate out the flags from the initial setup, since
I'll turn the setup into "add guest pcores."

Reinstall your kernel headers.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/x86/trap.c
kern/arch/x86/vmm/vmm.c
kern/arch/x86/vmm/vmm.h
kern/include/ros/vmm.h
kern/src/syscall.c
tests/vmm/vmrunkernel.c
user/vmm/sched.c

index acd5ce2..f9d6999 100644 (file)
@@ -1075,7 +1075,7 @@ static void vmexit_dispatch(struct vm_trapframe *tf)
         * do it for external IRQs - the irq_dispatch code will handle it. */
        switch (tf->tf_exit_reason) {
        case EXIT_REASON_VMCALL:
-               if (current->vmm.flags & VMM_VMCALL_PRINTF &&
+               if (current->vmm.flags & VMM_CTL_FL_KERN_PRINTC &&
                    tf->tf_rax == VMCALL_PRINTC) {
                        printk("%c", tf->tf_rdi);
                        tf->tf_rip += 3;
index f40625d..1aeb16f 100644 (file)
@@ -68,16 +68,12 @@ void vmm_pcpu_init(void)
 /* Initializes a process to run virtual machine contexts, returning the number
  * initialized, throwing on error. */
 int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores,
-                    struct vmm_gpcore_init *u_gpcis, int flags)
+                    struct vmm_gpcore_init *u_gpcis)
 {
        ERRSTACK(1);
        struct vmm *vmm = &p->vmm;
        struct vmm_gpcore_init gpci;
 
-       if (flags & ~VMM_ALL_FLAGS)
-               error(EINVAL, "%s: flags is 0x%lx, VMM_ALL_FLAGS is 0x%lx\n", __func__,
-                     flags, VMM_ALL_FLAGS);
-       vmm->flags = flags;
        if (!x86_supports_vmx)
                error(ENODEV, "This CPU does not support VMX");
        qlock(&vmm->qlock);
index da62fe9..a704756 100644 (file)
@@ -50,7 +50,7 @@ void vmm_init(void);
 void vmm_pcpu_init(void);
 
 int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores,
-                    struct vmm_gpcore_init *gpcis, int flags);
+                    struct vmm_gpcore_init *gpcis);
 void __vmm_struct_cleanup(struct proc *p);
 int vmm_poke_guest(struct proc *p, int guest_pcoreid);
 
index ef70f49..d797520 100644 (file)
@@ -8,16 +8,18 @@
 
 #include <ros/arch/vmm.h>
 
-#define        VMM_VMCALL_PRINTF       0x1     /* Enable VMCALL output console hack */
-
 /* VMCALL FUNCTION NUMBERS */
 #define VMCALL_PRINTC          0x1
 #define VMCALL_SMPBOOT         0x2
 
-#define VMM_ALL_FLAGS  (VMM_VMCALL_PRINTF)
-
 #define VMM_CTL_GET_EXITS              1
 #define VMM_CTL_SET_EXITS              2
+#define VMM_CTL_GET_FLAGS              3
+#define VMM_CTL_SET_FLAGS              4
+
 #define VMM_CTL_EXIT_HALT              (1 << 0)
 #define VMM_CTL_EXIT_PAUSE             (1 << 1)
 #define VMM_CTL_ALL_EXITS              ((1 << 2) - 1)
+
+#define VMM_CTL_FL_KERN_PRINTC         (1 << 0)
+#define VMM_CTL_ALL_FLAGS                      (VMM_CTL_FL_KERN_PRINTC)
index f7e684c..8fef27f 100644 (file)
@@ -1493,7 +1493,7 @@ static int sys_pop_ctx(struct proc *p, struct user_context *ctx)
 /* Initializes a process to run virtual machine contexts, returning the number
  * initialized, optionally setting errno */
 static int sys_vmm_setup(struct proc *p, unsigned int nr_guest_pcores,
-                         struct vmm_gpcore_init *gpcis, int flags)
+                         struct vmm_gpcore_init *gpcis)
 {
        int ret;
        ERRSTACK(1);
@@ -1502,7 +1502,7 @@ static int sys_vmm_setup(struct proc *p, unsigned int nr_guest_pcores,
                poperror();
                return -1;
        }
-       ret = vmm_struct_init(p, nr_guest_pcores, gpcis, flags);
+       ret = vmm_struct_init(p, nr_guest_pcores, gpcis);
        poperror();
        return ret;
 }
@@ -1545,6 +1545,16 @@ static int sys_vmm_ctl(struct proc *p, int cmd, unsigned long arg1,
                        error(ENOTSUP, "AMD VMMs unsupported");
                ret = vmx_ctl_set_exits(&vmm->vmx, arg1);
                break;
+       case VMM_CTL_GET_FLAGS:
+               ret = vmm->flags;
+               break;
+       case VMM_CTL_SET_FLAGS:
+               if (arg1 & ~VMM_CTL_ALL_FLAGS)
+                       error(EINVAL, "Bad vmm_ctl flags.  Got 0x%lx, allowed 0x%lx\n",
+                             arg1, VMM_CTL_ALL_FLAGS);
+               vmm->flags = arg1;
+               ret = 0;
+               break;
        default:
                error(EINVAL, "Bad vmm_ctl cmd %d", cmd);
        }
index 91793f1..d379645 100644 (file)
@@ -380,7 +380,7 @@ int main(int argc, char **argv)
        char *cmdline_extra = "\0";
        char *cmdline;
        void *a = (void *)0xe0000;
-       int vmmflags = 0; // Disabled probably forever. VMM_VMCALL_PRINTF;
+       int vmmflags = 0;
        uint64_t entry = 0;
        int ret;
        struct vm_trapframe *vm_tf;
@@ -448,7 +448,7 @@ int main(int argc, char **argv)
                        debug++;
                        break;
                case 'v':
-                       vmmflags |= VMM_VMCALL_PRINTF;
+                       vmmflags |= VMM_CTL_FL_KERN_PRINTC;
                        break;
                case 'm':
                        memsize = strtoull(optarg, 0, 0);
index 26d5d17..d3a9dfe 100644 (file)
@@ -567,8 +567,12 @@ int vmm_init(struct virtual_machine *vm, int flags)
        if (current_vm)
                return -1;
        current_vm = vm;
-       if (syscall(SYS_vmm_setup, vm->nr_gpcs, vm->gpcis, flags) != vm->nr_gpcs)
+       if (syscall(SYS_vmm_setup, vm->nr_gpcs, vm->gpcis) != vm->nr_gpcs)
                return -1;
+       if (flags) {
+               if (syscall(SYS_vmm_ctl, VMM_CTL_SET_FLAGS, flags))
+                       return -1;
+       }
        gths = malloc(vm->nr_gpcs * sizeof(struct guest_thread *));
        if (!gths)
                return -1;