From nobody Sun Feb 8 05:42:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1489510893519961.9571711496806; Tue, 14 Mar 2017 10:01:33 -0700 (PDT) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2EGvuuE011269; Tue, 14 Mar 2017 12:57:56 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2EGvtlH002599 for ; Tue, 14 Mar 2017 12:57:55 -0400 Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2EGvr5w020461 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 14 Mar 2017 12:57:54 -0400 Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 7F7561062D0; Tue, 14 Mar 2017 17:57:53 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 14 Mar 2017 17:57:42 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/12] Introduce /domain/cpu/@check XML attribute 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The attribute can be used to request a specific way of checking whether the virtual CPU matches created by the hypervisor matches the specification in domain XML. Signed-off-by: Jiri Denemark --- docs/formatdomain.html.in | 30 ++++++++++++++++++++++++++++++ docs/schemas/cputypes.rng | 10 ++++++++++ docs/schemas/domaincommon.rng | 3 +++ src/conf/cpu_conf.c | 30 ++++++++++++++++++++++++++++++ src/conf/cpu_conf.h | 12 ++++++++++++ src/conf/domain_conf.c | 21 +++++++++++++++++++++ 6 files changed, 106 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 75367d6dd..3bea3c75a 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1247,6 +1247,36 @@ Since 0.8.5 the match attribute can be omitted and will default to exact. =20 + Sometimes the hypervisor is not able to create a virtual CPU exact= ly + matching the specification passed by libvirt. + Since 3.2.0, an optional check<= /code> + attribute can be used to request a specific way of checking whether + the virtual CPU matches the specification. It is usually safe to o= mit + this attribute when starting a domain and stick with the default + value. Once the domain starts, libvirt will automatically change t= he + check attribute to the best supported value to ensure= the + virtual CPU does not change when the domain is migrated to another + host. The following values can be used: + +
+
none
+
Libvirt does no checking and it is up to the hypervisor to + refuse to start the domain if it cannot provide the requested = CPU. + With QEMU this means no checking is done at all since the defa= ult + behavior of QEMU is to emit warnings, but start the domain any= way. +
+ +
partial
+
Libvirt will check the guest CPU specification before starti= ng + a domain, but the rest is left on the hypervisor. It can still + provide a different virtual CPU.
+ +
full
+
The virtual CPU created by the hypervisor will be checked + against the CPU specification and the domain will not be start= ed + unless the two CPUs match.
+
+ Since 0.9.10, an optional mode<= /code> attribute may be used to make it easier to configure a guest CPU t= o be as close to host CPU as possible. Possible values for the diff --git a/docs/schemas/cputypes.rng b/docs/schemas/cputypes.rng index 7cc9dd3d8..8189114e3 100644 --- a/docs/schemas/cputypes.rng +++ b/docs/schemas/cputypes.rng @@ -23,6 +23,16 @@ =20 + + + + none + partial + full + + + + diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 5e593285e..767d6979c 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4503,6 +4503,9 @@ + + + diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 2724fa30a..90accaea7 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -45,6 +45,12 @@ VIR_ENUM_IMPL(virCPUMatch, VIR_CPU_MATCH_LAST, "exact", "strict") =20 +VIR_ENUM_IMPL(virCPUCheck, VIR_CPU_CHECK_LAST, + "default", + "none", + "partial", + "full") + VIR_ENUM_IMPL(virCPUFallback, VIR_CPU_FALLBACK_LAST, "allow", "forbid") @@ -182,6 +188,7 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu) copy->type =3D cpu->type; copy->mode =3D cpu->mode; copy->match =3D cpu->match; + copy->check =3D cpu->check; copy->fallback =3D cpu->fallback; copy->sockets =3D cpu->sockets; copy->cores =3D cpu->cores; @@ -277,6 +284,7 @@ virCPUDefParseXML(xmlNodePtr node, =20 if (def->type =3D=3D VIR_CPU_TYPE_GUEST) { char *match =3D virXMLPropString(node, "match"); + char *check; =20 if (!match) { if (virXPathBoolean("boolean(./model)", ctxt)) @@ -294,6 +302,18 @@ virCPUDefParseXML(xmlNodePtr node, goto error; } } + + if ((check =3D virXMLPropString(node, "check"))) { + def->check =3D virCPUCheckTypeFromString(check); + VIR_FREE(check); + + if (def->check < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Invalid check attribute for CPU " + "specification")); + goto error; + } + } } =20 if (def->type =3D=3D VIR_CPU_TYPE_HOST) { @@ -532,6 +552,16 @@ virCPUDefFormatBufFull(virBufferPtr buf, } virBufferAsprintf(&attributeBuf, " match=3D'%s'", tmp); } + + if (def->check) { + if (!(tmp =3D virCPUCheckTypeToString(def->check))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected CPU check policy %d"), + def->check); + goto cleanup; + } + virBufferAsprintf(&attributeBuf, " check=3D'%s'", tmp); + } } =20 /* Format children */ diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index cc3fbf0a4..507f630dc 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -64,6 +64,17 @@ typedef enum { VIR_ENUM_DECL(virCPUMatch) =20 typedef enum { + VIR_CPU_CHECK_DEFAULT, + VIR_CPU_CHECK_NONE, + VIR_CPU_CHECK_PARTIAL, + VIR_CPU_CHECK_FULL, + + VIR_CPU_CHECK_LAST +} virCPUCheck; + +VIR_ENUM_DECL(virCPUCheck) + +typedef enum { VIR_CPU_FALLBACK_ALLOW, VIR_CPU_FALLBACK_FORBID, =20 @@ -98,6 +109,7 @@ struct _virCPUDef { int type; /* enum virCPUType */ int mode; /* enum virCPUMode */ int match; /* enum virCPUMatch */ + int check; /* virCPUCheck */ virArch arch; char *model; char *vendor_id; /* vendor id returned by CPUID in the guest */ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 88d419e27..a2cdb260a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4587,6 +4587,24 @@ virDomainVcpuDefPostParse(virDomainDefPtr def) =20 =20 static int +virDomainDefPostParseCPU(virDomainDefPtr def) +{ + if (!def->cpu) + return 0; + + if (def->cpu->mode =3D=3D VIR_CPU_MODE_CUSTOM && + !def->cpu->model && + def->cpu->check !=3D VIR_CPU_CHECK_DEFAULT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("check attribute specified for CPU with no model"= )); + return -1; + } + + return 0; +} + + +static int virDomainDefPostParseInternal(virDomainDefPtr def, struct virDomainDefPostParseDeviceIteratorDa= ta *data) { @@ -4636,6 +4654,9 @@ virDomainDefPostParseInternal(virDomainDefPtr def, =20 virDomainDefPostParseGraphics(def); =20 + if (virDomainDefPostParseCPU(def) < 0) + return -1; + return 0; } =20 --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list