On Wed, Sep 08, 2021 at 09:15:55AM +0800, Haibin Huang wrote: > 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; The 'case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC' block ends here, but > + > + 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); This is EPC specific code. Since you put the virCommandAddArgList() call inside the switch() for the other memory model types, I think this virCommandAddArgBuffer for EPC should be inside the switch too. > } > > return 0; Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|