The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=02f3565d51a70085d8ebf9fa79e811d2ac8ec62a

commit 02f3565d51a70085d8ebf9fa79e811d2ac8ec62a
Author:     Mark Johnston <[email protected]>
AuthorDate: 2026-12-03 22:35:36 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-12-03 22:38:57 +0000

    vmm: Refactor VM reinitialization code a bit
    
    We can avoid the bool parameter to vm_init() by moving a bit of code
    around.  This makes the VM (re)initialization code easier to read.
    
    No functional change intended.
    
    Reviewed by:    bnovkov
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D61043
---
 sys/amd64/vmm/vmm.c | 20 ++++++++------------
 sys/arm64/vmm/vmm.c | 19 +++++++------------
 sys/riscv/vmm/vmm.c | 19 +++++++------------
 3 files changed, 22 insertions(+), 36 deletions(-)

diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
index 7525e2ad7b8f..8c18f5bce5a4 100644
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -313,7 +313,7 @@ vmm_modcleanup(void)
 }
 
 static void
-vm_init(struct vm *vm, bool create)
+vm_init(struct vm *vm)
 {
        vm->cookie = vmmops_init(vm, vmspace_pmap(vm_vmspace(vm)));
        vm->iommu = NULL;
@@ -322,8 +322,6 @@ vm_init(struct vm *vm, bool create)
        vm->vatpic = vatpic_init(vm);
        vm->vatpit = vatpit_init(vm);
        vm->vpmtmr = vpmtmr_init(vm);
-       if (create)
-               vm->vrtc = vrtc_init(vm);
 
        CPU_ZERO(&vm->active_cpus);
        CPU_ZERO(&vm->debug_cpus);
@@ -331,13 +329,6 @@ vm_init(struct vm *vm, bool create)
 
        vm->suspend = 0;
        CPU_ZERO(&vm->suspended_cpus);
-
-       if (!create) {
-               for (int i = 0; i < vm->maxcpus; i++) {
-                       if (vm->vcpu[i] != NULL)
-                               vcpu_init(vm->vcpu[i]);
-               }
-       }
 }
 
 struct vcpu *
@@ -395,7 +386,8 @@ vm_create(const char *name, struct vm **retvm)
        vm->threads = 1;        /* XXX backwards compatibility */
        vm->maxcpus = vm_maxcpu;
 
-       vm_init(vm, true);
+       vm->vrtc = vrtc_init(vm);
+       vm_init(vm);
 
        *retvm = vm;
        return (0);
@@ -453,7 +445,11 @@ void
 vm_reset(struct vm *vm)
 {
        vm_cleanup(vm, false);
-       vm_init(vm, false);
+       vm_init(vm);
+       for (int i = 0; i < vm->maxcpus; i++) {
+               if (vm->vcpu[i] != NULL)
+                       vcpu_init(vm->vcpu[i]);
+       }
 }
 
 int
diff --git a/sys/arm64/vmm/vmm.c b/sys/arm64/vmm/vmm.c
index 4491aeb83b47..73f437775aaa 100644
--- a/sys/arm64/vmm/vmm.c
+++ b/sys/arm64/vmm/vmm.c
@@ -261,10 +261,8 @@ vmm_modcleanup(void)
 }
 
 static void
-vm_init(struct vm *vm, bool create)
+vm_init(struct vm *vm)
 {
-       int i;
-
        vm->cookie = vmmops_init(vm, vmspace_pmap(vm_vmspace(vm)));
        MPASS(vm->cookie != NULL);
 
@@ -276,13 +274,6 @@ vm_init(struct vm *vm, bool create)
 
        memset(vm->mmio_region, 0, sizeof(vm->mmio_region));
        memset(vm->special_reg, 0, sizeof(vm->special_reg));
-
-       if (!create) {
-               for (i = 0; i < vm->maxcpus; i++) {
-                       if (vm->vcpu[i] != NULL)
-                               vcpu_init(vm->vcpu[i]);
-               }
-       }
 }
 
 struct vcpu *
@@ -345,7 +336,7 @@ vm_create(const char *name, struct vm **retvm)
        vm->vcpu = malloc(sizeof(*vm->vcpu) * vm->maxcpus, M_VMM,
            M_WAITOK | M_ZERO);
 
-       vm_init(vm, true);
+       vm_init(vm);
 
        *retvm = vm;
        return (0);
@@ -399,7 +390,11 @@ void
 vm_reset(struct vm *vm)
 {
        vm_cleanup(vm, false);
-       vm_init(vm, false);
+       vm_init(vm);
+       for (int i = 0; i < vm->maxcpus; i++) {
+               if (vm->vcpu[i] != NULL)
+                       vcpu_init(vm->vcpu[i]);
+       }
 }
 
 int
diff --git a/sys/riscv/vmm/vmm.c b/sys/riscv/vmm/vmm.c
index 1546bde87b41..6217a83621a5 100644
--- a/sys/riscv/vmm/vmm.c
+++ b/sys/riscv/vmm/vmm.c
@@ -147,10 +147,8 @@ vmm_modcleanup(void)
 }
 
 static void
-vm_init(struct vm *vm, bool create)
+vm_init(struct vm *vm)
 {
-       int i;
-
        vm->cookie = vmmops_init(vm, vmspace_pmap(vm_vmspace(vm)));
        MPASS(vm->cookie != NULL);
 
@@ -161,13 +159,6 @@ vm_init(struct vm *vm, bool create)
        CPU_ZERO(&vm->suspended_cpus);
 
        memset(vm->mmio_region, 0, sizeof(vm->mmio_region));
-
-       if (!create) {
-               for (i = 0; i < vm->maxcpus; i++) {
-                       if (vm->vcpu[i] != NULL)
-                               vcpu_init(vm->vcpu[i]);
-               }
-       }
 }
 
 struct vcpu *
@@ -224,7 +215,7 @@ vm_create(const char *name, struct vm **retvm)
        vm->vcpu = malloc(sizeof(*vm->vcpu) * vm->maxcpus, M_VMM,
            M_WAITOK | M_ZERO);
 
-       vm_init(vm, true);
+       vm_init(vm);
 
        *retvm = vm;
        return (0);
@@ -269,7 +260,11 @@ void
 vm_reset(struct vm *vm)
 {
        vm_cleanup(vm, false);
-       vm_init(vm, false);
+       vm_init(vm);
+       for (int i = 0; i < vm->maxcpus; i++) {
+               if (vm->vcpu[i] != NULL)
+                       vcpu_init(vm->vcpu[i]);
+       }
 }
 
 int

Reply via email to