summaryrefslogtreecommitdiff
path: root/usr.sbin/vmd/config.c
diff options
context:
space:
mode:
authorDave Voutila <dv@cvs.openbsd.org>2022-05-08 14:44:55 +0000
committerDave Voutila <dv@cvs.openbsd.org>2022-05-08 14:44:55 +0000
commit5caad49bb892f7c03b4c51b1f00e950cec05fa4d (patch)
treee10577fe808b5484fb7dbbb3a45aba1c96ae4e72 /usr.sbin/vmd/config.c
parent659e120b2f77c26bd9001d246d60204a983b4773 (diff)
vmd: fix rebooting a received vm
Rebooting a received vm resulted in vmd(8) exiting as a result of flawed state tracking in the parent process. When stopping a vm, clear the VM_RECEIVE_STATE flag. When starting a vm, make sure the parent process collapses any existing memory ranges after the vm is sent to the vmm process (responsible for launching the vm). ok mlarkin@
Diffstat (limited to 'usr.sbin/vmd/config.c')
-rw-r--r--usr.sbin/vmd/config.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/usr.sbin/vmd/config.c b/usr.sbin/vmd/config.c
index 2750be4f580..374d7de6629 100644
--- a/usr.sbin/vmd/config.c
+++ b/usr.sbin/vmd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.64 2021/11/10 20:49:04 sthen Exp $ */
+/* $OpenBSD: config.c,v 1.65 2022/05/08 14:44:54 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -231,6 +231,7 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid)
unsigned int unit;
struct timeval tv, rate, since_last;
struct vmop_addr_req var;
+ size_t bytes = 0;
if (vm->vm_state & VM_STATE_RUNNING) {
log_warnx("%s: vm is already running", __func__);
@@ -518,6 +519,14 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid)
free(tapfds);
+ /* Collapse any memranges after the vm was sent to PROC_VMM */
+ if (vcp->vcp_nmemranges > 0) {
+ for (i = 0; i < vcp->vcp_nmemranges; i++)
+ bytes += vcp->vcp_memranges[i].vmr_size;
+ memset(&vcp->vcp_memranges, 0, sizeof(vcp->vcp_memranges));
+ vcp->vcp_nmemranges = 0;
+ vcp->vcp_memranges[0].vmr_size = bytes;
+ }
vm->vm_state |= VM_STATE_RUNNING;
return (0);