vmm: Allow dynamic growth of __gths
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 11 Sep 2017 20:23:56 +0000 (16:23 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 14 Sep 2017 20:38:44 +0000 (16:38 -0400)
Right now the main vmm code doesn't use this.  There's really no need for
actual virtual machines.  Vthreads will use this later.

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

index b153671..ae8e888 100644 (file)
@@ -126,7 +126,16 @@ 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];
+       struct guest_thread **array;
+       struct guest_thread *gth;
+
+       /* Syncing with any dynamic growth of __gths */
+       do {
+               array = ACCESS_ONCE(vm->__gths);
+               gth = array[gpc_id];
+               rmb();  /* read ret before rereading array pointer */
+       } while (array != ACCESS_ONCE(vm->__gths));
+       return gth;
 }
 
 static struct vm_trapframe *gpcid_to_vmtf(struct virtual_machine *vm,
index bdfeab7..27ee1cf 100644 (file)
@@ -597,6 +597,7 @@ int vmm_init(struct virtual_machine *vm, struct vmm_gpcore_init *gpcis,
                        return -1;
                }
        }
+       wmb(); /* All gths posted before advertising. */
        vm->__gths = gths;
        uthread_mcp_init();
        register_ev_handler(EV_FREE_APPLE_PIE, ev_handle_diag, NULL);