opnsense-src/sys/dev/vmm/vmm_dev.h
Mark Johnston a97f683fe3 vmm: Add a device file interface for creating and destroying VMs
This supersedes the sysctl interface, which has the limitations of being
root-only and not supporting automatic resource destruction, i.e., we
cannot easily destroy VMs automatically when bhyve terminates.

For now, two ioctls are implemented VMMCTL_VM_CREATE and
VMMCTL_VM_DESTROY.  Eventually I would like to support tying a VM's
lifetime to that of the descriptor, so that it is automatically
destroyed when the descriptor is closed.  However, this will require
some work in bhyve: when the guest wants to reboot, bhyve exits with a
status that indicates that it is to be restarted.  This is incompatible
with the idea of tying a VM's lifetime to that of a descriptor, since we
want to avoid creating and destroying a VM across each reboot (as this
involves freeing all of the guest memory, among other things).  One
possible design would be to decompose bhyve into two processes, a parent
which handles reboots, and a child which runs in capability mode and
handles guest execution.

In any case, this gets us closer to addressing the shortcomings
mentioned above.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D47028
2024-11-05 01:40:41 +00:00

70 lines
1.9 KiB
C

/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 NetApp, Inc.
* Copyright (C) 2015 Mihai Carabas <mihai.carabas@gmail.com>
* All rights reserved.
*/
#ifndef _DEV_VMM_DEV_H_
#define _DEV_VMM_DEV_H_
#include <sys/types.h>
#include <sys/ioccom.h>
#include <machine/vmm_dev.h>
#ifdef _KERNEL
struct thread;
struct vm;
struct vcpu;
int vmmdev_init(void);
int vmmdev_cleanup(void);
int vmmdev_machdep_ioctl(struct vm *vm, struct vcpu *vcpu, u_long cmd,
caddr_t data, int fflag, struct thread *td);
/*
* Entry in an ioctl handler table. A number of generic ioctls are defined,
* plus a table of machine-dependent ioctls. The flags indicate the
* required preconditions for a given ioctl.
*
* Some ioctls encode a vcpuid as the first member of their ioctl structure.
* These ioctls must specify one of the following flags:
* - ALLOC_VCPU: create the vCPU if it does not already exist
* - LOCK_ONE_VCPU: create the vCPU if it does not already exist
* and lock the vCPU for the duration of the ioctl
* - MAYBE_ALLOC_VCPU: if the vcpuid is -1, do nothing, otherwise
* create the vCPU if it does not already exist
*/
struct vmmdev_ioctl {
unsigned long cmd;
#define VMMDEV_IOCTL_SLOCK_MEMSEGS 0x01
#define VMMDEV_IOCTL_XLOCK_MEMSEGS 0x02
#define VMMDEV_IOCTL_LOCK_ONE_VCPU 0x04
#define VMMDEV_IOCTL_LOCK_ALL_VCPUS 0x08
#define VMMDEV_IOCTL_ALLOC_VCPU 0x10
#define VMMDEV_IOCTL_MAYBE_ALLOC_VCPU 0x20
int flags;
};
#define VMMDEV_IOCTL(_cmd, _flags) { .cmd = (_cmd), .flags = (_flags) }
extern const struct vmmdev_ioctl vmmdev_machdep_ioctls[];
extern const size_t vmmdev_machdep_ioctl_count;
#endif /* _KERNEL */
struct vmmctl_vm_create {
char name[VM_MAX_NAMELEN + 1];
int reserved[16];
};
struct vmmctl_vm_destroy {
char name[VM_MAX_NAMELEN + 1];
int reserved[16];
};
#define VMMCTL_VM_CREATE _IOWR('V', 0, struct vmmctl_vm_create)
#define VMMCTL_VM_DESTROY _IOWR('V', 1, struct vmmctl_vm_destroy)
#endif /* _DEV_VMM_DEV_H_ */