summaryrefslogtreecommitdiff
path: root/usr.sbin/vmd/virtio.c
diff options
context:
space:
mode:
authorDave Voutila <dv@cvs.openbsd.org>2023-05-13 23:15:29 +0000
committerDave Voutila <dv@cvs.openbsd.org>2023-05-13 23:15:29 +0000
commit0450f77e1971ab09e8861ab1cab51909d3e1adbb (patch)
tree54405ab1af285f1b5301105e31cc0e9c675cda5d /usr.sbin/vmd/virtio.c
parent7698cea1a4c2fa7eff4cc2405547ca04b294213b (diff)
vmm(4)/vmd(8): switch to anonymous shared mappings.
While splitting out emulated virtio network and block devices into separate processes, I originally used named mappings via shm_mkstemp(3). While this functionally achieved the desired result, it had two unintended consequences: 1) tearing down a vm process and its child processes required excessive locking as the guest memory was tied into the VFS layer. 2) it was observed by mlarkin@ that actions in other parts of the VFS layer could cause some of the guest memory to flush to storage, possibly filling /tmp. This commit adds a new vmm(4) ioctl dedicated to allowing a process request the kernel share a mapping of guest memory into its own vm space. This requires an open fd to /dev/vmm (requiring root) and both the "vmm" and "proc" pledge(2) promises. In addition, the caller must know enough about the original memory ranges to reconstruct them to make the vm's ranges. Tested with help from Mischa Peters. ok mlarkin@
Diffstat (limited to 'usr.sbin/vmd/virtio.c')
-rw-r--r--usr.sbin/vmd/virtio.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/usr.sbin/vmd/virtio.c b/usr.sbin/vmd/virtio.c
index 92e77b8f834..d29b9e7b883 100644
--- a/usr.sbin/vmd/virtio.c
+++ b/usr.sbin/vmd/virtio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: virtio.c,v 1.102 2023/04/27 22:47:27 dv Exp $ */
+/* $OpenBSD: virtio.c,v 1.103 2023/05/13 23:15:28 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@@ -1297,7 +1297,7 @@ virtio_start(struct vmd_vm *vm)
static int
virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev)
{
- char *nargv[8], num[32], t[2];
+ char *nargv[10], num[32], vmm_fd[32], t[2];
pid_t dev_pid;
int data_fds[VM_MAX_BASE_PER_DISK], sync_fds[2], async_fds[2], ret = 0;
size_t i, j, data_fds_sz, sz = 0;
@@ -1483,6 +1483,8 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev)
memset(&nargv, 0, sizeof(nargv));
memset(num, 0, sizeof(num));
snprintf(num, sizeof(num), "%d", sync_fds[1]);
+ memset(vmm_fd, 0, sizeof(vmm_fd));
+ snprintf(vmm_fd, sizeof(vmm_fd), "%d", env->vmd_fd);
t[0] = dev->dev_type;
t[1] = '\0';
@@ -1492,13 +1494,15 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev)
nargv[2] = num;
nargv[3] = "-t";
nargv[4] = t;
- nargv[5] = "-n";
+ nargv[5] = "-i";
+ nargv[6] = vmm_fd;
+ nargv[7] = "-n";
if (env->vmd_verbose) {
- nargv[6] = "-v";
- nargv[7] = NULL;
+ nargv[8] = "-v";
+ nargv[9] = NULL;
} else
- nargv[6] = NULL;
+ nargv[8] = NULL;
/* Control resumes in vmd.c:main(). */
execvp(nargv[0], nargv);