From nobody Tue May 7 13:01:07 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); From nobody Tue May 7 13:01:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1603987663; cv=none; d=zohomail.com; s=zohoarc; b=Byxk8iZ4i2kQVb8yCJshfc7dB3x7SJQlR00bBuQTPa7TSBLBd7wsolxKwJzKs43LF9aDLwAbCZC+v892+QUd6o1emjdLmNPamF3LFhcsz0JmIRuXjSrPKMhKYIOxICfQlpqEFr21GbE5XPg10blIVWVb7IqvuKoR8QObEhBo9lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603987663; 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=p2WI5sWP83z7tMeG2zPff1L8FQa9pcYeiiViLBgzU9c=; b=fjMNeoB+gfni1AsL4so3IbHXUM9R+ZzR7CONIFI2u3wjJMC3oQnll+TTB4F4nT7Q560LbOkd2ClJ9geHMse/P8vLg1qSpl2H+uBQ4V5jUkY9PVi7zUbnjriiASiuU9z++6QRN4V78AM9whfMcdiQb2Hic788mBR7WyY8HvaIcEk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603987662991574.1470825757547; Thu, 29 Oct 2020 09:07:42 -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-365-BU44PJczNJ2Em8t2-fEKGg-1; Thu, 29 Oct 2020 12:07:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 140E4804746; Thu, 29 Oct 2020 16:07:31 +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 A3D976198B; Thu, 29 Oct 2020 16:07:30 +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 DC6BC181A870; Thu, 29 Oct 2020 16:07:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09TFtndL029176 for ; Thu, 29 Oct 2020 11:55:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 643F810F8E23; Thu, 29 Oct 2020 15:55:49 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6020910FFE69 for ; Thu, 29 Oct 2020 15:55:47 +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 0585F858280 for ; Thu, 29 Oct 2020 15:55:47 +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-400-5Q_EzPNLNrC-Nd91N-LU5w-1; Thu, 29 Oct 2020 11:55:44 -0400 Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0FFF0ACA0 for ; Thu, 29 Oct 2020 15:55:43 +0000 (UTC) X-MC-Unique: BU44PJczNJ2Em8t2-fEKGg-1 X-MC-Unique: 5Q_EzPNLNrC-Nd91N-LU5w-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Subject: [RFC PATCH 2/2] qemu: Add support for max physical address size From: Dario Faggioli To: libvir-list@redhat.com Date: Thu, 29 Oct 2020 15:55:42 +0000 Message-ID: <160398694221.12832.16596704523899993962.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.3 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.12 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 maps /domain/cpu/maxphysaddr into -cpu parameters: - becomes host-phys-bits=3Don - becomes phys-bits=3D42 Passthrough mode can only be used if the chosen CPU model is 'host-passthrough'. The feature is available since QEMU 2.7.0. Signed-off-by: Dario Faggioli --- src/qemu/qemu_capabilities.c | 2 + src/qemu/qemu_capabilities.h | 1=20 src/qemu/qemu_command.c | 28 ++++++++++++ src/qemu/qemu_domain.c | 46 ++++++++++++++++= ++++ tests/qemuxml2argvdata/cpu-phys-bits-emulate.args | 29 +++++++++++++ tests/qemuxml2argvdata/cpu-phys-bits-emulate.xml | 20 +++++++++ tests/qemuxml2argvdata/cpu-phys-bits-emulate2.args | 30 +++++++++++++ tests/qemuxml2argvdata/cpu-phys-bits-emulate2.xml | 20 +++++++++ tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err | 1=20 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml | 20 +++++++++ .../cpu-phys-bits-passthrough.args | 29 +++++++++++++ .../qemuxml2argvdata/cpu-phys-bits-passthrough.xml | 20 +++++++++ .../cpu-phys-bits-passthrough2.err | 1=20 .../cpu-phys-bits-passthrough2.xml | 20 +++++++++ .../cpu-phys-bits-passthrough3.err | 1=20 .../cpu-phys-bits-passthrough3.xml | 20 +++++++++ tests/qemuxml2argvtest.c | 7 +++ 17 files changed, 295 insertions(+) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate.args create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate.xml create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate2.args create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate2.xml create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-passthrough.args create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-passthrough.xml create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-passthrough2.err create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-passthrough2.xml create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-passthrough3.err create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-passthrough3.xml diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a67fb785b5..70adb423f1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -603,6 +603,7 @@ VIR_ENUM_IMPL(virQEMUCaps, "virtio-balloon.free-page-reporting", "block-export-add", "netdev.vhost-vdpa", + "host-phys-bits", ); =20 =20 @@ -1679,6 +1680,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsObjec= tPropsMaxCPU[] =3D { { "unavailable-features", QEMU_CAPS_CPU_UNAVAILABLE_FEATURES }, { "kvm-no-adjvtime", QEMU_CAPS_CPU_KVM_NO_ADJVTIME }, { "migratable", QEMU_CAPS_CPU_MIGRATABLE }, + { "host-phys-bits", QEMU_CAPS_CPU_PHYS_BITS }, }; =20 static virQEMUCapsObjectTypeProps virQEMUCapsObjectProps[] =3D { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 047ba8a0ee..0fe97d2fd1 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -583,6 +583,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_VIRTIO_BALLOON_FREE_PAGE_REPORTING, /*virtio balloon free-pa= ge-reporting */ QEMU_CAPS_BLOCK_EXPORT_ADD, /* 'block-export-add' command is supported= */ QEMU_CAPS_NETDEV_VHOST_VDPA, /* -netdev vhost-vdpa*/ + QEMU_CAPS_CPU_PHYS_BITS, /* -cpu phys-bits=3D42 or host-phys-bits=3Don= */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7847706594..d58f80547e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6507,6 +6507,34 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, virBufferAddLit(&buf, ",l3-cache=3Doff"); } =20 + if (def->cpu && def->cpu->addr) { + virCPUMaxPhysAddrDefPtr addr =3D def->cpu->addr; + + switch (addr->mode) { + case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH: + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_PHYS_BITS)) + virBufferAddLit(&buf, ",host-phys-bits=3Don"); + else + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting host physical address bits is " + "not supported by this QEMU")); + break; + + case VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE: + if (addr->bits !=3D -1 && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_PHYS_BITS)) + virBufferAsprintf(&buf, ",phys-bits=3D%d", addr->bits); + else + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Physical address bits unspecified or " + "setting it not supported by this QEMU")); + break; + + case VIR_CPU_MAX_PHYS_ADDR_MODE_LAST: + break; + } + } + cpu =3D virBufferContentAndReset(&cpu_buf); cpu_flags =3D virBufferContentAndReset(&buf); =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d7dbca487a..e9f20d82a1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4051,6 +4051,52 @@ qemuDomainDefCPUPostParse(virDomainDefPtr def, } } =20 + if (def->cpu->addr) { + virCPUMaxPhysAddrDefPtr addr =3D def->cpu->addr; + + if (!ARCH_IS_X86(def->os.arch)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("CPU maximum physical address bits specificat= ion " + "is not supported for '%s' architecture"), + virArchToString(def->os.arch)); + return -1; + } + + switch (addr->mode) { + case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH: + if (def->cpu->mode !=3D VIR_CPU_MODE_HOST_PASSTHROUGH) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("CPU maximum physical address bits mode '= %s' " + "can only be used with '%s' CPUs"), + virCPUMaxPhysAddrModeTypeToString(addr->mod= e), + virCPUModeTypeToString(VIR_CPU_MODE_HOST_PA= SSTHROUGH)); + return -1; + } + if (addr->bits !=3D -1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("CPU maximum physical address bits number= " + "specification cannot be used with " + "mode=3D'%s'"), + virCPUMaxPhysAddrModeTypeToString(VIR_CPU_M= AX_PHYS_ADDR_MODE_PASSTHROUGH)); + return -1; + } + break; + + case VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE: + if (addr->bits =3D=3D -1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("if using CPU maximum physical address " + "mode=3D'%s', bits=3D must be specified t= oo"), + virCPUMaxPhysAddrModeTypeToString(VIR_CPU_M= AX_PHYS_ADDR_MODE_EMULATE)); + return -1; + } + break; + + case VIR_CPU_MAX_PHYS_ADDR_MODE_LAST: + break; + } + } + for (i =3D 0; i < def->cpu->nfeatures; i++) { virCPUFeatureDefPtr feature =3D &def->cpu->features[i]; =20 diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate.args b/tests/qemu= xml2argvdata/cpu-phys-bits-emulate.args new file mode 100644 index 0000000000..5627b41b25 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-emulate.args @@ -0,0 +1,29 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-foo \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-foo/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-foo/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-foo/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name foo \ +-S \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-cpu host,phys-bits=3D42 \ +-m 214 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-foo/monitor.soc= k,server,\ +nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate.xml b/tests/qemux= ml2argvdata/cpu-phys-bits-emulate.xml new file mode 100644 index 0000000000..f8bd63bc68 --- /dev/null +++ b/tests/qemuxml2argvdata/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/qemuxml2argvdata/cpu-phys-bits-emulate2.args b/tests/qem= uxml2argvdata/cpu-phys-bits-emulate2.args new file mode 100644 index 0000000000..f105f96f02 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-emulate2.args @@ -0,0 +1,30 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-foo \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-foo/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-foo/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-foo/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name foo \ +-S \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-cpu core2duo,+ds,+acpi,+ss,+ht,+tm,+pbe,+ds_cpl,+vmx,+est,+tm2,+cx16,+xtp= r,\ ++lahf_lm,phys-bits=3D42 \ +-m 214 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-foo/monitor.soc= k,server,\ +nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate2.xml b/tests/qemu= xml2argvdata/cpu-phys-bits-emulate2.xml new file mode 100644 index 0000000000..188b3066ed --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-emulate2.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err b/tests/qemu= xml2argvdata/cpu-phys-bits-emulate3.err new file mode 100644 index 0000000000..5e21998259 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err @@ -0,0 +1 @@ +unsupported configuration: if using CPU maximum physical address mode=3D'e= mulate', bits=3D must be specified too diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml b/tests/qemu= xml2argvdata/cpu-phys-bits-emulate3.xml new file mode 100644 index 0000000000..30a14894dd --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-passthrough.args b/tests/= qemuxml2argvdata/cpu-phys-bits-passthrough.args new file mode 100644 index 0000000000..a4f3f55bb9 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-passthrough.args @@ -0,0 +1,29 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-foo \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-foo/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-foo/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-foo/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name foo \ +-S \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-cpu host,host-phys-bits=3Don \ +-m 214 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-foo/monitor.soc= k,server,\ +nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-passthrough.xml b/tests/q= emuxml2argvdata/cpu-phys-bits-passthrough.xml new file mode 100644 index 0000000000..db570beb8d --- /dev/null +++ b/tests/qemuxml2argvdata/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/qemuxml2argvdata/cpu-phys-bits-passthrough2.err b/tests/= qemuxml2argvdata/cpu-phys-bits-passthrough2.err new file mode 100644 index 0000000000..22009cc6e6 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-passthrough2.err @@ -0,0 +1 @@ +unsupported configuration: CPU maximum physical address bits mode 'passthr= ough' can only be used with 'host-passthrough' CPUs diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-passthrough2.xml b/tests/= qemuxml2argvdata/cpu-phys-bits-passthrough2.xml new file mode 100644 index 0000000000..511bbf9949 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-passthrough2.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-passthrough3.err b/tests/= qemuxml2argvdata/cpu-phys-bits-passthrough3.err new file mode 100644 index 0000000000..28f2e43432 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-passthrough3.err @@ -0,0 +1 @@ +unsupported configuration: CPU maximum physical address bits number specif= ication cannot be used with mode=3D'passthrough' diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-passthrough3.xml b/tests/= qemuxml2argvdata/cpu-phys-bits-passthrough3.xml new file mode 100644 index 0000000000..a94e567dcb --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-passthrough3.xml @@ -0,0 +1,20 @@ + + foo + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + + + + destroy + restart + destroy + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index c5a0095e0d..fd17fea744 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3409,6 +3409,13 @@ mymain(void) =20 DO_TEST_CAPS_LATEST("virtio-9p-multidevs"); =20 + DO_TEST("cpu-phys-bits-passthrough", QEMU_CAPS_KVM, QEMU_CAPS_CPU_PHYS= _BITS); + DO_TEST("cpu-phys-bits-emulate", QEMU_CAPS_KVM, QEMU_CAPS_CPU_PHYS_BIT= S); + DO_TEST("cpu-phys-bits-emulate2", QEMU_CAPS_KVM, QEMU_CAPS_CPU_PHYS_BI= TS); + DO_TEST_PARSE_ERROR("cpu-phys-bits-emulate3", QEMU_CAPS_KVM); + DO_TEST_PARSE_ERROR("cpu-phys-bits-passthrough2", QEMU_CAPS_KVM); + DO_TEST_PARSE_ERROR("cpu-phys-bits-passthrough3", QEMU_CAPS_KVM); + if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); =20