diff options
author | pd <pd@cvs.openbsd.org> | 2019-07-17 05:51:08 +0000 |
---|---|---|
committer | pd <pd@cvs.openbsd.org> | 2019-07-17 05:51:08 +0000 |
commit | b0fbf84b4b14aca5456de8ec175f740b26aa6ad4 (patch) | |
tree | 8817f23d489071b6014567888f2db3653e2cbd2e /sys/arch/amd64 | |
parent | eb035a8d91662acbd8d08a8c195ea92714cf46bc (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 'sys/arch/amd64')
-rw-r--r-- | sys/arch/amd64/amd64/vmm.c | 72 | ||||
-rw-r--r-- | sys/arch/amd64/include/vmmvar.h | 20 |
2 files changed, 90 insertions, 2 deletions
diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index 3c5e45e6409..4dadb04bbf6 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.248 2019/07/08 19:57:11 mlarkin Exp $ */ +/* $OpenBSD: vmm.c,v 1.249 2019/07/17 05:51:07 pd Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> * @@ -124,6 +124,7 @@ int vm_get_info(struct vm_info_params *); int vm_resetcpu(struct vm_resetcpu_params *); int vm_intr_pending(struct vm_intr_params *); int vm_rwregs(struct vm_rwregs_params *, int); +int vm_rwvmparams(struct vm_rwvmparams_params *, int); int vm_find(uint32_t, struct vm **); int vcpu_readregs_vmx(struct vcpu *, uint64_t, struct vcpu_reg_state *); int vcpu_readregs_svm(struct vcpu *, uint64_t, struct vcpu_reg_state *); @@ -485,6 +486,13 @@ vmmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) case VMM_IOC_WRITEREGS: ret = vm_rwregs((struct vm_rwregs_params *)data, 1); break; + case VMM_IOC_READVMPARAMS: + ret = vm_rwvmparams((struct vm_rwvmparams_params *)data, 0); + break; + case VMM_IOC_WRITEVMPARAMS: + ret = vm_rwvmparams((struct vm_rwvmparams_params *)data, 1); + break; + default: DPRINTF("%s: unknown ioctl code 0x%lx\n", __func__, cmd); ret = ENOTTY; @@ -516,6 +524,8 @@ pledge_ioctl_vmm(struct proc *p, long com) case VMM_IOC_INTR: case VMM_IOC_READREGS: case VMM_IOC_WRITEREGS: + case VMM_IOC_READVMPARAMS: + case VMM_IOC_WRITEVMPARAMS: return (0); } @@ -667,6 +677,66 @@ vm_intr_pending(struct vm_intr_params *vip) } /* + * vm_rwvmparams + * + * IOCTL handler to read/write the current vmm params like pvclock gpa, pvclock + * version, etc. + * + * Parameters: + * vrwp: Describes the VM and VCPU to get/set the params from + * dir: 0 for reading, 1 for writing + * + * Return values: + * 0: if successful + * ENOENT: if the VM/VCPU defined by 'vpp' cannot be found + * EINVAL: if an error occured reading the registers of the guest + */ +int +vm_rwvmparams(struct vm_rwvmparams_params *vpp, int dir) { + struct vm *vm; + struct vcpu *vcpu; + int error; + + /* Find the desired VM */ + rw_enter_read(&vmm_softc->vm_lock); + error = vm_find(vpp->vpp_vm_id, &vm); + + /* Not found? exit. */ + if (error != 0) { + rw_exit_read(&vmm_softc->vm_lock); + return (error); + } + + rw_enter_read(&vm->vm_vcpu_lock); + SLIST_FOREACH(vcpu, &vm->vm_vcpu_list, vc_vcpu_link) { + if (vcpu->vc_id == vpp->vpp_vcpu_id) + break; + } + rw_exit_read(&vm->vm_vcpu_lock); + rw_exit_read(&vmm_softc->vm_lock); + + if (vcpu == NULL) + return (ENOENT); + + if (dir == 0) { + if (vpp->vpp_mask & VM_RWVMPARAMS_PVCLOCK_VERSION) + vpp->vpp_pvclock_version = vcpu->vc_pvclock_version; + if (vpp->vpp_mask & VM_RWVMPARAMS_PVCLOCK_SYSTEM_GPA) + vpp->vpp_pvclock_system_gpa = \ + vcpu->vc_pvclock_system_gpa; + return (0); + } + + if (vpp->vpp_mask & VM_RWVMPARAMS_PVCLOCK_VERSION) + vcpu->vc_pvclock_version = vpp->vpp_pvclock_version; + if (vpp->vpp_mask & VM_RWVMPARAMS_PVCLOCK_SYSTEM_GPA) { + vmm_init_pvclock(vcpu, vpp->vpp_pvclock_system_gpa); + } + return (0); + +} + +/* * vm_readregs * * IOCTL handler to read/write the current register values of a guest VCPU. diff --git a/sys/arch/amd64/include/vmmvar.h b/sys/arch/amd64/include/vmmvar.h index e4df09f6f92..78c477291f2 100644 --- a/sys/arch/amd64/include/vmmvar.h +++ b/sys/arch/amd64/include/vmmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmmvar.h,v 1.66 2019/05/17 19:07:16 guenther Exp $ */ +/* $OpenBSD: vmmvar.h,v 1.67 2019/07/17 05:51:07 pd Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> * @@ -525,6 +525,20 @@ struct vm_intr_params { uint16_t vip_intr; }; +#define VM_RWVMPARAMS_PVCLOCK_SYSTEM_GPA 0x1 /* read/write pvclock gpa */ +#define VM_RWVMPARAMS_PVCLOCK_VERSION 0x2 /* read/write pvclock version */ +#define VM_RWVMPARAMS_ALL (VM_RWVMPARAMS_PVCLOCK_SYSTEM_GPA | \ + VM_RWVMPARAMS_PVCLOCK_VERSION) + +struct vm_rwvmparams_params { + /* Input parameters to VMM_IOC_READVMPARAMS/VMM_IOC_WRITEVMPARAMS */ + uint32_t vpp_vm_id; + uint32_t vpp_vcpu_id; + uint32_t vpp_mask; + paddr_t vpp_pvclock_system_gpa; + uint32_t vpp_pvclock_version; +}; + #define VM_RWREGS_GPRS 0x1 /* read/write GPRs */ #define VM_RWREGS_SREGS 0x2 /* read/write segment registers */ #define VM_RWREGS_CRS 0x4 /* read/write CRs */ @@ -553,6 +567,10 @@ struct vm_rwregs_params { #define VMM_IOC_INTR _IOW('V', 6, struct vm_intr_params) /* Intr pending */ #define VMM_IOC_READREGS _IOWR('V', 7, struct vm_rwregs_params) /* Get regs */ #define VMM_IOC_WRITEREGS _IOW('V', 8, struct vm_rwregs_params) /* Set regs */ +/* Get VM params */ +#define VMM_IOC_READVMPARAMS _IOWR('V', 9, struct vm_rwvmparams_params) +/* Set VM params */ +#define VMM_IOC_WRITEVMPARAMS _IOW('V', 10, struct vm_rwvmparams_params) /* CPUID masks */ |