From: Dave Voutila Subject: remove vmd's send/receive functionality To: tech@openbsd.org Date: Thu, 05 Jun 2025 22:10:14 -0400 This diff nukes it from vmd(8) and vmctl(8). There's a vmm(4) ioctl we could nuke afterwards as well, but I wanted to keep this immediate change userland focused. vmd's send/receive functionality has been broken for some time now. I'd guess a few months. Nobody has noticed or I've not noticed anyone noticing. Clearly it has few users. I took a look at fixing it, yet again. It's often broken by advancements elsewhere in vmd. (Usually by me!) This time, it's proving to be a bit more pain to root cause and fix fully. *shrug* At this point: 1. it just gets in the way of new things I'm working on (hint: dragging vmd's virtio devices from v0.9 dark ages to modern v1.x) 2. I don't personally use it 3. I don't get help keeping it working 3 strikes, it's out. ok? diffstat /usr/src M usr.sbin/vmctl/main.c | 0+ 43- M usr.sbin/vmctl/vmctl.8 | 0+ 14- M usr.sbin/vmctl/vmctl.c | 0+ 78- M usr.sbin/vmctl/vmctl.h | 0+ 2- M usr.sbin/vmd/arm64_vm.c | 0+ 24- M usr.sbin/vmd/config.c | 5+ 12- M usr.sbin/vmd/control.c | 0+ 3- M usr.sbin/vmd/vioblk.c | 0+ 12- M usr.sbin/vmd/vionet.c | 0+ 36- M usr.sbin/vmd/vm.c | 8+ 238- M usr.sbin/vmd/vmd.c | 2+ 118- M usr.sbin/vmd/vmd.h | 0+ 5- M usr.sbin/vmd/vmm.c | 4+ 44- M usr.sbin/vmd/x86_vm.c | 0+ 245- 14 files changed, 19 insertions(+), 874 deletions(-) diff /usr/src path + /usr/src commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - fd60e9d48d0423da507e2b4f7178e3e12ece8652 file + usr.sbin/vmctl/main.c --- usr.sbin/vmctl/main.c +++ usr.sbin/vmctl/main.c @@ -63,8 +63,6 @@ int ctl_stop(struct parse_result *, int, char *[]); int ctl_waitfor(struct parse_result *, int, char *[]); int ctl_pause(struct parse_result *, int, char *[]); int ctl_unpause(struct parse_result *, int, char *[]); -int ctl_send(struct parse_result *, int, char *[]); -int ctl_receive(struct parse_result *, int, char *[]); struct ctl_command ctl_commands[] = { { "console", CMD_CONSOLE, ctl_console, "id" }, @@ -73,10 +71,8 @@ struct ctl_command ctl_commands[] = { { "load", CMD_LOAD, ctl_load, "filename" }, { "log", CMD_LOG, ctl_log, "[brief | verbose]" }, { "pause", CMD_PAUSE, ctl_pause, "id" }, - { "receive", CMD_RECEIVE, ctl_receive, "name" , 1}, { "reload", CMD_RELOAD, ctl_reload, "" }, { "reset", CMD_RESET, ctl_reset, "[all | switches | vms]" }, - { "send", CMD_SEND, ctl_send, "id", 1}, { "show", CMD_STATUS, ctl_status, "[id]" }, { "start", CMD_START, ctl_start, "[-cL] [-B device] [-b path] [-d disk] [-i count]\n" @@ -257,14 +253,6 @@ vmmaction(struct parse_result *res) case CMD_UNPAUSE: unpause_vm(res->id, res->name); break; - case CMD_SEND: - send_vm(res->id, res->name); - done = 1; - ret = 0; - break; - case CMD_RECEIVE: - vm_receive(res->id, res->name); - break; case CMD_CREATE: case NONE: /* The action is not expected here */ @@ -325,9 +313,6 @@ vmmaction(struct parse_result *res) case CMD_PAUSE: done = pause_vm_complete(&imsg, &ret); break; - case CMD_RECEIVE: - done = vm_start_complete(&imsg, &ret, 0); - break; case CMD_UNPAUSE: done = unpause_vm_complete(&imsg, &ret); break; @@ -1012,34 +997,6 @@ ctl_unpause(struct parse_result *res, int argc, char * return (vmmaction(res)); } -int -ctl_send(struct parse_result *res, int argc, char *argv[]) -{ - if (pledge("stdio unix sendfd unveil", NULL) == -1) - err(1, "pledge"); - if (argc == 2) { - if (parse_vmid(res, argv[1], 0) == -1) - errx(1, "invalid id: %s", argv[1]); - } else if (argc != 2) - ctl_usage(res->ctl); - - return (vmmaction(res)); -} - -int -ctl_receive(struct parse_result *res, int argc, char *argv[]) -{ - if (pledge("stdio unix sendfd unveil", NULL) == -1) - err(1, "pledge"); - if (argc == 2) { - if (parse_vmid(res, argv[1], 1) == -1) - errx(1, "invalid id: %s", argv[1]); - } else if (argc != 2) - ctl_usage(res->ctl); - - return (vmmaction(res)); -} - __dead void ctl_openconsole(const char *name) { commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - e76460bcd6af6b43c298a7976300e3d2eb100ed6 file + usr.sbin/vmctl/vmctl.8 --- usr.sbin/vmctl/vmctl.8 +++ usr.sbin/vmctl/vmctl.8 @@ -117,9 +117,6 @@ Disable or enable verbose debug logging. .It Cm pause Ar id Pause a VM with the specified .Ar id . -.It Cm receive Ar name -Receive a VM from standard input and start it with the specified -.Ar name . .It Cm reload Remove all stopped VMs and reload the configuration from the default configuration file. @@ -132,17 +129,6 @@ reset .Cm switches , or reset and terminate all .Cm vms . -.It Cm send Ar id -Send a VM with the specified -.Ar id -to standard output and terminate it. -The VM is paused during send processing. -Data sent to standard output contains the VM parameters and its memory, -not the disk image. -.Pp -In order to move a VM from one host to another, disk files must be -synced between the send and the receive processes and must be located -under the same path. .It Cm show Oo Fl r Oc Op Ar id An alias for the .Cm status commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - 7c4388fdcb9ff1d7b72cc449df826948b576261a file + usr.sbin/vmctl/vmctl.c --- usr.sbin/vmctl/vmctl.c +++ usr.sbin/vmctl/vmctl.c @@ -291,84 +291,6 @@ vm_start_complete(struct imsg *imsg, int *ret, int aut } void -send_vm(uint32_t id, const char *name) -{ - struct vmop_id vid; - int fds[2], readn, writen; - long pagesz; - char *buf; - - pagesz = getpagesize(); - buf = malloc(pagesz); - if (buf == NULL) - errx(1, "%s: memory allocation failure", __func__); - - memset(&vid, 0, sizeof(vid)); - vid.vid_id = id; - if (name != NULL) - strlcpy(vid.vid_name, name, sizeof(vid.vid_name)); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fds) == -1) { - warnx("%s: socketpair creation failed", __func__); - } else { - imsg_compose(ibuf, IMSG_VMDOP_SEND_VM_REQUEST, 0, 0, fds[0], - &vid, sizeof(vid)); - imsgbuf_flush(ibuf); - while (1) { - readn = atomicio(read, fds[1], buf, pagesz); - if (!readn) - break; - writen = atomicio(vwrite, STDOUT_FILENO, buf, - readn); - if (writen != readn) - break; - } - if (vid.vid_id) - warnx("sent vm %d successfully", vid.vid_id); - else - warnx("sent vm %s successfully", vid.vid_name); - } - - free(buf); -} - -void -vm_receive(uint32_t id, const char *name) -{ - struct vmop_id vid; - int fds[2], readn, writen; - long pagesz; - char *buf; - - pagesz = getpagesize(); - buf = malloc(pagesz); - if (buf == NULL) - errx(1, "%s: memory allocation failure", __func__); - - memset(&vid, 0, sizeof(vid)); - if (name != NULL) - strlcpy(vid.vid_name, name, sizeof(vid.vid_name)); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fds) == -1) { - warnx("%s: socketpair creation failed", __func__); - } else { - imsg_compose(ibuf, IMSG_VMDOP_RECEIVE_VM_REQUEST, 0, 0, fds[0], - &vid, sizeof(vid)); - imsgbuf_flush(ibuf); - while (1) { - readn = atomicio(read, STDIN_FILENO, buf, pagesz); - if (!readn) { - close(fds[1]); - break; - } - writen = atomicio(vwrite, fds[1], buf, readn); - if (writen != readn) - break; - } - } - - free(buf); -} - -void pause_vm(uint32_t pause_id, const char *name) { struct vmop_id vid; commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - 97767f466984ea586e6a555e2193c8719b35ca99 file + usr.sbin/vmctl/vmctl.h --- usr.sbin/vmctl/vmctl.h +++ usr.sbin/vmctl/vmctl.h @@ -36,8 +36,6 @@ enum actions { CMD_WAITFOR, CMD_PAUSE, CMD_UNPAUSE, - CMD_SEND, - CMD_RECEIVE, }; struct ctl_command; commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - a17bc8bc18be7c8efd3fed54b4cf20ffe9882472 file + usr.sbin/vmd/arm64_vm.c --- usr.sbin/vmd/arm64_vm.c +++ usr.sbin/vmd/arm64_vm.c @@ -43,14 +43,6 @@ init_emulated_hw(struct vmop_create_params *vcp, int c } void -restore_emulated_hw(struct vm_create_params *vcp, int fd, int *child_taps, - int child_disks[][VM_MAX_BASE_PER_DISK], int child_cdrom) -{ - fatalx("%s: unimplemented", __func__); - /* NOTREACHED */ -} - -void pause_vm_md(struct vmd_vm *vm) { fatalx("%s: unimplemented", __func__); @@ -64,22 +56,6 @@ unpause_vm_md(struct vmd_vm *vm) /* NOTREACHED */ } -int -dump_devs(int fd) -{ - fatalx("%s: unimplemented", __func__); - /* NOTREACHED */ - return (-1); -} - -int -dump_send_header(int fd) -{ - fatalx("%s: unimplemented", __func__); - /* NOTREACHED */ - return (-1); -} - void * hvaddr_mem(paddr_t gpa, size_t len) { fatalx("%s: unimplemented", __func__); commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - bb2ac1523aaa3fb5c0326f32b05d17c8764ae70b file + usr.sbin/vmd/config.c --- usr.sbin/vmd/config.c +++ usr.sbin/vmd/config.c @@ -258,7 +258,7 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, ui /* * From here onward, all failures need cleanup and use goto fail */ - if (!(vm->vm_state & VM_STATE_RECEIVED) && vm->vm_kernel == -1) { + if (vm->vm_kernel == -1) { if (vm->vm_kernel_path != NULL) { /* Open external kernel for child */ kernfd = open(vm->vm_kernel_path, O_RDONLY | O_CLOEXEC); @@ -455,14 +455,8 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, ui /* Send VM information */ /* XXX check proc_compose_imsg return values */ - if (vm->vm_state & VM_STATE_RECEIVED) - proc_compose_imsg(ps, PROC_VMM, -1, - IMSG_VMDOP_RECEIVE_VM_REQUEST, vm->vm_vmid, fd, vmc, - sizeof(struct vmop_create_params)); - else - proc_compose_imsg(ps, PROC_VMM, -1, - IMSG_VMDOP_START_VM_REQUEST, vm->vm_vmid, vm->vm_kernel, - vmc, sizeof(*vmc)); + proc_compose_imsg(ps, PROC_VMM, -1, IMSG_VMDOP_START_VM_REQUEST, + vm->vm_vmid, vm->vm_kernel, vmc, sizeof(*vmc)); if (strlen(vmc->vmc_cdrom)) proc_compose_imsg(ps, PROC_VMM, -1, @@ -490,9 +484,8 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, ui vm->vm_vmid, dup(tapfds[i]), &var, sizeof(var)); } - if (!(vm->vm_state & VM_STATE_RECEIVED)) - proc_compose_imsg(ps, PROC_VMM, -1, - IMSG_VMDOP_START_VM_END, vm->vm_vmid, fd, NULL, 0); + proc_compose_imsg(ps, PROC_VMM, -1, IMSG_VMDOP_START_VM_END, + vm->vm_vmid, fd, NULL, 0); free(tapfds); commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - de7325fdeac0bd6a28af675664bca4d9b70b44e9 file + usr.sbin/vmd/control.c --- usr.sbin/vmd/control.c +++ usr.sbin/vmd/control.c @@ -93,7 +93,6 @@ control_dispatch_vmd(int fd, struct privsep_proc *p, s switch (type) { case IMSG_VMDOP_START_VM_RESPONSE: case IMSG_VMDOP_PAUSE_VM_RESPONSE: - case IMSG_VMDOP_SEND_VM_RESPONSE: case IMSG_VMDOP_UNPAUSE_VM_RESPONSE: case IMSG_VMDOP_GET_INFO_VM_DATA: case IMSG_VMDOP_GET_INFO_VM_END_DATA: @@ -438,8 +437,6 @@ control_dispatch_imsg(int fd, short event, void *arg) peer_id, -1, &v, sizeof(v))) goto fail; break; - case IMSG_VMDOP_RECEIVE_VM_REQUEST: - case IMSG_VMDOP_SEND_VM_REQUEST: case IMSG_CTL_RESET: case IMSG_VMDOP_LOAD: case IMSG_VMDOP_RELOAD: commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - a822584de0f3c41c8e40f96f04f04173d0e5bac6 file + usr.sbin/vmd/vioblk.c --- usr.sbin/vmd/vioblk.c +++ usr.sbin/vmd/vioblk.c @@ -155,10 +155,6 @@ vioblk_main(int fd, int fd_vmm) log_debug("%s: initialized vioblk%d with %s image (capacity=%lld)", __func__, vioblk->idx, disk_type(type), vioblk->capacity); - /* If we're restoring hardware, reinitialize the virtqueue hva. */ - if (vm.vm_state & VM_STATE_RECEIVED) - vioblk_update_qa(vioblk); - /* Initialize libevent so we can start wiring event handlers. */ event_init(); @@ -540,14 +536,6 @@ handle_sync_io(int fd, short event, void *arg) imsg_free(&imsg); switch (msg.type) { - case VIODEV_MSG_DUMP: - /* Dump device */ - n = atomicio(vwrite, dev->sync_fd, dev, sizeof(*dev)); - if (n != sizeof(*dev)) { - log_warnx("%s: failed to dump vioblk device", - __func__); - break; - } case VIODEV_MSG_IO_READ: /* Read IO: make sure to send a reply */ msg.data = handle_io_read(&msg, dev, &intr); commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - 6d45fc4f675cd0af27ae6364fa5de282cc10686a file + usr.sbin/vmd/vionet.c --- usr.sbin/vmd/vionet.c +++ usr.sbin/vmd/vionet.c @@ -159,34 +159,6 @@ vionet_main(int fd, int fd_vmm) if (pledge("stdio", NULL) == -1) fatal("pledge2"); - /* If we're restoring hardware, re-initialize virtqueue hva's. */ - if (vm.vm_state & VM_STATE_RECEIVED) { - struct virtio_vq_info *vq_info; - void *hva = NULL; - - vq_info = &dev.vionet.vq[TXQ]; - if (vq_info->q_gpa != 0) { - log_debug("%s: restoring TX virtqueue for gpa 0x%llx", - __func__, vq_info->q_gpa); - hva = hvaddr_mem(vq_info->q_gpa, - vring_size(VIONET_QUEUE_SIZE)); - if (hva == NULL) - fatalx("%s: hva == NULL", __func__); - vq_info->q_hva = hva; - } - - vq_info = &dev.vionet.vq[RXQ]; - if (vq_info->q_gpa != 0) { - log_debug("%s: restoring RX virtqueue for gpa 0x%llx", - __func__, vq_info->q_gpa); - hva = hvaddr_mem(vq_info->q_gpa, - vring_size(VIONET_QUEUE_SIZE)); - if (hva == NULL) - fatalx("%s: hva == NULL", __func__); - vq_info->q_hva = hva; - } - } - /* Initialize our packet injection pipe. */ if (pipe2(pipe_inject, O_NONBLOCK) == -1) { log_warn("%s: injection pipe", __func__); @@ -1015,14 +987,6 @@ handle_sync_io(int fd, short event, void *arg) imsg_free(&imsg); switch (msg.type) { - case VIODEV_MSG_DUMP: - /* Dump device */ - n = atomicio(vwrite, dev->sync_fd, dev, sizeof(*dev)); - if (n != sizeof(*dev)) { - log_warnx("%s: failed to dump vionet device", - __func__); - break; - } case VIODEV_MSG_IO_READ: /* Read IO: make sure to send a reply */ msg.data = handle_io_read(&msg, dev, &intr); commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - feee29aab481e3a965bb5001bea710b6477f3646 file + usr.sbin/vmd/vm.c --- usr.sbin/vmd/vm.c +++ usr.sbin/vmd/vm.c @@ -49,12 +49,6 @@ static void vm_dispatch_vmm(int, short, void *); static void *event_thread(void *); static void *vcpu_run_loop(void *); static int vmm_create_vm(struct vmd_vm *); -static int send_vm(int, struct vmd_vm *); -static int dump_vmr(int , struct vm_mem_range *); -static int dump_mem(int, struct vmd_vm *); -static void restore_vmr(int, struct vm_mem_range *); -static void restore_mem(int, struct vm_create_params *); -static int restore_vm_params(int, struct vm_create_params *); static void pause_vm(struct vmd_vm *); static void unpause_vm(struct vmd_vm *); static int start_vm(struct vmd_vm *, int); @@ -143,12 +137,9 @@ vm_main(int fd, int fd_vmm) * We need, at minimum, a vm_kernel fd to boot a vm. This is either a * kernel or a BIOS image. */ - if (!(vm.vm_state & VM_STATE_RECEIVED)) { - if (vm.vm_kernel == -1) { - log_warnx("%s: failed to receive boot fd", - vcp->vcp_name); - _exit(EINVAL); - } + if (vm.vm_kernel == -1) { + log_warnx("%s: failed to receive boot fd", vcp->vcp_name); + _exit(EINVAL); } if (vcp->vcp_sev && env->vmd_psp_fd < 0) { @@ -191,14 +182,12 @@ start_vm(struct vmd_vm *vm, int fd) int nicfds[VM_MAX_NICS_PER_VM]; int ret; size_t i; - struct vm_rwregs_params vrp; /* * We first try to initialize and allocate memory before bothering * vmm(4) with a request to create a new vm. */ - if (!(vm->vm_state & VM_STATE_RECEIVED)) - create_memory_map(vcp); + create_memory_map(vcp); /* Create the vm in vmm(4). */ ret = vmm_create_vm(vm); @@ -247,13 +236,8 @@ start_vm(struct vmd_vm *vm, int fd) return (1); } - /* Prepare either our boot image or receive an existing vm to launch. */ - if (vm->vm_state & VM_STATE_RECEIVED) { - ret = atomicio(read, vm->vm_receive_fd, &vrp, sizeof(vrp)); - if (ret != sizeof(vrp)) - fatal("received incomplete vrp - exiting"); - vrs = vrp.vrwp_regs; - } else if (load_firmware(vm, &vrs)) + /* Prepare our boot image. */ + if (load_firmware(vm, &vrs)) fatalx("failed to load kernel or firmware image"); if (vm->vm_kernel != -1) @@ -291,21 +275,12 @@ start_vm(struct vmd_vm *vm, int fd) fatal("setup vm pipe"); /* - * Initialize or restore our emulated hardware. + * Initialize our emulated hardware. */ for (i = 0; i < VMM_MAX_NICS_PER_VM; i++) nicfds[i] = vm->vm_ifs[i].vif_fd; + init_emulated_hw(vmc, vm->vm_cdrom, vm->vm_disks, nicfds); - if (vm->vm_state & VM_STATE_RECEIVED) { - restore_mem(vm->vm_receive_fd, vcp); - restore_emulated_hw(vcp, vm->vm_receive_fd, nicfds, - vm->vm_disks, vm->vm_cdrom); - if (restore_vm_params(vm->vm_receive_fd, vcp)) - fatal("restore vm params failed"); - unpause_vm(vm); - } else - init_emulated_hw(vmc, vm->vm_cdrom, vm->vm_disks, nicfds); - /* Drop privleges further before starting the vcpu run loop(s). */ if (pledge("stdio vmm recvfd", NULL) == -1) fatal("pledge"); @@ -404,17 +379,6 @@ vm_dispatch_vmm(int fd, short event, void *arg) IMSG_VMDOP_UNPAUSE_VM_RESPONSE, id, pid, -1, &vmr, sizeof(vmr)); break; - case IMSG_VMDOP_SEND_VM_REQUEST: - vmr.vmr_id = vm->vm_vmid; - vmr.vmr_result = send_vm(imsg_get_fd(&imsg), vm); - imsg_compose_event(&vm->vm_iev, - IMSG_VMDOP_SEND_VM_RESPONSE, id, pid, -1, &vmr, - sizeof(vmr)); - if (!vmr.vmr_result) { - imsgbuf_flush(¤t_vm->vm_iev.ibuf); - _exit(0); - } - break; case IMSG_VMDOP_PRIV_GET_ADDR_RESPONSE: vmop_addr_result_read(&imsg, &var); log_debug("%s: received tap addr %s for nic %d", @@ -461,186 +425,6 @@ vm_shutdown(unsigned int cmd) _exit(0); } -int -send_vm(int fd, struct vmd_vm *vm) -{ - struct vm_rwregs_params vrp; - struct vm_rwvmparams_params vpp; - struct vmop_create_params *vmc; - struct vm_terminate_params vtp; - unsigned int flags = 0; - unsigned int i; - int ret = 0; - size_t sz; - - if (dump_send_header(fd)) { - log_warnx("%s: failed to send vm dump header", __func__); - goto err; - } - - pause_vm(vm); - - vmc = calloc(1, sizeof(struct vmop_create_params)); - if (vmc == NULL) { - log_warn("%s: calloc error getting vmc", __func__); - ret = -1; - goto err; - } - - flags |= VMOP_CREATE_MEMORY; - memcpy(&vmc->vmc_params, ¤t_vm->vm_params, sizeof(struct - vmop_create_params)); - vmc->vmc_flags = flags; - vrp.vrwp_vm_id = vm->vm_params.vmc_params.vcp_id; - vrp.vrwp_mask = VM_RWREGS_ALL; - vpp.vpp_mask = VM_RWVMPARAMS_ALL; - vpp.vpp_vm_id = vm->vm_params.vmc_params.vcp_id; - - sz = atomicio(vwrite, fd, vmc, sizeof(struct vmop_create_params)); - if (sz != sizeof(struct vmop_create_params)) { - ret = -1; - goto err; - } - - for (i = 0; i < vm->vm_params.vmc_params.vcp_ncpus; i++) { - vrp.vrwp_vcpu_id = i; - if ((ret = ioctl(env->vmd_fd, VMM_IOC_READREGS, &vrp))) { - log_warn("%s: readregs failed", __func__); - goto err; - } - - sz = atomicio(vwrite, fd, &vrp, - sizeof(struct vm_rwregs_params)); - if (sz != sizeof(struct vm_rwregs_params)) { - log_warn("%s: dumping registers failed", __func__); - ret = -1; - goto err; - } - } - - /* Dump memory before devices to aid in restoration. */ - if ((ret = dump_mem(fd, vm))) - goto err; - if ((ret = dump_devs(fd))) - goto err; - if ((ret = pci_dump(fd))) - goto err; - if ((ret = virtio_dump(fd))) - goto err; - - for (i = 0; i < vm->vm_params.vmc_params.vcp_ncpus; i++) { - vpp.vpp_vcpu_id = i; - if ((ret = ioctl(env->vmd_fd, VMM_IOC_READVMPARAMS, &vpp))) { - log_warn("%s: readvmparams failed", __func__); - goto err; - } - - sz = atomicio(vwrite, fd, &vpp, - sizeof(struct vm_rwvmparams_params)); - if (sz != sizeof(struct vm_rwvmparams_params)) { - log_warn("%s: dumping vm params failed", __func__); - ret = -1; - goto err; - } - } - - vtp.vtp_vm_id = vm->vm_params.vmc_params.vcp_id; - if (ioctl(env->vmd_fd, VMM_IOC_TERM, &vtp) == -1) { - log_warnx("%s: term IOC error: %d, %d", __func__, - errno, ENOENT); - } -err: - close(fd); - if (ret) - unpause_vm(vm); - return ret; -} - -int -dump_mem(int fd, struct vmd_vm *vm) -{ - unsigned int i; - int ret; - struct vm_mem_range *vmr; - - for (i = 0; i < vm->vm_params.vmc_params.vcp_nmemranges; i++) { - vmr = &vm->vm_params.vmc_params.vcp_memranges[i]; - ret = dump_vmr(fd, vmr); - if (ret) - return ret; - } - return (0); -} - -int -restore_vm_params(int fd, struct vm_create_params *vcp) { - unsigned int i; - struct vm_rwvmparams_params vpp; - - for (i = 0; i < vcp->vcp_ncpus; i++) { - if (atomicio(read, fd, &vpp, sizeof(vpp)) != sizeof(vpp)) { - log_warn("%s: error restoring vm params", __func__); - return (-1); - } - vpp.vpp_vm_id = vcp->vcp_id; - vpp.vpp_vcpu_id = i; - if (ioctl(env->vmd_fd, VMM_IOC_WRITEVMPARAMS, &vpp) < 0) { - log_debug("%s: writing vm params failed", __func__); - return (-1); - } - } - return (0); -} - -void -restore_mem(int fd, struct vm_create_params *vcp) -{ - unsigned int i; - struct vm_mem_range *vmr; - - for (i = 0; i < vcp->vcp_nmemranges; i++) { - vmr = &vcp->vcp_memranges[i]; - restore_vmr(fd, vmr); - } -} - -int -dump_vmr(int fd, struct vm_mem_range *vmr) -{ - size_t rem = vmr->vmr_size, read=0; - char buf[PAGE_SIZE]; - - while (rem > 0) { - if (read_mem(vmr->vmr_gpa + read, buf, PAGE_SIZE)) { - log_warn("failed to read vmr"); - return (-1); - } - if (atomicio(vwrite, fd, buf, sizeof(buf)) != sizeof(buf)) { - log_warn("failed to dump vmr"); - return (-1); - } - rem = rem - PAGE_SIZE; - read = read + PAGE_SIZE; - } - return (0); -} - -void -restore_vmr(int fd, struct vm_mem_range *vmr) -{ - size_t rem = vmr->vmr_size, wrote=0; - char buf[PAGE_SIZE]; - - while (rem > 0) { - if (atomicio(read, fd, buf, sizeof(buf)) != sizeof(buf)) - fatal("failed to restore vmr"); - if (write_mem(vmr->vmr_gpa + wrote, buf, PAGE_SIZE)) - fatal("failed to write vmr"); - rem = rem - PAGE_SIZE; - wrote = wrote + PAGE_SIZE; - } -} - static void pause_vm(struct vmd_vm *vm) { @@ -813,7 +597,6 @@ static int run_vm(struct vmop_create_params *vmc, struct vcpu_reg_state *vrs) { struct vm_create_params *vcp = &vmc->vmc_params; - struct vm_rwregs_params vregsp; uint8_t evdone = 0; size_t i; int ret; @@ -882,19 +665,6 @@ run_vm(struct vmop_create_params *vmc, struct vcpu_reg return (EIO); } - /* once more because reset_cpu changes regs */ - if (current_vm->vm_state & VM_STATE_RECEIVED) { - vregsp.vrwp_vm_id = vcp->vcp_id; - vregsp.vrwp_vcpu_id = i; - vregsp.vrwp_regs = *vrs; - vregsp.vrwp_mask = VM_RWREGS_ALL; - if ((ret = ioctl(env->vmd_fd, VMM_IOC_WRITEREGS, - &vregsp)) == -1) { - log_warn("%s: writeregs failed", __func__); - return (ret); - } - } - if (sev_encrypt_state(current_vm, i)) { log_warnx("%s: state encryption failed for VCPU " "%zu failed - exiting.", __progname, i); commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - cfaedcbeb9c4a4b3dd55b1b8519d0319281af934 file + usr.sbin/vmd/vmd.c --- usr.sbin/vmd/vmd.c +++ usr.sbin/vmd/vmd.c @@ -54,7 +54,6 @@ int vmd_dispatch_control(int, struct privsep_proc *, int vmd_dispatch_vmm(int, struct privsep_proc *, struct imsg *); int vmd_dispatch_agentx(int, struct privsep_proc *, struct imsg *); int vmd_dispatch_priv(int, struct privsep_proc *, struct imsg *); -int vmd_check_vmh(struct vm_dump_header *); int vm_instance(struct privsep *, struct vmd_vm **, struct vmop_create_params *, uid_t); @@ -92,18 +91,15 @@ int vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg) { struct privsep *ps = p->p_ps; - int res = 0, ret = 0, cmd = 0, verbose; - int ifd; + int res = 0, cmd = 0, verbose; unsigned int v = 0, flags; struct vmop_create_params vmc; struct vmop_id vid; struct vmop_result vmr; - struct vm_dump_header vmh; struct vmd_vm *vm = NULL; char *str = NULL; uint32_t peer_id, type, vm_id = 0; struct control_sock *rcs; - size_t i; peer_id = imsg_get_id(imsg); type = imsg_get_type(imsg); @@ -251,95 +247,6 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, s proc_compose_imsg(ps, PROC_VMM, -1, type, vm->vm_peerid, -1, &vid, sizeof(vid)); break; - case IMSG_VMDOP_SEND_VM_REQUEST: - vmop_id_read(imsg, &vid); - vm_id = vid.vid_id; - ifd = imsg_get_fd(imsg); - if (vid.vid_id == 0) { - if ((vm = vm_getbyname(vid.vid_name)) == NULL) { - res = ENOENT; - cmd = IMSG_VMDOP_SEND_VM_RESPONSE; - close(ifd); - break; - } else { - vid.vid_id = vm->vm_vmid; - } - } else if ((vm = vm_getbyvmid(vid.vid_id)) == NULL) { - res = ENOENT; - cmd = IMSG_VMDOP_SEND_VM_RESPONSE; - close(ifd); - break; - } - vmr.vmr_id = vid.vid_id; - log_debug("%s: sending fd to vmm", __func__); - proc_compose_imsg(ps, PROC_VMM, -1, type, peer_id, ifd, &vid, - sizeof(vid)); - break; - case IMSG_VMDOP_RECEIVE_VM_REQUEST: - vmop_id_read(imsg, &vid); - ifd = imsg_get_fd(imsg); - if (ifd == -1) { - log_warnx("%s: invalid fd", __func__); - return (-1); - } - if (atomicio(read, ifd, &vmh, sizeof(vmh)) != sizeof(vmh)) { - log_warnx("%s: error reading vmh from received vm", - __func__); - res = EIO; - close(ifd); - cmd = IMSG_VMDOP_START_VM_RESPONSE; - break; - } - - if (vmd_check_vmh(&vmh)) { - res = ENOENT; - close(ifd); - cmd = IMSG_VMDOP_START_VM_RESPONSE; - break; - } - if (atomicio(read, ifd, &vmc, sizeof(vmc)) != sizeof(vmc)) { - log_warnx("%s: error reading vmc from received vm", - __func__); - res = EIO; - close(ifd); - cmd = IMSG_VMDOP_START_VM_RESPONSE; - break; - } - - /* vm_create_params was read from an untrusted source. Scrub. */ - vmc.vmc_params.vcp_name[sizeof(vmc.vmc_params.vcp_name) - 1] = - '\0'; - for (i = 0; i < nitems(vmc.vmc_disks); i++) - vmc.vmc_disks[i][sizeof(vmc.vmc_disks[i]) - 1] = '\0'; - for (i = 0; i < nitems(vmc.vmc_ifnames); i++) - vmc.vmc_ifnames[i][sizeof(vmc.vmc_ifnames[i]) - 1] - = '\0'; - for (i = 0; i < nitems(vmc.vmc_ifswitch); i++) - vmc.vmc_ifswitch[i][sizeof(vmc.vmc_ifswitch[i]) - 1] - = '\0'; - for (i = 0; i < nitems(vmc.vmc_ifgroup); i++) - vmc.vmc_ifgroup[i][sizeof(vmc.vmc_ifgroup[i]) - 1] - = '\0'; - vmc.vmc_instance[sizeof(vmc.vmc_instance) - 1] = '\0'; - - strlcpy(vmc.vmc_params.vcp_name, vid.vid_name, - sizeof(vmc.vmc_params.vcp_name)); - vmc.vmc_params.vcp_id = 0; - - ret = vm_register(ps, &vmc, &vm, 0, vmc.vmc_owner.uid); - if (ret != 0) { - res = errno; - cmd = IMSG_VMDOP_START_VM_RESPONSE; - close(ifd); - } else { - vm->vm_state |= VM_STATE_RECEIVED; - config_setvm(ps, vm, peer_id, vmc.vmc_owner.uid); - log_debug("%s: sending fd to vmm", __func__); - proc_compose_imsg(ps, PROC_VMM, -1, - IMSG_VMDOP_RECEIVE_VM_END, vm->vm_vmid, ifd, - NULL, 0); - } - break; case IMSG_VMDOP_DONE: control_reset(&ps->ps_csock); TAILQ_FOREACH(rcs, &ps->ps_rcsocks, cs_entry) @@ -463,28 +370,6 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struc vm->vm_state |= VM_STATE_SHUTDOWN; } break; - case IMSG_VMDOP_SEND_VM_RESPONSE: - vmop_result_read(imsg, &vmr); - if ((vm = vm_getbyvmid(vmr.vmr_id)) == NULL) - break; - if (!vmr.vmr_result) { - log_info("%s: sent vm %d successfully.", - vm->vm_params.vmc_params.vcp_name, - vm->vm_vmid); - vm_terminate(vm, __func__); - } - - /* Send a response if a control client is waiting for it */ - if (peer_id != (uint32_t)-1) { - /* the error is meaningless for deferred responses */ - vmr.vmr_result = 0; - - if (proc_compose_imsg(ps, PROC_CONTROL, -1, - IMSG_VMDOP_SEND_VM_RESPONSE, peer_id, -1, &vmr, - sizeof(vmr)) == -1) - return (-1); - } - break; case IMSG_VMDOP_TERMINATE_VM_EVENT: vmop_result_read(imsg, &vmr); DPRINTF("%s: handling TERMINATE_EVENT for vm id %d ret %d", @@ -1150,8 +1035,7 @@ vm_stop(struct vmd_vm *vm, int keeptty, const char *ca __func__, ps->ps_title[privsep_process], caller, vm->vm_vmid, keeptty ? ", keeping tty open" : ""); - vm->vm_state &= ~(VM_STATE_RECEIVED | VM_STATE_RUNNING - | VM_STATE_SHUTDOWN); + vm->vm_state &= ~(VM_STATE_RUNNING | VM_STATE_SHUTDOWN); if (vm->vm_iev.ibuf.fd != -1) { event_del(&vm->vm_iev.ev); commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - 8efae7f0b109e1763e3442883ebe6634c32c8185 file + usr.sbin/vmd/vmd.h --- usr.sbin/vmd/vmd.h +++ usr.sbin/vmd/vmd.h @@ -115,10 +115,6 @@ enum imsg_type { IMSG_VMDOP_PAUSE_VM_RESPONSE, IMSG_VMDOP_UNPAUSE_VM, IMSG_VMDOP_UNPAUSE_VM_RESPONSE, - IMSG_VMDOP_SEND_VM_REQUEST, - IMSG_VMDOP_SEND_VM_RESPONSE, - IMSG_VMDOP_RECEIVE_VM_REQUEST, - IMSG_VMDOP_RECEIVE_VM_END, IMSG_VMDOP_WAIT_VM_REQUEST, IMSG_VMDOP_TERMINATE_VM_REQUEST, IMSG_VMDOP_TERMINATE_VM_RESPONSE, @@ -322,7 +318,6 @@ struct vmd_vm { #define VM_STATE_DISABLED 0x02 /* When set, VM is marked to be shut down */ #define VM_STATE_SHUTDOWN 0x04 -#define VM_STATE_RECEIVED 0x08 #define VM_STATE_PAUSED 0x10 #define VM_STATE_WAITING 0x20 commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - 85164d7bed27c5b8e10139588103203b87edbfc9 file + usr.sbin/vmd/vmm.c --- usr.sbin/vmd/vmm.c +++ usr.sbin/vmd/vmm.c @@ -100,7 +100,6 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, st struct vm_terminate_params vtp; struct vmop_id vid; struct vmop_result vmr; - struct vmop_create_params vmc; struct vmop_addr_result var; uint32_t id = 0, vm_id, type; pid_t pid, vm_pid = 0; @@ -250,43 +249,6 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, st imsg_compose_event(&vm->vm_iev, type, -1, pid, imsg_get_fd(imsg), &vid, sizeof(vid)); break; - case IMSG_VMDOP_SEND_VM_REQUEST: - vmop_id_read(imsg, &vid); - id = vid.vid_id; - if ((vm = vm_getbyvmid(id)) == NULL) { - res = ENOENT; - close(imsg_get_fd(imsg)); /* XXX */ - cmd = IMSG_VMDOP_START_VM_RESPONSE; - break; - } - imsg_compose_event(&vm->vm_iev, type, -1, pid, - imsg_get_fd(imsg), &vid, sizeof(vid)); - break; - case IMSG_VMDOP_RECEIVE_VM_REQUEST: - vmop_create_params_read(imsg, &vmc); - if (vm_register(ps, &vmc, &vm, vm_id, vmc.vmc_owner.uid) != 0) { - res = errno; - cmd = IMSG_VMDOP_START_VM_RESPONSE; - break; - } - vm->vm_tty = imsg_get_fd(imsg); - vm->vm_state |= VM_STATE_RECEIVED; - vm->vm_state |= VM_STATE_PAUSED; - break; - case IMSG_VMDOP_RECEIVE_VM_END: - if ((vm = vm_getbyvmid(vm_id)) == NULL) { - res = ENOENT; - close(imsg_get_fd(imsg)); /* XXX */ - cmd = IMSG_VMDOP_START_VM_RESPONSE; - break; - } - vm->vm_receive_fd = imsg_get_fd(imsg); - res = vmm_start_vm(imsg, &id, &pid); - /* Check if the ID can be mapped correctly */ - if ((id = vm_id2vmid(id, NULL)) == 0) - res = ENOENT; - cmd = IMSG_VMDOP_START_VM_RESPONSE; - break; case IMSG_VMDOP_PRIV_GET_ADDR_RESPONSE: vmop_addr_result_read(imsg, &var); if ((vm = vm_getbyvmid(var.var_vmid)) == NULL) { @@ -523,7 +485,6 @@ vmm_dispatch_vm(int fd, short event, void *arg) case IMSG_VMDOP_VM_REBOOT: vm->vm_state &= ~VM_STATE_SHUTDOWN; break; - case IMSG_VMDOP_SEND_VM_RESPONSE: case IMSG_VMDOP_PAUSE_VM_RESPONSE: case IMSG_VMDOP_UNPAUSE_VM_RESPONSE: for (i = 0; i < nitems(procs); i++) { @@ -644,13 +605,12 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *p } vcp = &vm->vm_params.vmc_params; - if (!(vm->vm_state & VM_STATE_RECEIVED)) { - if ((vm->vm_tty = imsg_get_fd(imsg)) == -1) { - log_warnx("%s: can't get tty", __func__); - goto err; - } + if ((vm->vm_tty = imsg_get_fd(imsg)) == -1) { + log_warnx("%s: can't get tty", __func__); + goto err; } + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, fds) == -1) fatal("socketpair"); commit - 9260884d99d8c4ba4d2a8372e6dee6765b6149b7 blob - aa64ddb02e83af21648fd80a14968f6716db20d8 file + usr.sbin/vmd/x86_vm.c --- usr.sbin/vmd/x86_vm.c +++ usr.sbin/vmd/x86_vm.c @@ -402,64 +402,7 @@ init_emulated_hw(struct vmop_create_params *vmc, int c ioports_map[FW_CFG_IO_DMA_ADDR_LOW] = vcpu_exit_fw_cfg_dma; } -/* - * restore_emulated_hw - * - * Restores the userspace hardware emulation from fd - */ void -restore_emulated_hw(struct vm_create_params *vcp, int fd, - int *child_taps, int child_disks[][VM_MAX_BASE_PER_DISK], int child_cdrom) -{ - /* struct vm_create_params *vcp = &vmc->vmc_params; */ - int i; - memset(&ioports_map, 0, sizeof(io_fn_t) * MAX_PORTS); - - /* Init i8253 PIT */ - i8253_restore(fd, vcp->vcp_id); - ioports_map[TIMER_CTRL] = vcpu_exit_i8253; - ioports_map[TIMER_BASE + TIMER_CNTR0] = vcpu_exit_i8253; - ioports_map[TIMER_BASE + TIMER_CNTR1] = vcpu_exit_i8253; - ioports_map[TIMER_BASE + TIMER_CNTR2] = vcpu_exit_i8253; - - /* Init master and slave PICs */ - i8259_restore(fd); - ioports_map[IO_ICU1] = vcpu_exit_i8259; - ioports_map[IO_ICU1 + 1] = vcpu_exit_i8259; - ioports_map[IO_ICU2] = vcpu_exit_i8259; - ioports_map[IO_ICU2 + 1] = vcpu_exit_i8259; - - /* Init ns8250 UART */ - ns8250_restore(fd, con_fd, vcp->vcp_id); - for (i = COM1_DATA; i <= COM1_SCR; i++) - ioports_map[i] = vcpu_exit_com; - - /* Init mc146818 RTC */ - mc146818_restore(fd, vcp->vcp_id); - ioports_map[IO_RTC] = vcpu_exit_mc146818; - ioports_map[IO_RTC + 1] = vcpu_exit_mc146818; - - /* Init QEMU fw_cfg interface */ - fw_cfg_restore(fd); - ioports_map[FW_CFG_IO_SELECT] = vcpu_exit_fw_cfg; - ioports_map[FW_CFG_IO_DATA] = vcpu_exit_fw_cfg; - ioports_map[FW_CFG_IO_DMA_ADDR_HIGH] = vcpu_exit_fw_cfg_dma; - ioports_map[FW_CFG_IO_DMA_ADDR_LOW] = vcpu_exit_fw_cfg_dma; - - /* Initialize PCI */ - 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[PCI_MODE1_DATA_REG] = vcpu_exit_pci; - ioports_map[PCI_MODE1_DATA_REG + 1] = vcpu_exit_pci; - ioports_map[PCI_MODE1_DATA_REG + 2] = vcpu_exit_pci; - ioports_map[PCI_MODE1_DATA_REG + 3] = vcpu_exit_pci; - pci_restore(fd); - virtio_restore(fd, current_vm, child_cdrom, child_disks, child_taps); -} - -void pause_vm_md(struct vmd_vm *vm) { i8253_stop(); @@ -477,65 +420,6 @@ unpause_vm_md(struct vmd_vm *vm) virtio_start(vm); } -int -dump_devs(int fd) -{ - int ret = 0; - - if ((ret = i8253_dump(fd))) - return ret; - if ((ret = i8259_dump(fd))) - return ret; - if ((ret = ns8250_dump(fd))) - return ret; - if ((ret = mc146818_dump(fd))) - return ret; - ret = fw_cfg_dump(fd); - - return ret; -} - -int -dump_send_header(int fd) { - struct vm_dump_header vmh; - int i; - - memcpy(&vmh.vmh_signature, VM_DUMP_SIGNATURE, - sizeof(vmh.vmh_signature)); - - vmh.vmh_cpuids[0].code = 0x00; - vmh.vmh_cpuids[0].leaf = 0x00; - - vmh.vmh_cpuids[1].code = 0x01; - vmh.vmh_cpuids[1].leaf = 0x00; - - vmh.vmh_cpuids[2].code = 0x07; - vmh.vmh_cpuids[2].leaf = 0x00; - - vmh.vmh_cpuids[3].code = 0x0d; - vmh.vmh_cpuids[3].leaf = 0x00; - - vmh.vmh_cpuids[4].code = 0x80000001; - vmh.vmh_cpuids[4].leaf = 0x00; - - vmh.vmh_version = VM_DUMP_VERSION; - - for (i=0; i < VM_DUMP_HEADER_CPUID_COUNT; i++) { - CPUID_LEAF(vmh.vmh_cpuids[i].code, - vmh.vmh_cpuids[i].leaf, - vmh.vmh_cpuids[i].a, - vmh.vmh_cpuids[i].b, - vmh.vmh_cpuids[i].c, - vmh.vmh_cpuids[i].d); - } - - if (atomicio(vwrite, fd, &vmh, sizeof(vmh)) != sizeof(vmh)) - return (-1); - - return (0); -} - - /* * vcpu_exit_inout * @@ -1238,132 +1122,3 @@ intr_toggle_el(struct vmd_vm *vm, int irq, int val) /* XXX select active interrupt controller */ pic_set_elcr(irq, val); } - -int -vmd_check_vmh(struct vm_dump_header *vmh) -{ - int i; - unsigned int code, leaf; - unsigned int a, b, c, d; - - if (strncmp(vmh->vmh_signature, VM_DUMP_SIGNATURE, strlen(VM_DUMP_SIGNATURE)) != 0) { - log_warnx("%s: incompatible dump signature", __func__); - return (-1); - } - - if (vmh->vmh_version != VM_DUMP_VERSION) { - log_warnx("%s: incompatible dump version", __func__); - return (-1); - } - - for (i = 0; i < VM_DUMP_HEADER_CPUID_COUNT; i++) { - code = vmh->vmh_cpuids[i].code; - leaf = vmh->vmh_cpuids[i].leaf; - if (leaf != 0x00) { - log_debug("%s: invalid leaf 0x%x for code 0x%x", - __func__, leaf, code); - return (-1); - } - - switch (code) { - case 0x00: - CPUID_LEAF(code, leaf, a, b, c, d); - if (vmh->vmh_cpuids[i].a > a) { - log_debug("%s: incompatible cpuid level", - __func__); - return (-1); - } - if (!(vmh->vmh_cpuids[i].b == b && - vmh->vmh_cpuids[i].c == c && - vmh->vmh_cpuids[i].d == d)) { - log_debug("%s: incompatible cpu brand", - __func__); - return (-1); - } - break; - - case 0x01: - CPUID_LEAF(code, leaf, a, b, c, d); - if ((vmh->vmh_cpuids[i].c & c & VMM_CPUIDECX_MASK) != - (vmh->vmh_cpuids[i].c & VMM_CPUIDECX_MASK)) { - log_debug("%s: incompatible cpu features " - "code: 0x%x leaf: 0x%x reg: c", __func__, - code, leaf); - return (-1); - } - if ((vmh->vmh_cpuids[i].d & d & VMM_CPUIDEDX_MASK) != - (vmh->vmh_cpuids[i].d & VMM_CPUIDEDX_MASK)) { - log_debug("%s: incompatible cpu features " - "code: 0x%x leaf: 0x%x reg: d", __func__, - code, leaf); - return (-1); - } - break; - - case 0x07: - CPUID_LEAF(code, leaf, a, b, c, d); - if ((vmh->vmh_cpuids[i].b & b & VMM_SEFF0EBX_MASK) != - (vmh->vmh_cpuids[i].b & VMM_SEFF0EBX_MASK)) { - log_debug("%s: incompatible cpu features " - "code: 0x%x leaf: 0x%x reg: c", __func__, - code, leaf); - return (-1); - } - if ((vmh->vmh_cpuids[i].c & c & VMM_SEFF0ECX_MASK) != - (vmh->vmh_cpuids[i].c & VMM_SEFF0ECX_MASK)) { - log_debug("%s: incompatible cpu features " - "code: 0x%x leaf: 0x%x reg: d", __func__, - code, leaf); - return (-1); - } - break; - - case 0x0d: - CPUID_LEAF(code, leaf, a, b, c, d); - if (vmh->vmh_cpuids[i].b > b) { - log_debug("%s: incompatible cpu: insufficient " - "max save area for enabled XCR0 features", - __func__); - return (-1); - } - if (vmh->vmh_cpuids[i].c > c) { - log_debug("%s: incompatible cpu: insufficient " - "max save area for supported XCR0 features", - __func__); - return (-1); - } - break; - - case 0x80000001: - CPUID_LEAF(code, leaf, a, b, c, d); - if ((vmh->vmh_cpuids[i].a & a) != - vmh->vmh_cpuids[i].a) { - log_debug("%s: incompatible cpu features " - "code: 0x%x leaf: 0x%x reg: a", __func__, - code, leaf); - return (-1); - } - if ((vmh->vmh_cpuids[i].c & c) != - vmh->vmh_cpuids[i].c) { - log_debug("%s: incompatible cpu features " - "code: 0x%x leaf: 0x%x reg: c", __func__, - code, leaf); - return (-1); - } - if ((vmh->vmh_cpuids[i].d & d) != - vmh->vmh_cpuids[i].d) { - log_debug("%s: incompatible cpu features " - "code: 0x%x leaf: 0x%x reg: d", __func__, - code, leaf); - return (-1); - } - break; - - default: - log_debug("%s: unknown code 0x%x", __func__, code); - return (-1); - } - } - - return (0); -}