VMM: init and cleanup take the proc * And do some minor connections between the guest pcore and its proc. Might need to think a bit about the weak vs strong refs. I'm pretty sure the cur_proc ref will always be active whenever we have a guest_pcore (vmx_vcpu). We'll see.
diff --git a/kern/arch/x86/vmm/intel/vmx.c b/kern/arch/x86/vmm/intel/vmx.c index 6a1fb7c..7af1198 100644 --- a/kern/arch/x86/vmm/intel/vmx.c +++ b/kern/arch/x86/vmm/intel/vmx.c
@@ -1207,7 +1207,7 @@ * * Returns: A new VCPU structure */ -struct vmx_vcpu *vmx_create_vcpu(void) +struct vmx_vcpu *vmx_create_vcpu(struct proc *p) { struct vmx_vcpu *vcpu = kmalloc(sizeof(struct vmx_vcpu), KMALLOC_WAIT); if (!vcpu) { @@ -1216,6 +1216,7 @@ memset(vcpu, 0, sizeof(*vcpu)); + vcpu->proc = p; /* uncounted (weak) reference */ vcpu->vmcs = vmx_alloc_vmcs(); printd("%d: vcpu->vmcs is %p\n", core_id(), vcpu->vmcs); if (!vcpu->vmcs)
diff --git a/kern/arch/x86/vmm/intel/vmx.h b/kern/arch/x86/vmm/intel/vmx.h index 26d5800..2b233bd 100644 --- a/kern/arch/x86/vmm/intel/vmx.h +++ b/kern/arch/x86/vmm/intel/vmx.h
@@ -625,7 +625,7 @@ int shutdown; int ret_code; - struct dune_guest *guest; + struct proc *proc; struct msr_autoload { unsigned nr;
diff --git a/kern/arch/x86/vmm/vmm.c b/kern/arch/x86/vmm/vmm.c index 4af9853..d19593a 100644 --- a/kern/arch/x86/vmm/vmm.c +++ b/kern/arch/x86/vmm/vmm.c
@@ -71,8 +71,9 @@ /* Initializes a process to run virtual machine contexts, returning the number * initialized, optionally setting errno */ -int vmm_struct_init(struct vmm *vmm, unsigned int nr_guest_pcores) +int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores) { + struct vmm *vmm = &p->vmm; unsigned int i; qlock(&vmm->qlock); if (vmm->vmmcp) { @@ -86,7 +87,7 @@ vmm->amd = 0; vmm->guest_pcores = kzmalloc(sizeof(void*) * nr_guest_pcores, KMALLOC_WAIT); for (i = 0; i < nr_guest_pcores; i++) { - vmm->guest_pcores[i] = vmx_create_vcpu(); + vmm->guest_pcores[i] = vmx_create_vcpu(p); /* If we failed, we'll clean it up when the process dies */ if (!vmm->guest_pcores[i]) { set_errno(ENOMEM); @@ -101,8 +102,9 @@ /* Has no concurrency protection - only call this when you know you have the * only ref to vmm. For instance, from __proc_free, where there is only one ref * to the proc (and thus proc.vmm). */ -void __vmm_struct_cleanup(struct vmm *vmm) +void __vmm_struct_cleanup(struct proc *p) { + struct vmm *vmm = &p->vmm; if (!vmm->vmmcp) return; for (int i = 0; i < vmm->nr_guest_pcores; i++) {
diff --git a/kern/arch/x86/vmm/vmm.h b/kern/arch/x86/vmm/vmm.h index 5945df5..7e604bc 100644 --- a/kern/arch/x86/vmm/vmm.h +++ b/kern/arch/x86/vmm/vmm.h
@@ -40,14 +40,14 @@ void vmm_init(void); void vmm_pcpu_init(void); -int vmm_struct_init(struct vmm *vmm, unsigned int nr_guest_pcores); -void __vmm_struct_cleanup(struct vmm *vmm); +int vmm_struct_init(struct proc *p, unsigned int nr_guest_pcores); +void __vmm_struct_cleanup(struct proc *p); int vm_run(uint64_t,uint64_t, uint64_t); int intel_vmx_start(int id); int intel_vmx_setup(int nvmcs); -struct vmx_vcpu *vmx_create_vcpu(void); +struct vmx_vcpu *vmx_create_vcpu(struct proc *p); void vmx_destroy_vcpu(struct vmx_vcpu *vcpu); #endif /* _VMM_H_ */
diff --git a/kern/src/process.c b/kern/src/process.c index 3b05c08..cac3977 100644 --- a/kern/src/process.c +++ b/kern/src/process.c
@@ -458,7 +458,7 @@ assert(kref_refcnt(&p->p_kref) == 0); assert(TAILQ_EMPTY(&p->alarmset.list)); - __vmm_struct_cleanup(&p->vmm); + __vmm_struct_cleanup(p); p->progname[0] = 0; cclose(p->dot); cclose(p->slash);
diff --git a/kern/src/syscall.c b/kern/src/syscall.c index 8e91d58..7d2e0d5 100644 --- a/kern/src/syscall.c +++ b/kern/src/syscall.c
@@ -1151,7 +1151,7 @@ * initialized, optionally setting errno */ static int sys_setup_vmm(struct proc *p, unsigned int nr_guest_pcores) { - return vmm_struct_init(&p->vmm, nr_guest_pcores); + return vmm_struct_init(p, nr_guest_pcores); } /* Pokes the ksched for the given resource for target_pid. If the target pid
diff --git a/tests/vmmcp.c b/tests/vmmcp.c index d083baa..886c06a 100644 --- a/tests/vmmcp.c +++ b/tests/vmmcp.c
@@ -53,6 +53,7 @@ int main(int argc, char **argv) { + int nr_gpcs = 1; int fd = open("#c/sysctl", O_RDWR), ret; void * x; static char cmd[512]; @@ -60,6 +61,10 @@ perror("#c/sysctl"); exit(1); } + if (ros_syscall(SYS_setup_vmm, nr_gpcs, 0, 0, 0, 0, 0) != nr_gpcs) { + perror("Guest pcore setup failed"); + exit(1); + } mcp = 1; //argc - 1; if (mcp) {