Index: sys/amd64/include/vmm.h =================================================================== --- sys/amd64/include/vmm.h (revision 249256) +++ sys/amd64/include/vmm.h (working copy) @@ -87,7 +87,7 @@ extern struct vmm_ops vmm_ops_intel; extern struct vmm_ops vmm_ops_amd; -struct vm *vm_create(const char *name); +int vm_create(const char *name, struct vm **retvm); void vm_destroy(struct vm *vm); const char *vm_name(struct vm *vm); int vm_malloc(struct vm *vm, vm_paddr_t gpa, size_t len); Index: sys/amd64/vmm/vmm.c =================================================================== --- sys/amd64/vmm/vmm.c (revision 249256) +++ sys/amd64/vmm/vmm.c (working copy) @@ -103,6 +103,8 @@ cpuset_t active_cpus; }; +static int vmm_initialized; + static struct vmm_ops *ops; #define VMM_INIT() (ops != NULL ? (*ops->init)() : 0) #define VMM_CLEANUP() (ops != NULL ? (*ops->cleanup)() : 0) @@ -213,6 +215,8 @@ vmmdev_init(); iommu_init(); error = vmm_init(); + if (error == 0) + vmm_initialized = 1; break; case MOD_UNLOAD: error = vmmdev_cleanup(); @@ -221,6 +225,7 @@ vmm_ipi_cleanup(); error = VMM_CLEANUP(); } + vmm_initialized = 0; break; default: error = 0; @@ -249,8 +254,8 @@ SYSCTL_NODE(_hw, OID_AUTO, vmm, CTLFLAG_RW, NULL, NULL); -struct vm * -vm_create(const char *name) +int +vm_create(const char *name, struct vm **retvm) { int i; struct vm *vm; @@ -258,8 +263,15 @@ const int BSP = 0; + /* + * If vmm.ko could not be successfully initialized then don't attempt + * to create the virtual machine. + */ + if (!vmm_initialized) + return (ENXIO); + if (name == NULL || strlen(name) >= VM_MAX_NAMELEN) - return (NULL); + return (EINVAL); vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO); strcpy(vm->name, name); @@ -274,7 +286,8 @@ vm->iommu = iommu_create_domain(maxaddr); vm_activate_cpu(vm, BSP); - return (vm); + *retvm = vm; + return (0); } static void Index: sys/amd64/vmm/vmm_dev.c =================================================================== --- sys/amd64/vmm/vmm_dev.c (revision 249256) +++ sys/amd64/vmm/vmm_dev.c (working copy) @@ -475,9 +475,9 @@ if (sc != NULL) return (EEXIST); - vm = vm_create(buf); - if (vm == NULL) - return (EINVAL); + error = vm_create(buf, &vm); + if (error != 0) + return (error); sc = malloc(sizeof(struct vmmdev_softc), M_VMMDEV, M_WAITOK | M_ZERO); sc->vm = vm;