Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177527140
D61044.1794631687.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D61044.1794631687.diff
View Options
diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -37,6 +37,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/rmlock.h>
#include <sys/rwlock.h>
#include <sys/sched.h>
#include <sys/smp.h>
@@ -372,6 +373,7 @@
strcpy(vm->name, name);
mtx_init(&vm->rendezvous_mtx, "vm rendezvous lock", 0, MTX_DEF);
sx_init(&vm->vcpus_init_lock, "vm vcpus");
+ rms_init(&vm->vm_reinit_lock, "vm reinit");
vm->vcpu = malloc(sizeof(*vm->vcpu) * vm_maxcpu, M_VM, M_WAITOK |
M_ZERO);
diff --git a/sys/arm64/vmm/vmm.c b/sys/arm64/vmm/vmm.c
--- a/sys/arm64/vmm/vmm.c
+++ b/sys/arm64/vmm/vmm.c
@@ -37,6 +37,7 @@
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/queue.h>
+#include <sys/rmlock.h>
#include <sys/rwlock.h>
#include <sys/sched.h>
#include <sys/smp.h>
@@ -323,6 +324,7 @@
strcpy(vm->name, name);
mtx_init(&vm->rendezvous_mtx, "vm rendezvous lock", 0, MTX_DEF);
sx_init(&vm->vcpus_init_lock, "vm vcpus");
+ rms_init(&vm->vm_reinit_lock, "vm reinit");
vm->sockets = 1;
vm->cores = 1; /* XXX backwards compatibility */
diff --git a/sys/dev/vmm/vmm_dev.h b/sys/dev/vmm/vmm_dev.h
--- a/sys/dev/vmm/vmm_dev.h
+++ b/sys/dev/vmm/vmm_dev.h
@@ -39,6 +39,7 @@
* and lock the vCPU for the duration of the ioctl
* - MAYBE_ALLOC_VCPU: if the vcpuid is -1, do nothing, otherwise
* create the vCPU if it does not already exist
+ * - REINIT: acquire the per-VM reinit lock, which blocks all other ioctls
*/
struct vmmdev_ioctl {
unsigned long cmd;
@@ -49,6 +50,7 @@
#define VMMDEV_IOCTL_ALLOC_VCPU 0x10
#define VMMDEV_IOCTL_MAYBE_ALLOC_VCPU 0x20
#define VMMDEV_IOCTL_PPT 0x40
+#define VMMDEV_IOCTL_REINIT 0x80
int flags;
};
diff --git a/sys/dev/vmm/vmm_dev.c b/sys/dev/vmm/vmm_dev.c
--- a/sys/dev/vmm/vmm_dev.c
+++ b/sys/dev/vmm/vmm_dev.c
@@ -21,6 +21,7 @@
#include <sys/proc.h>
#include <sys/queue.h>
#include <sys/resourcevar.h>
+#include <sys/rmlock.h>
#include <sys/smp.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
@@ -407,7 +408,8 @@
VMMDEV_IOCTL(VM_MUNMAP_MEMSEG,
VMMDEV_IOCTL_XLOCK_MEMSEGS | VMMDEV_IOCTL_LOCK_ALL_VCPUS),
VMMDEV_IOCTL(VM_REINIT,
- VMMDEV_IOCTL_XLOCK_MEMSEGS | VMMDEV_IOCTL_LOCK_ALL_VCPUS),
+ VMMDEV_IOCTL_XLOCK_MEMSEGS | VMMDEV_IOCTL_LOCK_ALL_VCPUS |
+ VMMDEV_IOCTL_REINIT),
#ifdef __amd64__
#if defined(COMPAT_FREEBSD12)
@@ -475,6 +477,11 @@
else if ((ioctl->flags & VMMDEV_IOCTL_SLOCK_MEMSEGS) != 0)
vm_slock_memsegs(sc->vm);
+ if ((ioctl->flags & VMMDEV_IOCTL_REINIT) != 0)
+ rms_wlock(&sc->vm->vm_reinit_lock);
+ else
+ rms_rlock(&sc->vm->vm_reinit_lock);
+
vcpu = NULL;
vcpuid = -1;
if ((ioctl->flags & (VMMDEV_IOCTL_LOCK_ONE_VCPU |
@@ -777,6 +784,11 @@
else if ((ioctl->flags & VMMDEV_IOCTL_LOCK_ONE_VCPU) != 0)
vcpu_unlock_one(vcpu);
+ if ((ioctl->flags & VMMDEV_IOCTL_REINIT) != 0)
+ rms_wunlock(&sc->vm->vm_reinit_lock);
+ else
+ rms_runlock(&sc->vm->vm_reinit_lock);
+
/*
* Make sure that no handler returns a kernel-internal
* error value to userspace.
@@ -786,6 +798,10 @@
return (error);
lockfail:
+ if ((ioctl->flags & VMMDEV_IOCTL_REINIT) != 0)
+ rms_wunlock(&sc->vm->vm_reinit_lock);
+ else
+ rms_runlock(&sc->vm->vm_reinit_lock);
if ((ioctl->flags &
(VMMDEV_IOCTL_XLOCK_MEMSEGS | VMMDEV_IOCTL_SLOCK_MEMSEGS)) != 0)
vm_unlock_memsegs(sc->vm);
diff --git a/sys/dev/vmm/vmm_vm.h b/sys/dev/vmm/vmm_vm.h
--- a/sys/dev/vmm/vmm_vm.h
+++ b/sys/dev/vmm/vmm_vm.h
@@ -10,6 +10,9 @@
#ifdef _KERNEL
#include <sys/_cpuset.h>
+#include <sys/_mutex.h>
+#include <sys/_rmlock.h>
+#include <sys/_sx.h>
#include <machine/vmm.h>
@@ -132,6 +135,7 @@
char name[VM_MAX_NAMELEN + 1]; /* (o) virtual machine name */
struct sx vcpus_init_lock; /* (o) */
+ struct rmslock vm_reinit_lock; /* (o) */
bool dying; /* (o) is dying */
int suspend; /* (i) stop VM execution */
diff --git a/sys/riscv/vmm/vmm.c b/sys/riscv/vmm/vmm.c
--- a/sys/riscv/vmm/vmm.c
+++ b/sys/riscv/vmm/vmm.c
@@ -42,6 +42,7 @@
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/queue.h>
+#include <sys/rmlock.h>
#include <sys/rwlock.h>
#include <sys/sched.h>
#include <sys/smp.h>
@@ -206,6 +207,7 @@
strcpy(vm->name, name);
mtx_init(&vm->rendezvous_mtx, "vm rendezvous lock", 0, MTX_DEF);
sx_init(&vm->vcpus_init_lock, "vm vcpus");
+ rms_init(&vm->vm_reinit_lock, "vm reinit");
vm->sockets = 1;
vm->cores = 1; /* XXX backwards compatibility */
@@ -246,6 +248,7 @@
free(vm->vcpu, M_VMM);
sx_destroy(&vm->vcpus_init_lock);
+ rms_destroy(&vm->vm_reinit_lock);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 4:48 AM (22 m, 52 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41703019
Default Alt Text
D61044.1794631687.diff (4 KB)
Attached To
Mode
D61044: vmm: Use an rms lock to synchronize ioctls
Attached
Detach File
Event Timeline