From nobody Mon Nov 25 12:39:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1603987124; cv=none; d=zohomail.com; s=zohoarc; b=Cc2/3zAv0DTUYtX6wtjn+FZpSFLP1buHqTaPlV7iGvcKmYoKo6TvcL76ZS1wp5SE50GWgC9rB+Qq3+6rum4y0bC1qGM4KEx9lZta+NzSBjgLdkjhs8s8MLDeTXnBShW3rBxcvfxoXNQp41xoJoP2G18IjRR15l7PocQt614HhHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603987124; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IRHEpR9kobGg3o5rz7P3+01PlOIr5sEfs/RUWc1pEJ4=; b=TxUcvHaYvtvWUNk4pxS5oWIHSKbfI4o11aHhwZCw4yJexsSSEejXBgeInt4nUaZOyzzKtFQE95ysnAP78dxIZvCG3YE0EPoOwGzG9eENx7efFhmq4wfLPakz2o9gmEdtKbtQPPyrYHea103Ql2yXYQDFj6iAy+GsVhjJKSvQME4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603987124469440.7359447743934; Thu, 29 Oct 2020 08:58:44 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-MBvuoaw8MtGKIpd9evidrA-1; Thu, 29 Oct 2020 11:58:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC0D81018F79; Thu, 29 Oct 2020 15:58:34 +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 8E4361975F; Thu, 29 Oct 2020 15:58:34 +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 334FB181A86E; Thu, 29 Oct 2020 15:58:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09TFtk7I029164 for ; Thu, 29 Oct 2020 11:55:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 417902156A4F; Thu, 29 Oct 2020 15:55:46 +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 398742156A4C for ; Thu, 29 Oct 2020 15:55:43 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A5A2811E76 for ; Thu, 29 Oct 2020 15:55:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-580-0HCXTP65NxS8Hsgw2cmnoA-1; Thu, 29 Oct 2020 11:55:39 -0400 Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 39FA9B298 for ; Thu, 29 Oct 2020 15:55:37 +0000 (UTC) X-MC-Unique: MBvuoaw8MtGKIpd9evidrA-1 X-MC-Unique: 0HCXTP65NxS8Hsgw2cmnoA-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Subject: [RFC PATCH 1/2] Add support for specifying max physical address size. From: Dario Faggioli To: libvir-list@redhat.com Date: Thu, 29 Oct 2020 15:55:36 +0000 Message-ID: <160398693628.12832.10312981876243507879.stgit@toolbox-dario-user-dev> In-Reply-To: <160398560496.12832.7946138363908682671.stgit@toolbox-dario-user-dev> References: <160398560496.12832.7946138363908682671.stgit@toolbox-dario-user-dev> User-Agent: StGit/0.23-36-gc01b MIME-Version: 1.0 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.78 on 10.11.54.6 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch introduces the: sub element of /domain/cpu. Purpose is being able to have a guest see the physical address size exactly as the host does (if mode=3D'passthrough' is used) or any size the user wants it to see (if mode=3D'emulate' is used and bits=3D'' is specified). This can be useful if the VM needs to have a large amount of memory. Signed-off-by: Dario Faggioli --- docs/formatdomain.rst | 21 ++++++++ docs/schemas/cputypes.rng | 19 +++++++ src/conf/cpu_conf.c | 52 ++++++++++++++++= ++++ src/conf/cpu_conf.h | 17 +++++++ src/libvirt_private.syms | 2 + .../genericxml2xmlindata/cpu-phys-bits-emulate.xml | 20 ++++++++ .../cpu-phys-bits-passthrough.xml | 20 ++++++++ tests/genericxml2xmltest.c | 3 + 8 files changed, 154 insertions(+) create mode 100644 tests/genericxml2xmlindata/cpu-phys-bits-emulate.xml create mode 100644 tests/genericxml2xmlindata/cpu-phys-bits-passthrough.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index ae635bedff..851391011f 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1207,6 +1207,7 @@ following collection of elements. :since:`Since 0.7.5` Intel + ... @@ -1223,6 +1224,7 @@ following collection of elements. :since:`Since 0.7.5` =20 + ... =20 @@ -1446,6 +1448,25 @@ In case no restrictions need to be put on CPU model = and its features, a simpler The virtual CPU will report no CPU cache of the specified level (= or no cache at all if the ``level`` attribute is missing). =20 +``maxphysaddress`` + :since:`Since 6.10.0` the ``maxphysaddr`` element specifies the size in= bits + of the physical addresses. The default behavior is that the vCPUs will = see + what it is configured by default in the hypervisor itself. + + ``mode`` + The following values are supported: + + ``passthrough`` + The number of physical address bits reported by the host CPU will= be + passed through to the virtual CPUs + ``emulate`` + The hypervisor will define a specific value for the number of bits + of physical addresses via the ``bits`` arrtibute, which is mandat= ory. + + ``bits`` + The number of bits of the physical addresses that the vCPUs should s= ee, + if the ``mode`` attribute is set to ``emulate``. + Guest NUMA topology can be specified using the ``numa`` element. :since:`S= ince 0.9.8` =20 diff --git a/docs/schemas/cputypes.rng b/docs/schemas/cputypes.rng index aea6ff0267..232115226a 100644 --- a/docs/schemas/cputypes.rng +++ b/docs/schemas/cputypes.rng @@ -299,6 +299,22 @@ =20 + + + + + emulate + passthrough + + + + + + + + + + @@ -410,6 +426,9 @@ + + + diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 7778e01131..a151bbf45b 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -83,6 +83,11 @@ VIR_ENUM_IMPL(virCPUCacheMode, "disable", ); =20 +VIR_ENUM_IMPL(virCPUMaxPhysAddrMode, + VIR_CPU_MAX_PHYS_ADDR_MODE_LAST, + "emulate", + "passthrough", +); =20 virCPUDefPtr virCPUDefNew(void) { @@ -128,6 +133,7 @@ virCPUDefFree(virCPUDefPtr def) if (g_atomic_int_dec_and_test(&def->refs)) { virCPUDefFreeModel(def); VIR_FREE(def->cache); + VIR_FREE(def->addr); VIR_FREE(def->tsc); VIR_FREE(def); } @@ -250,6 +256,11 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu) *copy->cache =3D *cpu->cache; } =20 + if (cpu->addr) { + copy->addr =3D g_new0(virCPUMaxPhysAddrDef, 1); + *copy->addr =3D *cpu->addr; + } + if (cpu->tsc) { copy->tsc =3D g_new0(virHostCPUTscInfo, 1); *copy->tsc =3D *cpu->tsc; @@ -670,6 +681,38 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, def->cache->mode =3D mode; } =20 + if (virXPathInt("count(./maxphysaddr)", ctxt, &n) < 0) { + return -1; + } else if (n > 1) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("at most one CPU maximum physical address bits " + "element may be specified")); + return -1; + } else if (n =3D=3D 1) { + int bits =3D -1; + g_autofree char *strmode =3D NULL; + int mode; + + if (virXPathBoolean("boolean(./maxphysaddr[1]/@bits)", ctxt) =3D= =3D 1 && + (virXPathInt("string(./maxphysaddr[1]/@bits)", ctxt, &bits) < = 0 || + bits < 0)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("CPU maximum physical address bits < 0")); + return -1; + } + + if (!(strmode =3D virXPathString("string(./maxphysaddr[1]/@mode)",= ctxt)) || + (mode =3D virCPUMaxPhysAddrModeTypeFromString(strmode)) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing or invalid CPU maximum physical " + "address bits mode")); + return -1; + } + + def->addr =3D g_new0(virCPUMaxPhysAddrDef, 1); + def->addr->bits =3D bits; + def->addr->mode =3D mode; + } *cpu =3D g_steal_pointer(&def); return 0; } @@ -841,6 +884,15 @@ virCPUDefFormatBuf(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } =20 + if (def->addr) { + virBufferAddLit(buf, "addr->bits !=3D -1) + virBufferAsprintf(buf, "bits=3D'%d' ", def->addr->bits); + virBufferAsprintf(buf, "mode=3D'%s'", + virCPUMaxPhysAddrModeTypeToString(def->addr->mod= e)); + virBufferAddLit(buf, "/>\n"); + } + for (i =3D 0; i < def->nfeatures; i++) { virCPUFeatureDefPtr feature =3D def->features + i; =20 diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 3ef14b7932..e7bbe916a3 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -117,6 +117,22 @@ struct _virCPUCacheDef { virCPUCacheMode mode; }; =20 +typedef enum { + VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE, + VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH, + + VIR_CPU_MAX_PHYS_ADDR_MODE_LAST +} virCPUMaxPhysAddrMode; + +VIR_ENUM_DECL(virCPUMaxPhysAddrMode); + +typedef struct _virCPUMaxPhysAddrDef virCPUMaxPhysAddrDef; +typedef virCPUMaxPhysAddrDef *virCPUMaxPhysAddrDefPtr; +struct _virCPUMaxPhysAddrDef { + int bits; /* -1 for unspecified */ + virCPUMaxPhysAddrMode mode; +}; + =20 typedef struct _virCPUDef virCPUDef; typedef virCPUDef *virCPUDefPtr; @@ -140,6 +156,7 @@ struct _virCPUDef { size_t nfeatures_max; virCPUFeatureDefPtr features; virCPUCacheDefPtr cache; + virCPUMaxPhysAddrDefPtr addr; virHostCPUTscInfoPtr tsc; virTristateSwitch migratable; /* for host-passthrough mode */ }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 95e50835ad..8629f81d33 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -117,6 +117,8 @@ virCPUDefParseXMLString; virCPUDefRef; virCPUDefStealModel; virCPUDefUpdateFeature; +virCPUMaxPhysAddrModeTypeFromString; +virCPUMaxPhysAddrModeTypeToString; virCPUModeTypeToString; =20 =20 diff --git a/tests/genericxml2xmlindata/cpu-phys-bits-emulate.xml b/tests/g= enericxml2xmlindata/cpu-phys-bits-emulate.xml new file mode 100644 index 0000000000..0b1b0f1672 --- /dev/null +++ b/tests/genericxml2xmlindata/cpu-phys-bits-emulate.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmlindata/cpu-phys-bits-passthrough.xml b/tes= ts/genericxml2xmlindata/cpu-phys-bits-passthrough.xml new file mode 100644 index 0000000000..cce676eaa6 --- /dev/null +++ b/tests/genericxml2xmlindata/cpu-phys-bits-passthrough.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 5110bfba86..6c1c6e699f 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -256,6 +256,9 @@ mymain(void) =20 DO_TEST_BACKUP_FULL("backup-pull-internal-invalid", true); =20 + DO_TEST("cpu-phys-bits-emulate"); + DO_TEST("cpu-phys-bits-passthrough"); + =20 virObjectUnref(caps); virObjectUnref(xmlopt);