Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/nvmm Mmh, fix nvmm_vcpu_create(), the cpuid is given...



details:   https://anonhg.NetBSD.org/src/rev/d7399209ca2c
branches:  trunk
changeset: 450869:d7399209ca2c
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Apr 27 17:30:38 2019 +0000

description:
Mmh, fix nvmm_vcpu_create(), the cpuid is given, and must not be chosen
from the free map. Looks like I forgot this after all my design rounds.
While here reorder the initialization.

diffstat:

 sys/dev/nvmm/nvmm.c |  41 ++++++++++++++++++++---------------------
 1 files changed, 20 insertions(+), 21 deletions(-)

diffs (91 lines):

diff -r 90b57e0669c4 -r d7399209ca2c sys/dev/nvmm/nvmm.c
--- a/sys/dev/nvmm/nvmm.c       Sat Apr 27 15:45:21 2019 +0000
+++ b/sys/dev/nvmm/nvmm.c       Sat Apr 27 17:30:38 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm.c,v 1.17 2019/04/10 18:49:04 maxv Exp $   */
+/*     $NetBSD: nvmm.c,v 1.18 2019/04/27 17:30:38 maxv Exp $   */
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.17 2019/04/10 18:49:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.18 2019/04/27 17:30:38 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -138,28 +138,27 @@
 /* -------------------------------------------------------------------------- */
 
 static int
-nvmm_vcpu_alloc(struct nvmm_machine *mach, struct nvmm_cpu **ret)
+nvmm_vcpu_alloc(struct nvmm_machine *mach, nvmm_cpuid_t cpuid,
+    struct nvmm_cpu **ret)
 {
        struct nvmm_cpu *vcpu;
-       size_t i;
-
-       for (i = 0; i < NVMM_MAX_VCPUS; i++) {
-               vcpu = &mach->cpus[i];
 
-               mutex_enter(&vcpu->lock);
-               if (vcpu->present) {
-                       mutex_exit(&vcpu->lock);
-                       continue;
-               }
+       if (cpuid >= NVMM_MAX_VCPUS) {
+               return EINVAL;
+       }
+       vcpu = &mach->cpus[cpuid];
 
-               vcpu->present = true;
-               vcpu->cpuid = i;
-               vcpu->state = kmem_zalloc(nvmm_impl->state_size, KM_SLEEP);
-               *ret = vcpu;
-               return 0;
+       mutex_enter(&vcpu->lock);
+       if (vcpu->present) {
+               mutex_exit(&vcpu->lock);
+               return EBUSY;
        }
 
-       return ENOBUFS;
+       vcpu->present = true;
+       vcpu->state = kmem_zalloc(nvmm_impl->state_size, KM_SLEEP);
+       vcpu->hcpu_last = -1;
+       *ret = vcpu;
+       return 0;
 }
 
 static void
@@ -168,7 +167,6 @@
        KASSERT(mutex_owned(&vcpu->lock));
        vcpu->present = false;
        kmem_free(vcpu->state, nvmm_impl->state_size);
-       vcpu->hcpu_last = -1;
 }
 
 int
@@ -375,7 +373,7 @@
        if (error)
                return error;
 
-       error = nvmm_vcpu_alloc(mach, &vcpu);
+       error = nvmm_vcpu_alloc(mach, args->cpuid, &vcpu);
        if (error)
                goto out;
 
@@ -899,9 +897,10 @@
                machines[i].machid = i;
                rw_init(&machines[i].lock);
                for (n = 0; n < NVMM_MAX_VCPUS; n++) {
+                       machines[i].cpus[n].present = false;
+                       machines[i].cpus[n].cpuid = n;
                        mutex_init(&machines[i].cpus[n].lock, MUTEX_DEFAULT,
                            IPL_NONE);
-                       machines[i].cpus[n].hcpu_last = -1;
                }
        }
 



Home | Main Index | Thread Index | Old Index