Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Apr 2013 01:16:53 +0000 (UTC)
From:      Neel Natu <neel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r249396 - in head/sys/amd64: include vmm
Message-ID:  <201304120116.r3C1GrOj091632@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: neel
Date: Fri Apr 12 01:16:52 2013
New Revision: 249396
URL: http://svnweb.freebsd.org/changeset/base/249396

Log:
  If vmm.ko could not be initialized correctly then prevent the creation of
  virtual machines subsequently.
  
  Submitted by:	Chris Torek

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/vmm.c
  head/sys/amd64/vmm/vmm_dev.c

Modified: head/sys/amd64/include/vmm.h
==============================================================================
--- head/sys/amd64/include/vmm.h	Fri Apr 12 00:34:19 2013	(r249395)
+++ head/sys/amd64/include/vmm.h	Fri Apr 12 01:16:52 2013	(r249396)
@@ -87,7 +87,7 @@ struct vmm_ops {
 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);

Modified: head/sys/amd64/vmm/vmm.c
==============================================================================
--- head/sys/amd64/vmm/vmm.c	Fri Apr 12 00:34:19 2013	(r249395)
+++ head/sys/amd64/vmm/vmm.c	Fri Apr 12 01:16:52 2013	(r249396)
@@ -103,6 +103,8 @@ struct vm {
 	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 @@ vmm_handler(module_t mod, int what, void
 		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_handler(module_t mod, int what, void
 			vmm_ipi_cleanup();
 			error = VMM_CLEANUP();
 		}
+		vmm_initialized = 0;
 		break;
 	default:
 		error = 0;
@@ -249,8 +254,8 @@ MODULE_VERSION(vmm, 1);
 
 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 @@ vm_create(const char *name)
 
 	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_create(const char *name)
 	vm->iommu = iommu_create_domain(maxaddr);
 	vm_activate_cpu(vm, BSP);
 
-	return (vm);
+	*retvm = vm;
+	return (0);
 }
 
 static void

Modified: head/sys/amd64/vmm/vmm_dev.c
==============================================================================
--- head/sys/amd64/vmm/vmm_dev.c	Fri Apr 12 00:34:19 2013	(r249395)
+++ head/sys/amd64/vmm/vmm_dev.c	Fri Apr 12 01:16:52 2013	(r249396)
@@ -475,9 +475,9 @@ sysctl_vmm_create(SYSCTL_HANDLER_ARGS)
 	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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201304120116.r3C1GrOj091632>