Move some header definitions from vmm(4) to vmd(8).
authordv <dv@openbsd.org>
Sat, 28 Jan 2023 14:40:53 +0000 (14:40 +0000)
committerdv <dv@openbsd.org>
Sat, 28 Jan 2023 14:40:53 +0000 (14:40 +0000)
Part of an ongoing effort to move userland-specific information out
of a kernel header and directly into vmd(8). No functional change.

ok mlarkin@

sys/arch/amd64/include/vmmvar.h
usr.sbin/vmctl/vmctl.c
usr.sbin/vmd/config.c
usr.sbin/vmd/parse.y
usr.sbin/vmd/pci.c
usr.sbin/vmd/priv.c
usr.sbin/vmd/vm.c
usr.sbin/vmd/vmd.c
usr.sbin/vmd/vmd.h

index 4a248ec..344261f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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
index 19dd2f6..9567bac 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -98,7 +98,7 @@ vm_start(uint32_t start_id, const char *name, size_t memsize, int nnics,
        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");
@@ -106,7 +106,7 @@ vm_start(uint32_t start_id, const char *name, size_t memsize, int nnics,
                        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");
index c955212..9745615 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -212,7 +212,7 @@ config_getreset(struct vmd *env, struct imsg *imsg)
 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;
@@ -264,7 +264,7 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid)
        }
        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;
 
index 3175e17..76c2140 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -346,7 +346,7 @@ vm          : VM string vm_instance         {
                        } 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;
                        }
@@ -426,7 +426,7 @@ vm_opts             : disable                       {
                        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;
@@ -504,7 +504,7 @@ vm_opts             : disable                       {
                                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;
                        }
@@ -1344,7 +1344,7 @@ parse_disk(char *word, int type)
        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);
        }
@@ -1372,7 +1372,7 @@ parse_disk(char *word, int type)
        }
 
        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);
        }
index e2ec4ed..c1cd815 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -80,26 +80,26 @@ pci_add_bar(uint8_t id, uint32_t type, void *barfn, void *cookie)
 
                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++;
        }
 
@@ -216,7 +216,7 @@ pci_init(void)
 
        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,
@@ -266,7 +266,7 @@ pci_handle_io(struct vm_run_params *vrp)
        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;
index 1732140..a7a7a2b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -352,7 +352,7 @@ vm_priv_ifconfig(struct privsep *ps, struct vmd_vm *vm)
        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)
index 25204bc..bf8b0b9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -293,7 +293,7 @@ start_vm(struct vmd_vm *vm, int fd)
        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;
@@ -383,7 +383,7 @@ start_vm(struct vmd_vm *vm, int fd)
        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();
@@ -1041,10 +1041,10 @@ vmm_create_vm(struct vm_create_params *vcp)
            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)
@@ -1114,7 +1114,7 @@ init_emulated_hw(struct vmop_create_params *vmc, int child_cdrom,
        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;
@@ -1172,7 +1172,7 @@ restore_emulated_hw(struct vm_create_params *vcp, int fd,
        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;
@@ -1231,10 +1231,10 @@ run_vm(int child_cdrom, int child_disks[][VM_MAX_BASE_PER_DISK],
        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 ||
@@ -1627,7 +1627,7 @@ vcpu_exit_pci(struct vm_run_params *vrp)
        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:
index 8d8d255..f604282 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -1192,7 +1192,7 @@ vm_stop(struct vmd_vm *vm, int keeptty, const char *caller)
                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]);
@@ -1200,7 +1200,7 @@ vm_stop(struct vmd_vm *vm, int keeptty, const char *caller)
                        }
                }
        }
-       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;
@@ -1330,10 +1330,10 @@ vm_register(struct privsep *ps, struct vmop_create_params *vmc,
        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 &&
@@ -1368,10 +1368,10 @@ vm_register(struct privsep *ps, struct vmop_create_params *vmc,
        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) {
index 3e7f1d1..d04c28f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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"
@@ -195,22 +206,22 @@ struct vmop_create_params {
 #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 */
@@ -273,8 +284,8 @@ struct vmd_vm {
        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;