From nobody Mon Feb 9 17:23:52 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 1644359901516997.4230682483998; Tue, 8 Feb 2022 14:38:21 -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-83-Y9OYtj4GOpW-viEFZHivOw-1; Tue, 08 Feb 2022 17:38:19 -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 CB1CA93922; Tue, 8 Feb 2022 22:38:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6A2613A58; Tue, 8 Feb 2022 22:38:13 +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 796FB4BB7C; Tue, 8 Feb 2022 22:38:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 2185Lgo4014453 for ; Tue, 8 Feb 2022 00:21:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 22E04C07F5C; Tue, 8 Feb 2022 05:21:42 +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 1EE5FC01784 for ; Tue, 8 Feb 2022 05:21:42 +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 07C8A811E76 for ; Tue, 8 Feb 2022 05:21:42 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-5YATtcf7NQygfBcwwBifqg-6; Tue, 08 Feb 2022 00:21:40 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2022 21:21:39 -0800 Received: from sse-tme-qnx-01.jf.intel.com ([10.54.34.46]) by orsmga001.jf.intel.com with ESMTP; 07 Feb 2022 21:21:39 -0800 X-MC-Unique: Y9OYtj4GOpW-viEFZHivOw-1 X-MC-Unique: 5YATtcf7NQygfBcwwBifqg-6 X-IronPort-AV: E=McAfee;i="6200,9189,10251"; a="248638164" X-IronPort-AV: E=Sophos;i="5.88,351,1635231600"; d="scan'208";a="248638164" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,351,1635231600"; d="scan'208";a="567729264" From: Haibin Huang To: libvir-list@redhat.com, haibin.huang@intel.com, berrange@redhat.com, jian-feng.ding@intel.com, lin.a.yang@intel.com, lianhao.lu@intel.com Subject: [libvirt][PATCH RESEND v10 5/5] qemu: Add command-line to generate SGX EPC memory backend Date: Mon, 7 Feb 2022 21:21:20 -0800 Message-Id: <20220208052120.14239-6-haibin.huang@intel.com> In-Reply-To: <20220208052120.14239-1-haibin.huang@intel.com> References: <20220208052120.14239-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.8 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: 1644359903164100002 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 | 46 +++++++++++++++++-- .../sgx-epc.x86_64-6.2.0.args | 38 +++++++++++++++ tests/qemuxml2argvtest.c | 2 + 4 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 tests/qemuxml2argvdata/sgx-epc.x86_64-6.2.0.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index e5a946cbed..03c79bcf0e 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -467,7 +467,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 e6f29d878c..71804e659c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3815,6 +3815,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 if (useHugepage || mem->nvdimmPath || memAccess || def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { =20 @@ -3972,6 +3976,12 @@ qemuBuildMemoryBackendProps(virJSONValue **backendPr= ops, _("this qemu doesn't support the " "memory-backend-memfd object")); return -1; + } else if (STREQ(backendType, "memory-backend-epc") && + !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_SGX_EPC)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this qemu doesn't support the " + "memory-backend-epc object")); + return -1; } =20 rc =3D 0; @@ -7800,6 +7810,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 */ @@ -7809,11 +7821,37 @@ qemuBuildMemoryDeviceCommandLine(virCommand *cmd, if (qemuBuildMemoryDimmBackendStr(cmd, def->mems[i], def, cfg, pri= v) < 0) return -1; =20 - if (!(props =3D qemuBuildMemoryDeviceProps(cfg, priv, def, def->me= ms[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(cfg, priv, 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=3Dmem%s", epcNum= ++, + 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/tests/qemuxml2argvdata/sgx-epc.x86_64-6.2.0.args b/tests/qemux= ml2argvdata/sgx-epc.x86_64-6.2.0.args new file mode 100644 index 0000000000..e1aa274054 --- /dev/null +++ b/tests/qemuxml2argvdata/sgx-epc.x86_64-6.2.0.args @@ -0,0 +1,38 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc-q35-6.2,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ra= m \ +-accel tcg \ +-cpu qemu64 \ +-m 134 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":140509184}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-object '{"qom-type":"memory-backend-epc","id":"memepc0","prealloc":true,"= size":67108864}' \ +-object '{"qom-type":"memory-backend-epc","id":"memepc1","prealloc":true,"= size":16777216}' \ +-M sgx-epc.0.memdev=3Dmemepc0,sgx-epc.1.memdev=3Dmemepc1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot strict=3Don \ +-device pcie-root-port,port=3D8,chassis=3D1,id=3Dpci.1,bus=3Dpcie.0,multif= unction=3Don,addr=3D0x1 \ +-device pcie-root-port,port=3D9,chassis=3D2,id=3Dpci.2,bus=3Dpcie.0,addr= =3D0x1.0x1 \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.1,addr=3D0x0 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 96d30f2475..2df18e4199 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3521,6 +3521,8 @@ mymain(void) /* HVF guests should not work on Linux with KVM */ DO_TEST_CAPS_LATEST_PARSE_ERROR("hvf-x86_64-q35-headless"); =20 + DO_TEST_CAPS_VER("sgx-epc", "6.2.0"); + if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); =20 --=20 2.17.1