vmm: Move the vmcall overrides to the VM struct
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 11 Sep 2017 20:49:57 +0000 (16:49 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 14 Sep 2017 20:38:44 +0000 (16:38 -0400)
The proximate cause of this is that vthreads is trying to set this before
creating the thread.  That's relying on the internals of vthreads having
actually made all the threads in advance.

Given that there's probably not a need to have the vmcall per vthread, we
can just do it per VM.  This also puts the vmcall hook right next to the
halt_exit hook.

Further, we don't need to copy the halt_exit hook to the gth either.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tests/dune/dune.c
user/vmm/include/vmm/sched.h
user/vmm/include/vmm/vmm.h
user/vmm/vmexit.c
user/vmm/vthread.c

index 6ee76c6..abad37f 100644 (file)
@@ -38,7 +38,8 @@ bool linuxemu(struct guest_thread *gth, struct vm_trapframe *tf);
 extern char **environ;
 
 static struct virtual_machine vm = {.halt_exit = true,
-                                    .root_mtx = UTH_MUTEX_INIT};
+                                    .root_mtx = UTH_MUTEX_INIT,
+                                    .vmcall = linuxemu};
 
 static unsigned long long memsize = GiB;
 static uintptr_t memstart = MinMemory;
@@ -347,7 +348,6 @@ int main(int argc, char **argv)
        }
 
        gth = gpcid_to_gth(&vm, 0);
-       gth->vmcall = linuxemu;
        vm_tf = gth_to_vmtf(gth);
 
        /* we can't use the default stack since we set one up
index 1adad6b..6da75bb 100644 (file)
@@ -31,14 +31,11 @@ struct guest_thread {
        struct uthread                          uthread;
        struct ctlr_thread                      *buddy;
        unsigned int                            gpc_id;
-       bool                                            halt_exit;
        uth_mutex_t                                     *halt_mtx;
        uth_cond_var_t                          *halt_cv;
        unsigned long                           nr_vmexits;
        struct vmm_gpcore_init          gpci;
        void                                            *user_data;
-       // TODO: work out a real ops strategy.
-       bool (*vmcall)(struct guest_thread *gth, struct vm_trapframe *);
 };
 
 struct ctlr_thread {
index ae8e888..5edfde1 100644 (file)
@@ -80,6 +80,8 @@ struct virtual_machine {
 
        /* Default value for whether guest threads halt on an exit. */
        bool                                            halt_exit;
+       /* Override for vmcall (vthreads) */
+       bool (*vmcall)(struct guest_thread *gth, struct vm_trapframe *);
 };
 
 struct elf_aux {
index ab649ce..0648146 100644 (file)
@@ -224,10 +224,11 @@ static bool handle_vmcall_smpboot(struct guest_thread *gth)
 static bool handle_vmcall(struct guest_thread *gth)
 {
        struct vm_trapframe *vm_tf = gth_to_vmtf(gth);
+       struct virtual_machine *vm = gth_to_vm(gth);
        bool retval = FALSE;
 
-       if (gth->vmcall)
-               return gth->vmcall(gth, vm_tf);
+       if (vm->vmcall)
+               return vm->vmcall(gth, vm_tf);
 
        switch (vm_tf->tf_rax) {
                case VMCALL_PRINTC:
@@ -298,8 +299,9 @@ static bool handle_apic_access(struct guest_thread *gth)
 static bool handle_halt(struct guest_thread *gth)
 {
        struct vm_trapframe *vm_tf = gth_to_vmtf(gth);
+       struct virtual_machine *vm = gth_to_vm(gth);
 
-       if (gth->halt_exit)
+       if (vm->halt_exit)
                return FALSE;
        /* It's possible the guest disabled IRQs and halted, perhaps waiting on an
         * NMI or something.  If we need to support that, we can change this.  */
index 69b9e3a..fdeefdc 100644 (file)
@@ -30,7 +30,6 @@ static int vmsetup(struct virtual_machine *vm, int flags)
        int i, ret;
        uint8_t *p;
        struct vmm_gpcore_init *gpcis;
-       struct guest_thread *gth;
 
        if (vm->vminit)
                return -EBUSY;
@@ -66,9 +65,7 @@ static int vmsetup(struct virtual_machine *vm, int flags)
        free(gpcis);
 
        for (i = 0; i < vm->nr_gpcs; i++) {
-               gth = gpcid_to_gth(vm, i);
-               gth->halt_exit = vm->halt_exit;
-               vm_tf = gth_to_vmtf(gth);
+               vm_tf = gpcid_to_vmtf(vm, i);
                vm_tf->tf_cr3 = (uint64_t) vm->root;
        }
        vm->vminit = 1;