summaryrefslogtreecommitdiff
path: root/usr.sbin/vmd
diff options
context:
space:
mode:
authorpd <pd@cvs.openbsd.org>2019-07-17 05:51:08 +0000
committerpd <pd@cvs.openbsd.org>2019-07-17 05:51:08 +0000
commitb0fbf84b4b14aca5456de8ec175f740b26aa6ad4 (patch)
tree8817f23d489071b6014567888f2db3653e2cbd2e /usr.sbin/vmd
parenteb035a8d91662acbd8d08a8c195ea92714cf46bc (diff)
vmm/vmd: Fix migration with pvclock
Implement VMM_IOC_READVMPARAMS and VMM_IOC_WRITEVMPARAMS ioctls to read and write pvclock state. reads ok mlarkin@
Diffstat (limited to 'usr.sbin/vmd')
-rw-r--r--usr.sbin/vmd/vm.c44
-rw-r--r--usr.sbin/vmd/vmd.h4
2 files changed, 45 insertions, 3 deletions
diff --git a/usr.sbin/vmd/vm.c b/usr.sbin/vmd/vm.c
index 16683af31cb..48776a74971 100644
--- a/usr.sbin/vmd/vm.c
+++ b/usr.sbin/vmd/vm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vm.c,v 1.50 2019/06/28 13:32:51 deraadt Exp $ */
+/* $OpenBSD: vm.c,v 1.51 2019/07/17 05:51:07 pd Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@@ -90,6 +90,7 @@ int dump_vmr(int , struct vm_mem_range *);
int dump_mem(int, struct vm_create_params *);
void restore_vmr(int, struct vm_mem_range *);
void restore_mem(int, struct vm_create_params *);
+int restore_vm_params(int, struct vm_create_params *);
void pause_vm(struct vm_create_params *);
void unpause_vm(struct vm_create_params *);
@@ -366,6 +367,8 @@ start_vm(struct vmd_vm *vm, int fd)
vm->vm_disks, vm->vm_cdrom);
mc146818_start();
restore_mem(vm->vm_receive_fd, vcp);
+ if (restore_vm_params(vm->vm_receive_fd, vcp))
+ fatal("restore vm params failed");
}
if (vmm_pipe(vm, fd, vm_dispatch_vmm) == -1)
@@ -503,6 +506,7 @@ int
send_vm(int fd, struct vm_create_params *vcp)
{
struct vm_rwregs_params vrp;
+ struct vm_rwvmparams_params vpp;
struct vmop_create_params *vmc;
struct vm_terminate_params vtp;
unsigned int flags = 0;
@@ -530,6 +534,8 @@ send_vm(int fd, struct vm_create_params *vcp)
vmc->vmc_flags = flags;
vrp.vrwp_vm_id = vcp->vcp_id;
vrp.vrwp_mask = VM_RWREGS_ALL;
+ vpp.vpp_mask = VM_RWVMPARAMS_ALL;
+ vpp.vpp_vm_id = vcp->vcp_id;
sz = atomicio(vwrite, fd, vmc,sizeof(struct vmop_create_params));
if (sz != sizeof(struct vmop_create_params)) {
@@ -570,6 +576,22 @@ send_vm(int fd, struct vm_create_params *vcp)
if ((ret = dump_mem(fd, vcp)))
goto err;
+ for (i = 0; i < vcp->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 = vcp->vcp_id;
if (ioctl(env->vmd_fd, VMM_IOC_TERM, &vtp) == -1) {
log_warnx("%s: term IOC error: %d, %d", __func__,
@@ -638,6 +660,26 @@ dump_mem(int fd, struct vm_create_params *vcp)
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)
{
diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h
index 7e40b38f51d..2d848e5d37e 100644
--- a/usr.sbin/vmd/vmd.h
+++ b/usr.sbin/vmd/vmd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmd.h,v 1.94 2019/05/11 23:07:46 jasper Exp $ */
+/* $OpenBSD: vmd.h,v 1.95 2019/07/17 05:51:07 pd Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@@ -215,7 +215,7 @@ struct vm_dump_header {
#define VM_DUMP_SIGNATURE VMM_HV_SIGNATURE
uint8_t vmh_pad[3];
uint8_t vmh_version;
-#define VM_DUMP_VERSION 6
+#define VM_DUMP_VERSION 7
struct vm_dump_header_cpuid
vmh_cpuids[VM_DUMP_HEADER_CPUID_COUNT];
} __packed;