-/* $OpenBSD: vmmvar.h,v 1.87 2023/01/19 15:52:51 dv Exp $ */
+/* $OpenBSD: vmmvar.h,v 1.88 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
*
#define VMM_PCI_MMIO_BAR_BASE 0xF0000000ULL
#define VMM_PCI_MMIO_BAR_END 0xFFDFFFFFULL /* 2 MiB below 4 GiB */
-#define VMM_PCI_MMIO_BAR_SIZE 0x00010000
-#define VMM_PCI_IO_BAR_BASE 0x1000
-#define VMM_PCI_IO_BAR_END 0xFFFF
-#define VMM_PCI_IO_BAR_SIZE 0x1000
/* VMX: Basic Exit Reasons */
#define VMX_EXIT_NMI 0
-/* $OpenBSD: vmctl.c,v 1.83 2022/05/13 00:17:20 yasuoka Exp $ */
+/* $OpenBSD: vmctl.c,v 1.84 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
else if (flags != 0) {
if (memsize < 1)
memsize = VM_DEFAULT_MEMORY;
- if (ndisks > VMM_MAX_DISKS_PER_VM)
+ if (ndisks > VM_MAX_DISKS_PER_VM)
errx(1, "too many disks");
else if (ndisks == 0)
warnx("starting without disks");
errx(1, "no kernel or disk/cdrom specified");
if (nnics == -1)
nnics = 0;
- if (nnics > VMM_MAX_NICS_PER_VM)
+ if (nnics > VM_MAX_NICS_PER_VM)
errx(1, "too many network interfaces");
if (nnics == 0)
warnx("starting without network interfaces");
-/* $OpenBSD: config.c,v 1.66 2022/10/31 14:02:11 dv Exp $ */
+/* $OpenBSD: config.c,v 1.67 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
int
config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid)
{
- int diskfds[VMM_MAX_DISKS_PER_VM][VM_MAX_BASE_PER_DISK];
+ int diskfds[VM_MAX_DISKS_PER_VM][VM_MAX_BASE_PER_DISK];
struct vmd_if *vif;
struct vmop_create_params *vmc = &vm->vm_params;
struct vm_create_params *vcp = &vmc->vmc_params;
}
vm->vm_start_tv = tv;
- for (i = 0; i < VMM_MAX_DISKS_PER_VM; i++)
+ for (i = 0; i < VM_MAX_DISKS_PER_VM; i++)
for (j = 0; j < VM_MAX_BASE_PER_DISK; j++)
diskfds[i][j] = -1;
-/* $OpenBSD: parse.y,v 1.62 2022/09/13 10:28:19 martijn Exp $ */
+/* $OpenBSD: parse.y,v 1.63 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2007-2016 Reyk Floeter <reyk@openbsd.org>
} else
name = $2;
- for (i = 0; i < VMM_MAX_NICS_PER_VM; i++) {
+ for (i = 0; i < VM_MAX_NICS_PER_VM; i++) {
/* Set the interface to UP by default */
vmc.vmc_ifflags[i] |= IFF_UP;
}
char type[IF_NAMESIZE];
i = vcp_nnics;
- if (++vcp_nnics > VMM_MAX_NICS_PER_VM) {
+ if (++vcp_nnics > VM_MAX_NICS_PER_VM) {
yyerror("too many interfaces: %zu", vcp_nnics);
free($3);
YYERROR;
yyerror("interfaces specified more than once");
YYERROR;
}
- if ($2 < 0 || $2 > VMM_MAX_NICS_PER_VM) {
+ if ($2 < 0 || $2 > VM_MAX_NICS_PER_VM) {
yyerror("too many interfaces: %lld", $2);
YYERROR;
}
int fd;
ssize_t len;
- if (vcp->vcp_ndisks >= VMM_MAX_DISKS_PER_VM) {
+ if (vcp->vcp_ndisks >= VM_MAX_DISKS_PER_VM) {
log_warnx("too many disks");
return (-1);
}
}
if (strlcpy(vcp->vcp_disks[vcp->vcp_ndisks], path,
- VMM_MAX_PATH_DISK) >= VMM_MAX_PATH_DISK) {
+ VM_MAX_PATH_DISK) >= VM_MAX_PATH_DISK) {
log_warnx("disk path too long");
return (-1);
}
-/* $OpenBSD: pci.c,v 1.29 2021/06/16 16:55:02 dv Exp $ */
+/* $OpenBSD: pci.c,v 1.30 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
pci.pci_devices[id].pd_cfg_space[bar_reg_idx] =
PCI_MAPREG_MEM_ADDR(pci.pci_next_mmio_bar);
- pci.pci_next_mmio_bar += VMM_PCI_MMIO_BAR_SIZE;
+ pci.pci_next_mmio_bar += VM_PCI_MMIO_BAR_SIZE;
pci.pci_devices[id].pd_barfunc[bar_ct] = barfn;
pci.pci_devices[id].pd_bar_cookie[bar_ct] = cookie;
pci.pci_devices[id].pd_bartype[bar_ct] = PCI_BAR_TYPE_MMIO;
- pci.pci_devices[id].pd_barsize[bar_ct] = VMM_PCI_MMIO_BAR_SIZE;
+ pci.pci_devices[id].pd_barsize[bar_ct] = VM_PCI_MMIO_BAR_SIZE;
pci.pci_devices[id].pd_bar_ct++;
} else if (type == PCI_MAPREG_TYPE_IO) {
- if (pci.pci_next_io_bar >= VMM_PCI_IO_BAR_END)
+ if (pci.pci_next_io_bar >= VM_PCI_IO_BAR_END)
return (1);
pci.pci_devices[id].pd_cfg_space[bar_reg_idx] =
PCI_MAPREG_IO_ADDR(pci.pci_next_io_bar) |
PCI_MAPREG_TYPE_IO;
- pci.pci_next_io_bar += VMM_PCI_IO_BAR_SIZE;
+ pci.pci_next_io_bar += VM_PCI_IO_BAR_SIZE;
pci.pci_devices[id].pd_barfunc[bar_ct] = barfn;
pci.pci_devices[id].pd_bar_cookie[bar_ct] = cookie;
DPRINTF("%s: adding pci bar cookie for dev %d bar %d = %p",
__progname, id, bar_ct, cookie);
pci.pci_devices[id].pd_bartype[bar_ct] = PCI_BAR_TYPE_IO;
- pci.pci_devices[id].pd_barsize[bar_ct] = VMM_PCI_IO_BAR_SIZE;
+ pci.pci_devices[id].pd_barsize[bar_ct] = VM_PCI_IO_BAR_SIZE;
pci.pci_devices[id].pd_bar_ct++;
}
memset(&pci, 0, sizeof(pci));
pci.pci_next_mmio_bar = VMM_PCI_MMIO_BAR_BASE;
- pci.pci_next_io_bar = VMM_PCI_IO_BAR_BASE;
+ pci.pci_next_io_bar = VM_PCI_IO_BAR_BASE;
if (pci_add_device(&id, PCI_VENDOR_OPENBSD, PCI_PRODUCT_OPENBSD_PCHB,
PCI_CLASS_BRIDGE, PCI_SUBCLASS_BRIDGE_HOST,
for (i = 0 ; i < pci.pci_dev_ct ; i++) {
for (j = 0 ; j < pci.pci_devices[i].pd_bar_ct; j++) {
b_lo = PCI_MAPREG_IO_ADDR(pci.pci_devices[i].pd_bar[j]);
- b_hi = b_lo + VMM_PCI_IO_BAR_SIZE;
+ b_hi = b_lo + VM_PCI_IO_BAR_SIZE;
if (reg >= b_lo && reg < b_hi) {
if (pci.pci_devices[i].pd_barfunc[j]) {
k = j;
-/* $OpenBSD: priv.c,v 1.21 2022/12/15 19:36:45 millert Exp $ */
+/* $OpenBSD: priv.c,v 1.22 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
struct sockaddr_in *sin4;
struct sockaddr_in6 *sin6;
- for (i = 0; i < VMM_MAX_NICS_PER_VM; i++) {
+ for (i = 0; i < VM_MAX_NICS_PER_VM; i++) {
vif = &vm->vm_ifs[i];
if (vif->vif_name == NULL)
-/* $OpenBSD: vm.c,v 1.81 2023/01/08 19:57:17 dv Exp $ */
+/* $OpenBSD: vm.c,v 1.82 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
struct vmop_create_params *vmc = &vm->vm_params;
struct vm_create_params *vcp = &vmc->vmc_params;
struct vcpu_reg_state vrs;
- int nicfds[VMM_MAX_NICS_PER_VM];
+ int nicfds[VM_MAX_NICS_PER_VM];
int ret;
gzFile fp;
size_t i;
if (fcntl(con_fd, F_SETFL, O_NONBLOCK) == -1)
fatal("failed to set nonblocking mode on console");
- for (i = 0; i < VMM_MAX_NICS_PER_VM; i++)
+ for (i = 0; i < VM_MAX_NICS_PER_VM; i++)
nicfds[i] = vm->vm_ifs[i].vif_fd;
event_init();
vcp->vcp_nmemranges > VMM_MAX_MEM_RANGES)
return (EINVAL);
- if (vcp->vcp_ndisks > VMM_MAX_DISKS_PER_VM)
+ if (vcp->vcp_ndisks > VM_MAX_DISKS_PER_VM)
return (EINVAL);
- if (vcp->vcp_nnics > VMM_MAX_NICS_PER_VM)
+ if (vcp->vcp_nnics > VM_MAX_NICS_PER_VM)
return (EINVAL);
if (ioctl(env->vmd_fd, VMM_IOC_CREATE, vcp) == -1)
ioports_map[FW_CFG_IO_DMA_ADDR_LOW] = vcpu_exit_fw_cfg_dma;
/* Initialize PCI */
- for (i = VMM_PCI_IO_BAR_BASE; i <= VMM_PCI_IO_BAR_END; i++)
+ for (i = VM_PCI_IO_BAR_BASE; i <= VM_PCI_IO_BAR_END; i++)
ioports_map[i] = vcpu_exit_pci;
ioports_map[PCI_MODE1_ADDRESS_REG] = vcpu_exit_pci;
ioports_map[FW_CFG_IO_DMA_ADDR_LOW] = vcpu_exit_fw_cfg_dma;
/* Initialize PCI */
- for (i = VMM_PCI_IO_BAR_BASE; i <= VMM_PCI_IO_BAR_END; i++)
+ for (i = VM_PCI_IO_BAR_BASE; i <= VM_PCI_IO_BAR_END; i++)
ioports_map[i] = vcpu_exit_pci;
ioports_map[PCI_MODE1_ADDRESS_REG] = vcpu_exit_pci;
if (vcp->vcp_ncpus > VMM_MAX_VCPUS_PER_VM)
return (EINVAL);
- if (vcp->vcp_ndisks > VMM_MAX_DISKS_PER_VM)
+ if (vcp->vcp_ndisks > VM_MAX_DISKS_PER_VM)
return (EINVAL);
- if (vcp->vcp_nnics > VMM_MAX_NICS_PER_VM)
+ if (vcp->vcp_nnics > VM_MAX_NICS_PER_VM)
return (EINVAL);
if (vcp->vcp_nmemranges == 0 ||
case PCI_MODE1_DATA_REG + 3:
pci_handle_data_reg(vrp);
break;
- case VMM_PCI_IO_BAR_BASE ... VMM_PCI_IO_BAR_END:
+ case VM_PCI_IO_BAR_BASE ... VM_PCI_IO_BAR_END:
intr = pci_handle_io(vrp);
break;
default:
-/* $OpenBSD: vmd.c,v 1.137 2023/01/22 22:18:40 dv Exp $ */
+/* $OpenBSD: vmd.c,v 1.138 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
event_del(&vm->vm_iev.ev);
close(vm->vm_iev.ibuf.fd);
}
- for (i = 0; i < VMM_MAX_DISKS_PER_VM; i++) {
+ for (i = 0; i < VM_MAX_DISKS_PER_VM; i++) {
for (j = 0; j < VM_MAX_BASE_PER_DISK; j++) {
if (vm->vm_disks[i][j] != -1) {
close(vm->vm_disks[i][j]);
}
}
}
- for (i = 0; i < VMM_MAX_NICS_PER_VM; i++) {
+ for (i = 0; i < VM_MAX_NICS_PER_VM; i++) {
if (vm->vm_ifs[i].vif_fd != -1) {
close(vm->vm_ifs[i].vif_fd);
vm->vm_ifs[i].vif_fd = -1;
if (vcp->vcp_ncpus > VMM_MAX_VCPUS_PER_VM) {
log_warnx("invalid number of CPUs");
goto fail;
- } else if (vcp->vcp_ndisks > VMM_MAX_DISKS_PER_VM) {
+ } else if (vcp->vcp_ndisks > VM_MAX_DISKS_PER_VM) {
log_warnx("invalid number of disks");
goto fail;
- } else if (vcp->vcp_nnics > VMM_MAX_NICS_PER_VM) {
+ } else if (vcp->vcp_nnics > VM_MAX_NICS_PER_VM) {
log_warnx("invalid number of interfaces");
goto fail;
} else if (strlen(vcp->vcp_kernel) == 0 &&
vm->vm_receive_fd = -1;
vm->vm_state &= ~VM_STATE_PAUSED;
- for (i = 0; i < VMM_MAX_DISKS_PER_VM; i++)
+ for (i = 0; i < VM_MAX_DISKS_PER_VM; i++)
for (j = 0; j < VM_MAX_BASE_PER_DISK; j++)
vm->vm_disks[i][j] = -1;
- for (i = 0; i < VMM_MAX_NICS_PER_VM; i++)
+ for (i = 0; i < VM_MAX_NICS_PER_VM; i++)
vm->vm_ifs[i].vif_fd = -1;
for (i = 0; i < vcp->vcp_nnics; i++) {
if ((sw = switch_getbyname(vmc->vmc_ifswitch[i])) != NULL) {
-/* $OpenBSD: vmd.h,v 1.113 2023/01/14 20:55:55 dv Exp $ */
+/* $OpenBSD: vmd.h,v 1.114 2023/01/28 14:40:53 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
#define VM_NAME_MAX 64
#define VM_MAX_BASE_PER_DISK 4
#define VM_TTYNAME_MAX 16
+#define VM_MAX_DISKS_PER_VM 4
+#define VM_MAX_PATH_DISK 128
+#define VM_MAX_PATH_CDROM 128
+#define VM_MAX_KERNEL_PATH 128
+#define VM_MAX_NICS_PER_VM 4
+
+#define VM_PCI_MMIO_BAR_SIZE 0x00010000
+#define VM_PCI_IO_BAR_BASE 0x1000
+#define VM_PCI_IO_BAR_END 0xFFFF
+#define VM_PCI_IO_BAR_SIZE 0x1000
+
#define MAX_TAP 256
#define NR_BACKLOG 5
#define VMD_SWITCH_TYPE "bridge"
#define VMBOOTDEV_DISK 1
#define VMBOOTDEV_CDROM 2
#define VMBOOTDEV_NET 3
- unsigned int vmc_ifflags[VMM_MAX_NICS_PER_VM];
+ unsigned int vmc_ifflags[VM_MAX_NICS_PER_VM];
#define VMIFF_UP 0x01
#define VMIFF_LOCKED 0x02
#define VMIFF_LOCAL 0x04
#define VMIFF_RDOMAIN 0x08
#define VMIFF_OPTMASK (VMIFF_LOCKED|VMIFF_LOCAL|VMIFF_RDOMAIN)
- unsigned int vmc_disktypes[VMM_MAX_DISKS_PER_VM];
- unsigned int vmc_diskbases[VMM_MAX_DISKS_PER_VM];
+ unsigned int vmc_disktypes[VM_MAX_DISKS_PER_VM];
+ unsigned int vmc_diskbases[VM_MAX_DISKS_PER_VM];
#define VMDF_RAW 0x01
#define VMDF_QCOW2 0x02
- char vmc_ifnames[VMM_MAX_NICS_PER_VM][IF_NAMESIZE];
- char vmc_ifswitch[VMM_MAX_NICS_PER_VM][VM_NAME_MAX];
- char vmc_ifgroup[VMM_MAX_NICS_PER_VM][IF_NAMESIZE];
- unsigned int vmc_ifrdomain[VMM_MAX_NICS_PER_VM];
+ char vmc_ifnames[VM_MAX_NICS_PER_VM][IF_NAMESIZE];
+ char vmc_ifswitch[VM_MAX_NICS_PER_VM][VM_NAME_MAX];
+ char vmc_ifgroup[VM_MAX_NICS_PER_VM][IF_NAMESIZE];
+ unsigned int vmc_ifrdomain[VM_MAX_NICS_PER_VM];
struct vmop_owner vmc_owner;
/* instance template params */
uint32_t vm_vmid;
int vm_kernel;
int vm_cdrom;
- int vm_disks[VMM_MAX_DISKS_PER_VM][VM_MAX_BASE_PER_DISK];
- struct vmd_if vm_ifs[VMM_MAX_NICS_PER_VM];
+ int vm_disks[VM_MAX_DISKS_PER_VM][VM_MAX_BASE_PER_DISK];
+ struct vmd_if vm_ifs[VM_MAX_NICS_PER_VM];
char *vm_ttyname;
int vm_tty;
uint32_t vm_peerid;