Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Feb 2025 16:27:37 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 23a28fe7776f - main - libvmmapi: Fix auto-loading of vmm.ko
Message-ID:  <202502061627.516GRb5t095521@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=23a28fe7776f6d76643a6ac16758d114dfbbeec2

commit 23a28fe7776f6d76643a6ac16758d114dfbbeec2
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-02-06 14:37:46 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-02-06 16:25:42 +0000

    libvmmapi: Fix auto-loading of vmm.ko
    
    - We should autoload vmm.ko when creating a VM with vm_openf(), to
      preserve behaviour prior to commit 99127fd10362.
    - kldload(2) returns a non-zero value upon success, so the existing code
      was wrong.
    
    Reviewed by:    jhb
    Reported by:    olivier
    Fixes:          99127fd10362 ("libvmmapi: Use the vmmctl device file to create and destroy VMs")
    Differential Revision:  https://reviews.freebsd.org/D48797
---
 lib/libvmmapi/vmmapi.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index 5042a1f3914e..a1a5d56ff8a2 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -90,6 +90,14 @@ vm_device_open(const char *name)
 	return (open(devpath, O_RDWR));
 }
 
+static int
+vm_ctl_open(void)
+{
+	if (modfind("vmm") < 0)
+		(void)kldload("vmm");
+	return (open("/dev/vmmctl", O_RDWR, 0));
+}
+
 static int
 vm_ctl_create(const char *name, int ctlfd)
 {
@@ -108,16 +116,10 @@ vm_create(const char *name)
 {
 	int error, fd;
 
-	/* Try to load vmm(4) module before creating a guest. */
-	if (modfind("vmm") < 0) {
-		error = kldload("vmm");
-		if (error != 0)
-			return (-1);
-	}
-
-	fd = open("/dev/vmmctl", O_RDWR, 0);
+	fd = vm_ctl_open();
 	if (fd < 0)
-		return (fd);
+		return (-1);
+
 	error = vm_ctl_create(name, fd);
 	if (error != 0) {
 		error = errno;
@@ -153,7 +155,7 @@ vm_openf(const char *name, int flags)
 	strcpy(vm->name, name);
 	memset(vm->memsegs, 0, sizeof(vm->memsegs));
 
-	if ((vm->ctlfd = open("/dev/vmmctl", O_RDWR, 0)) < 0)
+	if ((vm->ctlfd = vm_ctl_open()) < 0)
 		goto err;
 
 	vm->fd = vm_device_open(vm->name);



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