From nobody Mon Feb 9 17:35:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 163953976109735.69177824045357; Tue, 14 Dec 2021 19:42:41 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-439-5JlujZEJPNylyTPx7TLSDQ-1; Tue, 14 Dec 2021 22:42:35 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E370A185302C; Wed, 15 Dec 2021 03:42:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C87FC84D00; Wed, 15 Dec 2021 03:42:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9FD461806D1C; Wed, 15 Dec 2021 03:42:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1BF3gM7U024561 for ; Tue, 14 Dec 2021 22:42:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id E6E6D401E55; Wed, 15 Dec 2021 03:42:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2E2C401DAD for ; Wed, 15 Dec 2021 03:42:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8894811E76 for ; Wed, 15 Dec 2021 03:42:21 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-217-efMlOGxKO-GYkcDaguMBKw-4; Tue, 14 Dec 2021 22:42:19 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2021 19:42:18 -0800 Received: from nhsgx.sh.intel.com ([10.239.36.138]) by fmsmga002.fm.intel.com with ESMTP; 14 Dec 2021 19:42:17 -0800 X-MC-Unique: 5JlujZEJPNylyTPx7TLSDQ-1 X-MC-Unique: efMlOGxKO-GYkcDaguMBKw-4 X-IronPort-AV: E=McAfee;i="6200,9189,10198"; a="236675537" X-IronPort-AV: E=Sophos;i="5.88,207,1635231600"; d="scan'208";a="236675537" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,207,1635231600"; d="scan'208";a="610210109" From: Haibin Huang To: libvir-list@redhat.com, haibin.huang@intel.com, jian-feng.ding@intel.com, lin.a.yang@intel.com, lianhao.lu@intel.com, yang.zhong@intel.com Subject: [libvirt][PATCH v9 4/5] qemu: Add command-line to generate SGX EPC memory backend Date: Wed, 15 Dec 2021 11:40:14 +0800 Message-Id: <20211215034015.1138-5-haibin.huang@intel.com> In-Reply-To: <20211215034015.1138-1-haibin.huang@intel.com> References: <20211215034015.1138-1-haibin.huang@intel.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZM-MESSAGEID: 1639539761376100003 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Lin Yang 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=3Dmem1,size=3D64M,prealloc=3Don \ -object memory-backend-epc,id=3Dmem2,size=3D28M \ -M sgx-epc.0.memdev=3Dmem1,sgx-epc.1.memdev=3Dmem2 Signed-off-by: Lin Yang --- 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 !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM && - mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) + mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM && + mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_SGX_EPC) return mem->info.addr.dimm.slot; =20 for (i =3D 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 **backendPr= ops, if (systemMemory) disableCanonicalPath =3D true; =20 + } else if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_SGX_EPC) { + backendType =3D "memory-backend-epc"; + if (!priv->memPrealloc) + prealloc =3D true; } else { backendType =3D "memory-backend-ram"; } @@ -7838,6 +7842,8 @@ qemuBuildMemoryDeviceCommandLine(virCommand *cmd, qemuDomainObjPrivate *priv) { size_t i; + g_auto(virBuffer) epcBuf =3D VIR_BUFFER_INITIALIZER; + int epcNum =3D 0; =20 /* 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, pri= v) < 0) return -1; =20 - if (!(props =3D 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 =3D qemuBuildMemoryDeviceProps(def, def->mems[i]))) + return -1; =20 - if (qemuBuildDeviceCommandlineFromJSON(cmd, props, priv->qemuCaps)= < 0) - return -1; + if (qemuBuildDeviceCommandlineFromJSON(cmd, props, priv->qemuC= aps) < 0) + return -1; + + break; + + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: + if (virBufferUse(&epcBuf) > 0) + virBufferAddChar(&epcBuf, ','); + + virBufferAsprintf(&epcBuf, "sgx-epc.%d.memdev=3D%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); } =20 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 =3D def->nmems; + unsigned int nmems =3D 0; unsigned long long hotplugSpace; unsigned long long hotplugMemory =3D 0; size_t i; =20 hotplugSpace =3D def->mem.max_memory - virDomainDefGetMemoryInitial(de= f); =20 + for (i =3D 0; i < def->nmems; i++) { + if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM || + def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM || + def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM= || + def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) + nmems++; + } + if (mem) { nmems++; hotplugMemory =3D mem->size; --=20 2.17.1