diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-11-26 08:26:49 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-11-26 08:26:49 +0000 |
commit | ceadf6e7a6f2cb298c190a7f63ba73cce1fdcfde (patch) | |
tree | f0636f34a8778d377d7871249370d8b2d2887e77 /sys/arch/amd64 | |
parent | 819c28bad11945f374a53f146195e25957b1ed67 (diff) |
Automatically start vmm(4) when the first VM is created and after the
last VM is terminated. This allows to remove the explicit "vmm
enable" / "vmm disable" (VMM_IOC_START / VMM_IOC_STOP) ioctls. You'll
have to update kernel and userland for this change, as the kernel ABI
changes.
OK mpi@ mlarkin@
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r-- | sys/arch/amd64/amd64/vmm.c | 35 | ||||
-rw-r--r-- | sys/arch/amd64/include/vmmvar.h | 16 |
2 files changed, 28 insertions, 23 deletions
diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index c069c65cf32..fd563a6caf3 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.7 2015/11/24 09:07:09 mlarkin Exp $ */ +/* $OpenBSD: vmm.c,v 1.8 2015/11/26 08:26:48 reyk Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> * @@ -307,19 +307,14 @@ vmmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) return (ENOTTY); switch(cmd) { - case VMM_IOC_START: - ret = vmm_start(); - if (ret) - vmm_stop(); - break; - case VMM_IOC_STOP: - if (vmm_softc->vm_ct > 0) - ret = EAGAIN; - else - ret = vmm_stop(); - break; case VMM_IOC_CREATE: + if ((ret = vmm_start()) != 0) { + vmm_stop(); + break; + } ret = vm_create((struct vm_create_params *)data, p); + if (vmm_softc->vm_ct < 1) + vmm_stop(); break; case VMM_IOC_RUN: ret = vm_run((struct vm_run_params *)data); @@ -329,6 +324,8 @@ vmmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) break; case VMM_IOC_TERM: ret = vm_terminate((struct vm_terminate_params *)data); + if (vmm_softc->vm_ct < 1) + vmm_stop(); break; case VMM_IOC_WRITEPAGE: ret = vm_writepage((struct vm_writepage_params *)data); @@ -557,12 +554,17 @@ vmm_start(void) { struct cpu_info *self = curcpu(); int ret = 0; - #ifdef MULTIPROCESSOR struct cpu_info *ci; CPU_INFO_ITERATOR cii; int i; +#endif + + /* VMM is already running */ + if (self->ci_flags & CPUF_VMM) + return (0); +#ifdef MULTIPROCESSOR /* Broadcast start VMM IPI */ x86_broadcast_ipi(X86_IPI_START_VMM); @@ -602,12 +604,17 @@ vmm_stop(void) { struct cpu_info *self = curcpu(); int ret = 0; - #ifdef MULTIPROCESSOR struct cpu_info *ci; CPU_INFO_ITERATOR cii; int i; +#endif + + /* VMM is not running */ + if (!(self->ci_flags & CPUF_VMM)) + return (0); +#ifdef MULTIPROCESSOR /* Stop VMM on other CPUs */ x86_broadcast_ipi(X86_IPI_STOP_VMM); diff --git a/sys/arch/amd64/include/vmmvar.h b/sys/arch/amd64/include/vmmvar.h index cd43de30611..5a02dc6c354 100644 --- a/sys/arch/amd64/include/vmmvar.h +++ b/sys/arch/amd64/include/vmmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmmvar.h,v 1.2 2015/11/16 10:08:41 mpi Exp $ */ +/* $OpenBSD: vmmvar.h,v 1.3 2015/11/26 08:26:48 reyk Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> * @@ -204,14 +204,12 @@ struct vm_readpage_params { }; /* IOCTL definitions */ -#define VMM_IOC_START _IO('V', 1) /* Start virtualization */ -#define VMM_IOC_STOP _IO('V', 2) /* Stop virtualization */ -#define VMM_IOC_CREATE _IOWR('V', 3, struct vm_create_params) /* Create VM */ -#define VMM_IOC_RUN _IOWR('V', 4, struct vm_run_params) /* Run VCPU */ -#define VMM_IOC_INFO _IOWR('V', 5, struct vm_info_params) /* Get VM Info */ -#define VMM_IOC_TERM _IOW('V', 6, struct vm_terminate_params) /* Terminate VM */ -#define VMM_IOC_WRITEPAGE _IOW('V', 7, struct vm_writepage_params) /* Wr Pg */ -#define VMM_IOC_READPAGE _IOW('V', 8, struct vm_readpage_params) /* Rd Pg */ +#define VMM_IOC_CREATE _IOWR('V', 1, struct vm_create_params) /* Create VM */ +#define VMM_IOC_RUN _IOWR('V', 2, struct vm_run_params) /* Run VCPU */ +#define VMM_IOC_INFO _IOWR('V', 3, struct vm_info_params) /* Get VM Info */ +#define VMM_IOC_TERM _IOW('V', 4, struct vm_terminate_params) /* Terminate VM */ +#define VMM_IOC_WRITEPAGE _IOW('V', 5, struct vm_writepage_params) /* Wr Pg */ +#define VMM_IOC_READPAGE _IOW('V', 6, struct vm_readpage_params) /* Rd Pg */ #ifdef _KERNEL |