summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-11-21 11:08:59 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-11-21 11:08:59 +0000
commit603c2bda9acbac44a0b2a996db68c6de9efd1a2c (patch)
tree2fd70eaf2cc90b8c13ef0e9040d0d8aeb2301f08 /sys/arch
parent988d2f86cb757bda87c106d80cd325140abab628 (diff)
Do not create a VM if vmm mode hasn't been enable.
Currently one MUST do "vmmctl -e" before creating a vm with "vmm -S ...". Lately this could be done automagically by vmd(8) but the kernel should not allow things that wont fly. While here, disable vmm mode in error path if at least one of the CPUs failed to enable it. ok mlarkin@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/amd64/amd64/vmm.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c
index 15991cdf056..d3d457cc15d 100644
--- a/sys/arch/amd64/amd64/vmm.c
+++ b/sys/arch/amd64/amd64/vmm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmm.c,v 1.4 2015/11/21 11:03:14 mpi Exp $ */
+/* $OpenBSD: vmm.c,v 1.5 2015/11/21 11:08:58 mpi Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
*
@@ -309,6 +309,8 @@ vmmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
switch(cmd) {
case VMM_IOC_START:
ret = vmm_start();
+ if (ret)
+ vmm_stop();
break;
case VMM_IOC_STOP:
ret = vmm_stop();
@@ -600,17 +602,14 @@ vmm_start(void)
int
vmm_stop(void)
{
- struct cpu_info *self;
+ struct cpu_info *self = curcpu();
int ret = 0;
#ifdef MULTIPROCESSOR
struct cpu_info *ci;
CPU_INFO_ITERATOR cii;
int i;
-#endif /* MULTIPROCESSOR */
- self = curcpu();
-#ifdef MULTIPROCESSOR
/* Stop VMM on other CPUs */
x86_broadcast_ipi(X86_IPI_STOP_VMM);
@@ -759,6 +758,9 @@ vm_create(struct vm_create_params *vcp, struct proc *p)
struct vm *vm;
struct vcpu *vcpu;
+ if (!(curcpu()->ci_flags & CPUF_VMM))
+ return (EINVAL);
+
vm = pool_get(&vm_pool, PR_WAITOK | PR_ZERO);
SLIST_INIT(&vm->vm_vcpu_list);
rw_init(&vm->vm_vcpu_lock, "vcpulock");
@@ -771,7 +773,7 @@ vm_create(struct vm_create_params *vcp, struct proc *p)
printf("failed to init arch-specific features for vm 0x%p\n",
vm);
vm_teardown(vm);
- return ENOMEM;
+ return (ENOMEM);
}
rw_enter_write(&vmm_softc->vm_lock);