vmm: Use a helper for all gth lookups
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 11 Sep 2017 19:59:39 +0000 (15:59 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 14 Sep 2017 20:38:42 +0000 (16:38 -0400)
With one central lookup helper, I can grow the list dynamically.  I used
the compiler to find these cases, hence the name change of gths -> __gths.

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

index ff9383c..6ee76c6 100644 (file)
@@ -234,6 +234,7 @@ int main(int argc, char **argv)
        uint64_t entry = 0;
        int ret;
        struct vm_trapframe *vm_tf;
+       struct guest_thread *gth;
        int c;
        int test = 0;
        int option_index;
@@ -345,8 +346,9 @@ int main(int argc, char **argv)
                exit(1);
        }
 
-       vm.gths[0]->vmcall = linuxemu;
-       vm_tf = gth_to_vmtf(vm.gths[0]);
+       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
         * ourselves. */
index dd32e26..ef6ccba 100644 (file)
@@ -694,14 +694,14 @@ int main(int argc, char **argv)
 
        setup_paging(vm);
 
-       vm_tf = gth_to_vmtf(vm->gths[0]);
+       vm_tf = gpcid_to_vmtf(vm, 0);
        vm_tf->tf_cr3 = (uint64_t) vm->root;
        vm_tf->tf_rip = entry;
        vm_tf->tf_rsp = 0xe0000;
        vm_tf->tf_rsi = (uint64_t) bp;
        vm->up_gpcs = 1;
        fprintf(stderr, "Start guest: cr3 %p rip %p\n", vm_tf->tf_cr3, entry);
-       start_guest_thread(vm->gths[0]);
+       start_guest_thread(gpcid_to_gth(vm, 0));
 
        uthread_sleep_forever();
        return 0;
index 4c558d2..b153671 100644 (file)
@@ -46,7 +46,7 @@ enum {
 
 /* Structure to encapsulate all of the bookkeeping for a VM. */
 struct virtual_machine {
-       struct guest_thread                     **gths;
+       struct guest_thread                     **__gths;
        unsigned int                            nr_gpcs;
        /* up_gpcs should not need synchronization. only the BSP should be making
         * startup vmcalls. For security's sake we might still want to lock in the
@@ -126,7 +126,13 @@ static struct vmm_gpcore_init *gth_to_gpci(struct guest_thread *gth)
 static struct guest_thread *gpcid_to_gth(struct virtual_machine *vm,
                                          unsigned int gpc_id)
 {
-       return vm->gths[gpc_id];
+       return vm->__gths[gpc_id];
+}
+
+static struct vm_trapframe *gpcid_to_vmtf(struct virtual_machine *vm,
+                                          unsigned int gpc_id)
+{
+       return gth_to_vmtf(gpcid_to_gth(vm, gpc_id));
 }
 
 static struct virtual_machine *get_my_vm(void)
index e9d8ab8..bdfeab7 100644 (file)
@@ -543,7 +543,7 @@ static void ev_handle_diag(struct event_msg *ev_msg, unsigned int ev_type,
 
        fprintf(stderr, "\nSCHED stats:\n---------------\n");
        for (int i = 0; i < vm->nr_gpcs; i++) {
-               gth = vm->gths[i];
+               gth = gpcid_to_gth(vm, i);
                cth = gth->buddy;
                fprintf(stderr, "\tGPC %2d: %lu resched, %lu gth runs, %lu ctl runs, %lu user-handled vmexits\n",
                                i,
@@ -597,7 +597,7 @@ int vmm_init(struct virtual_machine *vm, struct vmm_gpcore_init *gpcis,
                        return -1;
                }
        }
-       vm->gths = gths;
+       vm->__gths = gths;
        uthread_mcp_init();
        register_ev_handler(EV_FREE_APPLE_PIE, ev_handle_diag, NULL);
        if (sched_is_greedy()) {
index cef0684..ab649ce 100644 (file)
@@ -203,7 +203,7 @@ static bool handle_vmcall_smpboot(struct guest_thread *gth)
        }
 
        /* Start up secondary core. */
-       vm_tf_ap = gth_to_vmtf(vm->gths[cur_pcores]);
+       vm_tf_ap = gpcid_to_vmtf(vm, cur_pcores);
        /* We use the BSP's CR3 for now. This should be fine because they
         * change it later anyway. */
        vm_tf_ap->tf_cr3 = vm_tf->tf_cr3;
@@ -216,7 +216,7 @@ static bool handle_vmcall_smpboot(struct guest_thread *gth)
 
        vm->up_gpcs++;
 
-       start_guest_thread(vm->gths[cur_pcores]);
+       start_guest_thread(gpcid_to_gth(vm, cur_pcores));
 
        return TRUE;
 }
index 7db2856..31cf141 100644 (file)
@@ -23,7 +23,7 @@ int vmm_interrupt_guest(struct virtual_machine *vm, unsigned int gpcoreid,
                        vm->nr_gpcs);
                return -1;
        }
-       gth = vm->gths[gpcoreid];
+       gth = gpcid_to_gth(vm, gpcoreid);
        gpci = gth_to_gpci(gth);
        /* The OUTSTANDING_NOTIF bit (256) is one greater than the last valid
         * descriptor */
index 98982b8..69b9e3a 100644 (file)
@@ -30,6 +30,7 @@ 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;
@@ -65,8 +66,9 @@ static int vmsetup(struct virtual_machine *vm, int flags)
        free(gpcis);
 
        for (i = 0; i < vm->nr_gpcs; i++) {
-               vm->gths[i]->halt_exit = vm->halt_exit;
-               vm_tf = gth_to_vmtf(vm->gths[i]);
+               gth = gpcid_to_gth(vm, i);
+               gth->halt_exit = vm->halt_exit;
+               vm_tf = gth_to_vmtf(gth);
                vm_tf->tf_cr3 = (uint64_t) vm->root;
        }
        vm->vminit = 1;
@@ -99,7 +101,7 @@ int vthread_create(struct virtual_machine *vm, int guest, void *rip, void *arg)
        if (guest > vm->nr_gpcs)
                return -ENOENT;
 
-       vm_tf = gth_to_vmtf(vm->gths[guest]);
+       vm_tf = gpcid_to_vmtf(vm, guest);
 
        /* For now we make the default VM stack pretty small.
         * We can grow it as needed. */
@@ -115,6 +117,6 @@ int vthread_create(struct virtual_machine *vm, int guest, void *rip, void *arg)
        }
        vm_tf->tf_rip = (uint64_t)rip;
        vm_tf->tf_rdi = (uint64_t)arg;
-       start_guest_thread(vm->gths[guest]);
+       start_guest_thread(gpcid_to_gth(vm, guest));
        return 0;
 }