From nobody Mon Feb 9 12:15:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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.133.124]) by mx.zohomail.com with SMTPS id 1639453569874474.80482351327737; Mon, 13 Dec 2021 19:46:09 -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-300-thRTkid8Pmuj2hQQY1c6rQ-1; Mon, 13 Dec 2021 22:46:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BCA7185302C; Tue, 14 Dec 2021 03:46:02 +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 7B60EADCB; Tue, 14 Dec 2021 03:46:02 +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 4E19A1806D1C; Tue, 14 Dec 2021 03:46:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1BE3i3Gq018680 for ; Mon, 13 Dec 2021 22:44:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 13F9E492CA4; Tue, 14 Dec 2021 03:44:03 +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 0FD2E492C3B for ; Tue, 14 Dec 2021 03:44:03 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 EA928811E76 for ; Tue, 14 Dec 2021 03:44:02 +0000 (UTC) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-490-sh3E4ew6MrWOUB2EsEICMA-5; Mon, 13 Dec 2021 22:44:00 -0500 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2021 19:42:58 -0800 Received: from nhsgx.sh.intel.com ([10.239.36.138]) by fmsmga005.fm.intel.com with ESMTP; 13 Dec 2021 19:42:56 -0800 X-MC-Unique: thRTkid8Pmuj2hQQY1c6rQ-1 X-MC-Unique: sh3E4ew6MrWOUB2EsEICMA-5 X-IronPort-AV: E=McAfee;i="6200,9189,10197"; a="325162456" X-IronPort-AV: E=Sophos;i="5.88,204,1635231600"; d="scan'208";a="325162456" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,204,1635231600"; d="scan'208";a="754687845" 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 v8 4/5] qemu: Add command-line to generate SGX EPC memory backend Date: Tue, 14 Dec 2021 11:41:10 +0800 Message-Id: <20211214034111.23623-5-haibin.huang@intel.com> In-Reply-To: <20211214034111.23623-1-haibin.huang@intel.com> References: <20211214034111.23623-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.9 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.14 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: 1639453570835100001 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 --- 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