summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2015-11-26 08:26:48 +0000
committerreyk <reyk@openbsd.org>2015-11-26 08:26:48 +0000
commita940fe282c273c7a2bd995c96a08754251696237 (patch)
tree30c3743c24ee2ef1e600f445a3e4ffdb526caadc
parentWhen prompting for a GPT partition type, use the partition's current type as (diff)
downloadwireguard-openbsd-a940fe282c273c7a2bd995c96a08754251696237.tar.xz
wireguard-openbsd-a940fe282c273c7a2bd995c96a08754251696237.zip
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@
-rw-r--r--sys/arch/amd64/amd64/vmm.c35
-rw-r--r--sys/arch/amd64/include/vmmvar.h16
-rw-r--r--usr.sbin/vmd/vmd.c52
-rw-r--r--usr.sbin/vmmctl/main.c14
-rw-r--r--usr.sbin/vmmctl/parser.c4
-rw-r--r--usr.sbin/vmmctl/parser.h8
-rw-r--r--usr.sbin/vmmctl/vmm.conf.534
-rw-r--r--usr.sbin/vmmctl/vmmctl.838
-rw-r--r--usr.sbin/vmmctl/vmmctl.c114
9 files changed, 36 insertions, 279 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
diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c
index 53feaf1ceab..35ad6d749ff 100644
--- a/usr.sbin/vmd/vmd.c
+++ b/usr.sbin/vmd/vmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmd.c,v 1.7 2015/11/25 22:44:21 tedu Exp $ */
+/* $OpenBSD: vmd.c,v 1.8 2015/11/26 08:26:48 reyk Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@@ -118,8 +118,6 @@ __dead void usage(void);
void sighdlr(int);
int main(int, char **);
int control_run(void);
-int disable_vmm(void);
-int enable_vmm(void);
int start_vm(struct imsg *);
int terminate_vm(struct imsg *);
int get_info_vm(struct imsgbuf *);
@@ -358,18 +356,6 @@ control_run(void)
/* Process incoming message (from vmmctl(8)) */
switch (imsg.hdr.type) {
- case IMSG_VMDOP_DISABLE_VMM_REQUEST:
- res = disable_vmm();
- imsg_compose(ibuf,
- IMSG_VMDOP_DISABLE_VMM_RESPONSE, 0, 0, -1,
- &res, sizeof(res));
- break;
- case IMSG_VMDOP_ENABLE_VMM_REQUEST:
- res = enable_vmm();
- imsg_compose(ibuf,
- IMSG_VMDOP_ENABLE_VMM_RESPONSE, 0, 0, -1,
- &res, sizeof(res));
- break;
case IMSG_VMDOP_START_VM_REQUEST:
res = start_vm(&imsg);
imsg_compose(ibuf,
@@ -411,42 +397,6 @@ control_run(void)
}
/*
- * disable_vmm
- *
- * Disables VMM mode on all CPUs
- *
- * Return values:
- * 0: success
- * !0 : ioctl to vmm(4) failed
- */
-int
-disable_vmm(void)
-{
- if (ioctl(vmm_fd, VMM_IOC_STOP, NULL) < 0)
- return (errno);
-
- return (0);
-}
-
-/*
- * enable_vmm
- *
- * Enables VMM mode on all CPUs
- *
- * Return values:
- * 0: success
- * !0 : ioctl to vmm(4) failed
- */
-int
-enable_vmm(void)
-{
- if (ioctl(vmm_fd, VMM_IOC_START, NULL) < 0)
- return (errno);
-
- return (0);
-}
-
-/*
* terminate_vm
*
* Requests vmm(4) to terminate the VM whose ID is provided in the
diff --git a/usr.sbin/vmmctl/main.c b/usr.sbin/vmmctl/main.c
index 1e0a622d114..928b705d8c6 100644
--- a/usr.sbin/vmmctl/main.c
+++ b/usr.sbin/vmmctl/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.2 2015/11/26 07:44:28 reyk Exp $ */
+/* $OpenBSD: main.c,v 1.3 2015/11/26 08:26:48 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -147,12 +147,6 @@ vmmaction(struct parse_result *res)
imsg_init(ibuf, ctl_sock);
switch (res->action) {
- case CMD_ENABLE:
- enable_vmm();
- break;
- case CMD_DISABLE:
- disable_vmm();
- break;
case CMD_START:
/* XXX validation should be done in start_vm() */
if (res->size < 1)
@@ -201,12 +195,6 @@ vmmaction(struct parse_result *res)
ret = 0;
switch (res->action) {
- case CMD_DISABLE:
- done = disable_vmm_complete(&imsg, &ret);
- break;
- case CMD_ENABLE:
- done = enable_vmm_complete(&imsg, &ret);
- break;
case CMD_START:
done = start_vm_complete(&imsg, &ret);
break;
diff --git a/usr.sbin/vmmctl/parser.c b/usr.sbin/vmmctl/parser.c
index b095067b3b1..b99b1c6ba24 100644
--- a/usr.sbin/vmmctl/parser.c
+++ b/usr.sbin/vmmctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.1 2015/11/22 20:55:18 reyk Exp $ */
+/* $OpenBSD: parser.c,v 1.2 2015/11/26 08:26:48 reyk Exp $ */
/*
* Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org>
@@ -67,9 +67,7 @@ static const struct token t_id[];
static const struct token t_opt_path[];
static const struct token t_main[] = {
- { KEYWORD, "enable", CMD_ENABLE, NULL },
{ KEYWORD, "create", CMD_CREATE, t_create },
- { KEYWORD, "disable", CMD_DISABLE, NULL },
{ KEYWORD, "load", CMD_LOAD, t_opt_path },
{ KEYWORD, "show", NONE, t_show },
{ KEYWORD, "start", CMD_START, t_start_name },
diff --git a/usr.sbin/vmmctl/parser.h b/usr.sbin/vmmctl/parser.h
index 66b86b7bc53..d45957828ff 100644
--- a/usr.sbin/vmmctl/parser.h
+++ b/usr.sbin/vmmctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.1 2015/11/22 20:55:18 reyk Exp $ */
+/* $OpenBSD: parser.h,v 1.2 2015/11/26 08:26:48 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -27,8 +27,6 @@
enum actions {
NONE,
CMD_CREATE,
- CMD_ENABLE,
- CMD_DISABLE,
CMD_START,
CMD_TERMINATE,
CMD_INFO,
@@ -68,10 +66,6 @@ int cmdline_symset(char *);
int create_imagefile(char *, long);
int start_vm(const char *, int, int, int, char **, char *);
int start_vm_complete(struct imsg *, int *);
-void enable_vmm(void);
-int enable_vmm_complete(struct imsg *, int *);
-void disable_vmm(void);
-int disable_vmm_complete(struct imsg *, int *);
void terminate_vm(uint32_t);
int terminate_vm_complete(struct imsg *, int *);
void get_info_vm(uint32_t);
diff --git a/usr.sbin/vmmctl/vmm.conf.5 b/usr.sbin/vmmctl/vmm.conf.5
index 3141794df20..fd5b51c73c0 100644
--- a/usr.sbin/vmmctl/vmm.conf.5
+++ b/usr.sbin/vmmctl/vmm.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: vmm.conf.5,v 1.5 2015/11/23 21:36:20 jmc Exp $
+.\" $OpenBSD: vmm.conf.5,v 1.6 2015/11/26 08:26:48 reyk Exp $
.\"
.\" Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
.\" Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 23 2015 $
+.Dd $Mdocdate: November 26 2015 $
.Dt VMM.CONF 5
.Os
.Sh NAME
@@ -36,10 +36,6 @@ is divided into three main sections:
.It Sy Macros
User-defined variables may be defined and used later, simplifying the
configuration file.
-.It Sy VMM Configuration
-Global settings for the
-.Xr vmm 4
-subsystem.
.It Sy VM Configuration
Configuration for each individual virtual machine.
.El
@@ -81,27 +77,6 @@ vm "vm1.example.com" {
kernel $ramdisk
}
.Ed
-.Sh VMM CONFIGURATION
-The options are as follows:
-.Bl -tag -width Ds
-.It Cm vmm disable
-Disable the VMM subsystem.
-Virtual machines running on the host should be terminated first.
-.It Cm vmm enable
-Enable the VMM subsystem.
-The VMM subsystem must be enabled before VMs can be managed on the host.
-.El
-.Pp
-Generally, the
-.Nm
-utility is run with
-.Cm enable
-option during system startup to enable the VMM subsystem on boot.
-This can be automated via the
-.Xr rc 8
-and
-.Xr rc.conf 8
-facilities used during system startup.
.Sh VM CONFIGURATION
Each
.Ic vm
@@ -135,11 +110,6 @@ can be used.
Number of network interfaces to add to the VM.
.El
.Sh EXAMPLES
-Enable the VMM subsystem:
-.Bd -literal -offset indent
-vmm enable
-.Ed
-.Pp
Create a new VM with 512MB memory, 1 network interface, one disk image
('disk.img') and boot from kernel '/bsd':
.Bd -literal -offset indent
diff --git a/usr.sbin/vmmctl/vmmctl.8 b/usr.sbin/vmmctl/vmmctl.8
index 3d27685c4ef..7934f0076ec 100644
--- a/usr.sbin/vmmctl/vmmctl.8
+++ b/usr.sbin/vmmctl/vmmctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: vmmctl.8,v 1.5 2015/11/23 13:40:28 reyk Exp $
+.\" $OpenBSD: vmmctl.8,v 1.6 2015/11/26 08:26:48 reyk Exp $
.\"
.\" Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 23 2015 $
+.Dd $Mdocdate: November 26 2015 $
.Dt VMMCTL 8
.Os
.Sh NAME
@@ -33,34 +33,6 @@ A VMM manages virtual machines (VMs) on a
.Ar host .
The VMM subsystem is responsible for creating, destroying, and executing
VMs.
-.Sh VMM OPERATIONS
-The options are as follows:
-.Bl -tag -width Ds
-.It Cm enable
-Enable the VMM subsystem.
-The VMM subsystem must be enabled before VMs can be managed on the host.
-.It Cm disable
-Disable the VMM subsystem.
-Virtual machines running on the host should be terminated first.
-.It Cm load Op Ar path
-Load the
-.Xr vmm.conf 5
-configuration file from
-.Pa /etc/vmm.conf
-or the specified
-.Ar path .
-.El
-.Pp
-Generally, the
-.Nm
-utility is run with
-.Cm enable
-option during system startup to enable the VMM subsystem on boot.
-This can be automated via the
-.Xr rc 8
-and
-.Xr rc.conf 8
-facilities used during system startup.
.Sh VM OPERATIONS
The options are as follows:
.Bl -tag -width Ds
@@ -108,12 +80,6 @@ The VMM subsystem could not be enabled or disabled as requested.
A requested VM-based operation could not be completed.
.El
.Sh EXAMPLES
-Enable the VMM subsystem:
-.Dl $ vmmctl enable
-.Pp
-Disable the VMM subsystem:
-.Dl $ vmmctl disable
-.Pp
Create a new disk image ('disk.img') of 4 gigabyte size:
.Dl $ vmmctl create disk.img size 4G
.Pp
diff --git a/usr.sbin/vmmctl/vmmctl.c b/usr.sbin/vmmctl/vmmctl.c
index 0d32454ab86..a26e01be729 100644
--- a/usr.sbin/vmmctl/vmmctl.c
+++ b/usr.sbin/vmmctl/vmmctl.c
@@ -44,120 +44,6 @@ extern char *__progname;
uint32_t info_id;
/*
- * enable_vmm
- *
- * Request vmd to enable VMM mode on the machine. This will result in the
- * appropriate instruction sequence (eg, vmxon) being executed in order
- * for the CPU to later service VMs.
- */
-void
-enable_vmm(void)
-{
- imsg_compose(ibuf, IMSG_VMDOP_ENABLE_VMM_REQUEST, 0, 0, -1, NULL, 0);
-}
-
-/*
- * enable_vmm_complete
- *
- * Callback function invoked when we are expecting an
- * IMSG_VMDOP_ENABLE_VMM_RESPONSE message indicating the completion of
- * an enable vmm operation.
- *
- * Parameters:
- * imsg : response imsg received from vmd
- * ret : return value
- *
- * Return:
- * Always 1 to indicate we have processed the return message (even if it
- * was an incorrect/failure message).
- *
- * The function also sets 'ret' to the error code as follows:
- * 0 : Message successfully processed
- * EINVAL: Invalid or unexpected response from vmd
- * EIO : enable_vmm command failed
- */
-int
-enable_vmm_complete(struct imsg *imsg, int *ret)
-{
- int res;
-
- if (imsg->hdr.type == IMSG_VMDOP_ENABLE_VMM_RESPONSE) {
- res = *(int *)imsg->data;
- if (res) {
- fprintf(stderr, "%s: enable VMM command failed (%d) - "
- "%s\n", __progname, res, strerror(res));
- *ret = EIO;
- } else {
- fprintf(stdout, "%s: enable VMM command successful\n",
- __progname);
- *ret = 0;
- }
- } else {
- fprintf(stderr, "%s: unexpected response received from vmd\n",
- __progname);
- *ret = EINVAL;
- }
-
- return (1);
-}
-
-/*
- * disable_vmm
- *
- * Request vmd to disable VMM mode on the machine.
- */
-void
-disable_vmm(void)
-{
- imsg_compose(ibuf, IMSG_VMDOP_DISABLE_VMM_REQUEST, 0, 0, -1, NULL, 0);
-}
-
-/*
- * disable_vmm_complete
- *
- * Callback function invoked when we are expecting an
- * IMSG_VMDOP_DISABLE_VMM_RESPONSE message indicating the completion of
- * a disable vmm operation.
- *
- * Parameters:
- * imsg : response imsg received from vmd
- * ret : return value
- *
- * Return:
- * Always 1 to indicate we have processed the return message (even if it
- * was an incorrect/failure message)
- *
- * The function also sets 'ret' to the error code as follows:
- * 0 : Message successfully processed
- * EINVAL: Invalid or unexpected response from vmd
- * EIO : disable_vmm command failed
- */
-int
-disable_vmm_complete(struct imsg *imsg, int *ret)
-{
- int res;
-
- if (imsg->hdr.type == IMSG_VMDOP_DISABLE_VMM_RESPONSE) {
- res = *(int *)imsg->data;
- if (res) {
- fprintf(stderr, "%s: disable VMM command failed (%d) - "
- "%s\n", __progname, res, strerror(res));
- *ret = EIO;
- } else {
- fprintf(stdout, "%s: disable VMM command successful\n",
- __progname);
- *ret = 0;
- }
- } else {
- fprintf(stderr, "%s: unexpected response received from vmd\n",
- __progname);
- *ret = EINVAL;
- }
-
- return (1);
-}
-
-/*
* start_vm
*
* Request vmd to start the VM defined by the supplied parameters