[PATCH v7 2/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
---
 src/qemu/qemu_alias.c   |  3 ++-
 src/qemu/qemu_command.c | 38 ++++++++++++++++++++++++++++++++++----
 src/qemu/qemu_domain.c  |  9 ++++++++-
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 5990fc5f87..53eb30b81f 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -476,7 +476,8 @@ qemuDeviceMemoryGetAliasID(virDomainDef *def,
     int maxidx = 0;
 
     /* virtio-pmem goes onto PCI bus and thus DIMM address is not valid */
-    if (!oldAlias && mem->model != VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM)
+    if (!oldAlias && mem->model != VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM &&
+        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 24572d03d7..11bce51e82 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3117,6 +3117,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";
     }
@@ -7565,6 +7569,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 */
@@ -7578,12 +7584,36 @@ qemuBuildMemoryDeviceCommandLine(virCommand *cmd,
         virCommandAddArg(cmd, "-object");
         virCommandAddArgBuffer(cmd, &buf);
 
-        if (!(dimmStr = qemuBuildMemoryDeviceStr(def, def->mems[i], priv->qemuCaps)))
-            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:
+            if (!(dimmStr = qemuBuildMemoryDeviceStr(def, def->mems[i], priv->qemuCaps)))
+                return -1;
+
+            virCommandAddArgList(cmd, "-device", dimmStr, NULL);
+
+            VIR_FREE(dimmStr);
+            break;
+
+        case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+            if (virBufferUse(&epcBuf) > 0)
+                virBufferAddChar(&epcBuf, ',');
 
-        virCommandAddArgList(cmd, "-device", dimmStr, NULL);
+            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;
+        }
+    }
 
-        VIR_FREE(dimmStr);
+    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 8e151d1fd5..7a535f0002 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9078,13 +9078,20 @@ 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)
+            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