[PATCH v9 4/5] qemu: Add command-line to generate SGX EPC memory backend

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

 



From: Lin Yang <lin.a.yang@xxxxxxxxx>

According to the result parsing from xml, add the argument of
SGX EPC memory backend into QEMU command line:

    #qemu-system-x86_64 \
        ...... \
        -object memory-backend-epc,id=mem1,size=64M,prealloc=on \
        -object memory-backend-epc,id=mem2,size=28M \
        -M sgx-epc.0.memdev=mem1,sgx-epc.1.memdev=mem2

Signed-off-by: Lin Yang <lin.a.yang@xxxxxxxxx>
---
 src/qemu/qemu_alias.c   |  3 ++-
 src/qemu/qemu_command.c | 40 ++++++++++++++++++++++++++++++++++++----
 src/qemu/qemu_domain.c  | 10 +++++++++-
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 5795924754..89afea8778 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -489,7 +489,8 @@ qemuDeviceMemoryGetAliasID(virDomainDef *def,
      * valid */
     if (!oldAlias &&
         mem->model != VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM &&
-        mem->model != VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM)
+        mem->model != VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM &&
+        mem->model != VIR_DOMAIN_MEMORY_MODEL_SGX_EPC)
         return mem->info.addr.dimm.slot;
 
     for (i = 0; i < def->nmems; i++) {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 36281a69e2..ebb3aa1023 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3555,6 +3555,10 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
         if (systemMemory)
             disableCanonicalPath = true;
 
+    } else if (mem->model == VIR_DOMAIN_MEMORY_MODEL_SGX_EPC) {
+        backendType = "memory-backend-epc";
+        if (!priv->memPrealloc)
+            prealloc = true;
     } else {
         backendType = "memory-backend-ram";
     }
@@ -7838,6 +7842,8 @@ qemuBuildMemoryDeviceCommandLine(virCommand *cmd,
                                  qemuDomainObjPrivate *priv)
 {
     size_t i;
+    g_auto(virBuffer) epcBuf = VIR_BUFFER_INITIALIZER;
+    int epcNum = 0;
 
     /* memory hotplug requires NUMA to be enabled - we already checked
      * that memory devices are present only when NUMA is */
@@ -7847,11 +7853,37 @@ qemuBuildMemoryDeviceCommandLine(virCommand *cmd,
         if (qemuBuildMemoryDimmBackendStr(cmd, def->mems[i], def, cfg, priv) < 0)
             return -1;
 
-        if (!(props = qemuBuildMemoryDeviceProps(def, def->mems[i])))
-            return -1;
+        switch ((virDomainMemoryModel) def->mems[i]->model) {
+        case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
+        case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+        case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
+        case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
+            if (!(props = qemuBuildMemoryDeviceProps(def, def->mems[i])))
+                return -1;
 
-        if (qemuBuildDeviceCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0)
-            return -1;
+            if (qemuBuildDeviceCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0)
+                return -1;
+
+            break;
+
+        case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+            if (virBufferUse(&epcBuf) > 0)
+                virBufferAddChar(&epcBuf, ',');
+
+            virBufferAsprintf(&epcBuf, "sgx-epc.%d.memdev=%s", epcNum++,
+                              g_strdup_printf("mem%s", def->mems[i]->info.alias));
+
+            break;
+
+        case VIR_DOMAIN_MEMORY_MODEL_NONE:
+        case VIR_DOMAIN_MEMORY_MODEL_LAST:
+            break;
+        }
+    }
+
+    if (virBufferUse(&epcBuf) > 0) {
+        virCommandAddArg(cmd, "-M");
+        virCommandAddArgBuffer(cmd, &epcBuf);
     }
 
     return 0;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f156d073e5..2db479ee7f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8895,13 +8895,21 @@ int
 qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                    const virDomainMemoryDef *mem)
 {
-    unsigned int nmems = def->nmems;
+    unsigned int nmems = 0;
     unsigned long long hotplugSpace;
     unsigned long long hotplugMemory = 0;
     size_t i;
 
     hotplugSpace = def->mem.max_memory - virDomainDefGetMemoryInitial(def);
 
+    for (i = 0; i < def->nmems; i++) {
+        if (def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_DIMM ||
+            def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM ||
+            def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM ||
+            def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM)
+            nmems++;
+    }
+
     if (mem) {
         nmems++;
         hotplugMemory = mem->size;
-- 
2.17.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux