From: Lin Yang <lin.a.yang(a)intel.com>
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 | 8 +++++---
src/qemu/qemu_command.c | 41 +++++++++++++++++++++++++++++++++++++----
src/qemu/qemu_domain.c | 8 +++++++-
3 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 101ab5608f..d935ae6847 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -487,10 +487,12 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
if (mem->model == VIR_DOMAIN_MEMORY_MODEL_DIMM)
prefix = "dimm";
- else
+ else if (mem->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
prefix = "nvdimm";
+ else
+ prefix = "epc";
- if (oldAlias) {
+ if (oldAlias || mem->model == VIR_DOMAIN_MEMORY_MODEL_SGX_EPC) {
for (i = 0; i < def->nmems; i++) {
if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, prefix))
>= maxidx)
maxidx = idx + 1;
@@ -674,7 +676,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
for (i = 0; i < def->nmems; i++) {
- if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0)
+ if (qemuAssignDeviceMemoryAlias(def, def->mems[i], false) < 0)
return -1;
}
if (def->vsock) {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4a1d0c3e9e..dba76d3f78 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3143,6 +3143,14 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
if (qemuBuildMemoryBackendPropsShare(props, memAccess) < 0)
return -1;
+ } else if (mem->model == VIR_DOMAIN_MEMORY_MODEL_SGX_EPC) {
+ backendType = "memory-backend-epc";
+ if (!priv->memPrealloc)
+ prealloc = true;
+ if (virJSONValueObjectAdd(props,
+ "B:prealloc", prealloc,
+ NULL) < 0)
+ return -1;
} else {
backendType = "memory-backend-ram";
}
@@ -7477,6 +7485,8 @@ qemuBuildMemoryDeviceCommandLine(virCommandPtr cmd,
qemuDomainObjPrivatePtr 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 */
@@ -7490,12 +7500,35 @@ qemuBuildMemoryDeviceCommandLine(virCommandPtr cmd,
virCommandAddArg(cmd, "-object");
virCommandAddArgBuffer(cmd, &buf);
- if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i], priv)))
- return -1;
+ switch ((virDomainMemoryModel) def->mems[i]->model) {
+ case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
+ case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+ if (!(dimmStr = qemuBuildMemoryDeviceStr(def->mems[i], priv)))
+ return -1;
+
+ virCommandAddArgList(cmd, "-device", dimmStr, NULL);
+
+ VIR_FREE(dimmStr);
+ 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;
- virCommandAddArgList(cmd, "-device", dimmStr, NULL);
+ 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 55c874da16..d9e2da5f70 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8430,7 +8430,7 @@ qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
const virDomainMemoryDef *mem)
{
- unsigned int nmems = def->nmems;
+ unsigned int nmems = 0;
unsigned long long hotplugSpace;
unsigned long long hotplugMemory = 0;
bool needPCDimmCap = false;
@@ -8439,6 +8439,12 @@ qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
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)
+ nmems++;
+ }
+
if (mem) {
nmems++;
hotplugMemory = mem->size;
--
2.17.1