Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Jun 2026 09:10:11 +0200
From:      Mario Marietto <marietto2008@gmail.com>
To:        =?UTF-8?Q?Corvin_K=C3=B6hne?= <corvink@freebsd.org>
Cc:        FreeBSD virtualization <freebsd-virtualization@freebsd.org>
Subject:   =?UTF-8?Q?Re=3A_=2A=2A=5BHelp=5D_bhyve=3A_bootrom=5Falloc=3A_vm=5Fmmap=5Fmapseg=3A_I?= =?UTF-8?Q?nvalid_argument_=E2=80=94_NVIDIA_passthrough_with_Corvin=27s_branch_?= =?UTF-8?Q?on_FreeBSD_15=2E0=2A=2A?=
Message-ID:  <CA%2B1FSihAcrz-9vV8rZjF%2BzoLRSACV3FPdYMcPe-61uW-KSf1kg@mail.gmail.com>
In-Reply-To: <bc674b3f2815204306480f88f71b48ff886c8a56.camel@FreeBSD.org>
References:  <CA%2B1FSiiGdW4JCi=XA68Wtr1pDbMNAwTpwq9P8TixdDGRHSf%2B6g@mail.gmail.com> <bc674b3f2815204306480f88f71b48ff886c8a56.camel@FreeBSD.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]

[-- Attachment #2 --]
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -755,10 +755,10 @@
 	sx_assert(&vm->mem.mem_segs_lock, SX_LOCKED);

 	for (i = 0; i < VM_MAX_MEMMAPS; i++) {
-		if (!vm_memseg_sysmem(vm, i))
+		mm = &vm->mem.mem_maps[i];
+		if (!vm_memseg_sysmem(vm, mm->segid))
 			continue;

-		mm = &vm->mem.mem_maps[i];
 		KASSERT((mm->flags & VM_MEMMAP_F_IOMMU) == 0,
 		    ("iommu map found invalid memmap %#lx/%#lx/%#x",
 		    mm->gpa, mm->len, mm->flags));
@@ -803,10 +803,10 @@
 	sx_assert(&vm->mem.mem_segs_lock, SX_LOCKED);

 	for (i = 0; i < VM_MAX_MEMMAPS; i++) {
-		if (!vm_memseg_sysmem(vm, i))
+		mm = &vm->mem.mem_maps[i];
+		if (!vm_memseg_sysmem(vm, mm->segid))
 			continue;

-		mm = &vm->mem.mem_maps[i];
 		if ((mm->flags & VM_MEMMAP_F_IOMMU) == 0)
 			continue;
 		mm->flags &= ~VM_MEMMAP_F_IOMMU;

[-- Attachment #3 --]
--- a/sys/dev/vmm/vmm_dev.c
+++ b/sys/dev/vmm/vmm_dev.c
@@ -14,6 +14,7 @@
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/mman.h>
+#include <sys/priv.h>
 #include <sys/proc.h>
 #include <sys/queue.h>
 #include <sys/sx.h>
@@ -74,14 +75,11 @@
 static void devmem_destroy(void *arg);
 static int devmem_create_cdev(struct vmmdev_softc *sc, int id, char *devmem);

+/* VMM_PRIV_CHECK_FIX_APPLIED */
 static int
-vmm_priv_check(struct ucred *ucred)
+vmm_priv_check(struct thread *td)
 {
-	if (jailed(ucred) &&
-	    !(ucred->cr_prison->pr_allow & pr_allow_flag))
-		return (EPERM);
-
-	return (0);
+	return (priv_check(td, PRIV_DRIVER));
 }

 static int
@@ -334,7 +332,7 @@
 	 * A jail without vmm access shouldn't be able to access vmm device
 	 * files at all, but check here just to be thorough.
 	 */
-	error = vmm_priv_check(td->td_ucred);
+	error = vmm_priv_check(td);
 	if (error != 0)
 		return (error);

@@ -813,7 +811,7 @@
 	char *buf;
 	int error, buflen;

-	error = vmm_priv_check(req->td->td_ucred);
+	error = vmm_priv_check(req->td);
 	if (error)
 		return (error);

@@ -902,7 +900,7 @@
 	char *buf;
 	int error, buflen;

-	error = vmm_priv_check(req->td->td_ucred);
+	error = vmm_priv_check(req->td);
 	if (error != 0)
 		return (error);

@@ -925,7 +923,7 @@
 {
 	int error;

-	error = vmm_priv_check(td->td_ucred);
+	error = vmm_priv_check(td);
 	if (error != 0)
 		return (error);

[-- Attachment #4 --]
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -390,6 +390,8 @@
 	 * This is the usual case for the SYSMEM segment created by userspace
 	 * loaders like bhyveload(8).
 	 */
+	if (segid != VM_SYSMEM) /* VM_ALLOC_MEMSEG_FIX_APPLIED */
+		goto alloc_devmem;
 	error = vm_get_memseg(ctx, segid, &memseg.len, memseg.name,
 	    sizeof(memseg.name));
 	if (error)
@@ -404,6 +406,7 @@
 		}
 	}

+alloc_devmem:
 	bzero(&memseg, sizeof(struct vm_memseg));
 	memseg.segid = segid;
 	memseg.len = len;
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2B1FSihAcrz-9vV8rZjF%2BzoLRSACV3FPdYMcPe-61uW-KSf1kg>