]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Show host model in domain capabilities
authorJiri Denemark <jdenemar@redhat.com>
Wed, 15 Jun 2016 14:45:47 +0000 (16:45 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 22 Sep 2016 13:40:08 +0000 (15:40 +0200)
The domain capabilities XML is capable of showing whether each guest CPU
mode is supported or not with a possibility to provide additional
details. This patch enhances host-model capability to advertise the
exact CPU model which will be used as a host-model:

    <cpu>
        ...
        <mode name='host-model' supported='yes'>
            <model fallback='allow'>Broadwell</model>
            <vendor>Intel</vendor>
            <feature policy='disable' name='aes'/>
            <feature policy='require' name='vmx'/>
        </mode>
        ...
    </cpu>

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
13 files changed:
docs/formatdomaincaps.html.in
docs/schemas/domaincaps.rng
src/conf/domain_capabilities.c
src/conf/domain_capabilities.h
src/qemu/qemu_capabilities.c
tests/domaincapsschemadata/full.xml
tests/domaincapsschemadata/qemu_1.7.0.x86_64.xml
tests/domaincapsschemadata/qemu_2.6.0-gicv2-virt.aarch64.xml
tests/domaincapsschemadata/qemu_2.6.0-gicv3-virt.aarch64.xml
tests/domaincapsschemadata/qemu_2.6.0.aarch64.xml
tests/domaincapsschemadata/qemu_2.6.0.ppc64le.xml
tests/domaincapsschemadata/qemu_2.6.0.x86_64.xml
tests/domaincapstest.c

index 045ba939fe06f6a9ac1b2e6cae00a4aeb4c4ea96..648e3d481e1fee4259feeb50b3de51db37ba262c 100644 (file)
   ...
   &lt;cpu&gt;
     &lt;mode name='host-passthrough' supported='yes'/&gt;
-    &lt;mode name='host-model' supported='yes'/&gt;
+    &lt;mode name='host-model' supported='yes'&gt;
+      &lt;model fallback='allow'&gt;Broadwell&lt;/model&gt;
+      &lt;vendor&gt;Intel&lt;/vendor&gt;
+      &lt;feature policy='disable' name='aes'/&gt;
+      &lt;feature policy='require' name='vmx'/&gt;
+    &lt;/mode&gt;
     &lt;mode name='custom' supported='yes'&gt;
       &lt;model usable='no'&gt;Broadwell&lt;/model&gt;
       &lt;model usable='yes'&gt;Broadwell-noTSX&lt;/model&gt;
       <dd>No mode specific details are provided.</dd>
 
       <dt><code>host-model</code></dt>
-      <dd>No mode specific details are provided yet.</dd>
+      <dd>
+        If <code>host-model</code> is supported by the hypervisor, the
+        <code>mode</code> describes the guest CPU which will be used when
+        starting a domain with <code>host-model</code> CPU. The hypervisor
+        specifics (such as unsupported CPU models or features, machine type,
+        etc.) may be accounted for in this guest CPU specification and thus
+        the CPU can be different from the one shown in host capabilities XML.
+        This is indicated by the <code>fallback</code> attribute of the
+        <code>model</code> sub element: <code>allow</code> means not all
+        specifics were accounted for and thus the CPU a guest will see may
+        be different; <code>forbid</code> indicates that the CPU a guest will
+        see should match this CPU definition.
+      </dd>
 
       <dt><code>custom</code></dt>
       <dd>
index 5a605a7e1a853a5b7d0ffeaa379c9aef393814c1..20cbc4e944d5c763ad0417dcc4ea35d8fca3d56c 100644 (file)
@@ -2,6 +2,7 @@
 <!-- A Relax NG schema for the libvirt domain capabilities XML format -->
 <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
   <include href='basictypes.rng'/>
+  <include href='cputypes.rng'/>
   <start>
     <ref name='domainCapabilities'/>
   </start>
         <value>host-model</value>
       </attribute>
       <ref name='supported'/>
+      <optional>
+        <ref name="cpuModel"/>
+        <optional>
+          <ref name="cpuVendor"/>
+        </optional>
+        <zeroOrMore>
+          <ref name="cpuFeature"/>
+        </zeroOrMore>
+      </optional>
     </element>
   </define>
 
index 9ec416e3b091e3fbe67cbd62f57edec82450577c..beedd7076296f365b018171fb1423243f7d1a67f 100644 (file)
@@ -402,9 +402,19 @@ virDomainCapsCPUFormat(virBufferPtr buf,
                       virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH),
                       cpu->hostPassthrough ? "yes" : "no");
 
-    virBufferAsprintf(buf, "<mode name='%s' supported='%s'/>\n",
-                      virCPUModeTypeToString(VIR_CPU_MODE_HOST_MODEL),
-                      cpu->hostModel ? "yes" : "no");
+    virBufferAsprintf(buf, "<mode name='%s' ",
+                      virCPUModeTypeToString(VIR_CPU_MODE_HOST_MODEL));
+    if (cpu->hostModel) {
+        virBufferAddLit(buf, "supported='yes'>\n");
+        virBufferAdjustIndent(buf, 2);
+
+        virCPUDefFormatBuf(buf, cpu->hostModel, false);
+
+        virBufferAdjustIndent(buf, -2);
+        virBufferAddLit(buf, "</mode>\n");
+    } else {
+        virBufferAddLit(buf, "supported='no'/>\n");
+    }
 
     virBufferAsprintf(buf, "<mode name='%s' ",
                       virCPUModeTypeToString(VIR_CPU_MODE_CUSTOM));
index 3ec05dc07dba28fc7e61f90839d1c6a5fb1e52a9..13a65e351666a98c10a61300b6ff74f62a2e3dc4 100644 (file)
@@ -132,7 +132,7 @@ typedef struct _virDomainCapsCPU virDomainCapsCPU;
 typedef virDomainCapsCPU *virDomainCapsCPUPtr;
 struct _virDomainCapsCPU {
     bool hostPassthrough;
-    bool hostModel;
+    virCPUDefPtr hostModel;
     virDomainCapsCPUModelsPtr custom;
 };
 
index 8fabe8deb50258d4d7873709b78a34ff82d3ee1d..5ef6c9c8da5ed8053eaabd18fee93730d9aabdaf 100644 (file)
@@ -4358,9 +4358,7 @@ virQEMUCapsFillDomainCPUCaps(virCapsPtr caps,
         virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
         domCaps->cpu.hostPassthrough = true;
 
-    if (qemuCaps->cpuDefinitions && caps->host.cpu)
-        domCaps->cpu.hostModel = virQEMUCapsGuestIsNative(caps->host.arch,
-                                                          qemuCaps->arch);
+    domCaps->cpu.hostModel = virCPUDefCopy(qemuCaps->hostCPUModel);
 
     if (qemuCaps->cpuDefinitions &&
         cpuGetModels(domCaps->arch, &models) >= 0) {
index b75e86ce5da86515db9c2b5d8e212075dc52daab..eaf6eb6c09b787001ca1ad45a4925dc45c7cee2c 100644 (file)
   </os>
   <cpu>
     <mode name='host-passthrough' supported='yes'/>
-    <mode name='host-model' supported='yes'/>
+    <mode name='host-model' supported='yes'>
+      <model>host</model>
+      <vendor>CPU Vendorrr</vendor>
+    </mode>
     <mode name='custom' supported='yes'>
       <model usable='unknown'>Model1</model>
       <model usable='no'>Model2</model>
index 2b17dd0f744349aa378e3dd129e974f3a042a345..4aa475c1e7beeddf8aab2c0b4d68fea052d20084 100644 (file)
@@ -20,7 +20,9 @@
   </os>
   <cpu>
     <mode name='host-passthrough' supported='yes'/>
-    <mode name='host-model' supported='yes'/>
+    <mode name='host-model' supported='yes'>
+      <model fallback='allow'>Broadwell</model>
+    </mode>
     <mode name='custom' supported='yes'>
       <model usable='unknown'>Opteron_G5</model>
       <model usable='unknown'>Opteron_G4</model>
index 8a54f9e3fd395667b61ee1ec3775f98d3e003f14..796c3afee811a8dafb891c152dc3f3d948c01e98 100644 (file)
@@ -20,7 +20,7 @@
   </os>
   <cpu>
     <mode name='host-passthrough' supported='yes'/>
-    <mode name='host-model' supported='yes'/>
+    <mode name='host-model' supported='no'/>
     <mode name='custom' supported='yes'>
       <model usable='unknown'>pxa262</model>
       <model usable='unknown'>pxa270-a0</model>
index 8d8087fb7cfedba9be1063cf6d73000a2e183423..5a5f82c5d469dbd1c064ed143f27adc837974121 100644 (file)
@@ -20,7 +20,7 @@
   </os>
   <cpu>
     <mode name='host-passthrough' supported='yes'/>
-    <mode name='host-model' supported='yes'/>
+    <mode name='host-model' supported='no'/>
     <mode name='custom' supported='yes'>
       <model usable='unknown'>pxa262</model>
       <model usable='unknown'>pxa270-a0</model>
index 83c03db465c5202a495100bdfe436c503ac0a03b..90b57ffa2abbbc859a196b53975d45d04b93dfb7 100644 (file)
@@ -20,7 +20,7 @@
   </os>
   <cpu>
     <mode name='host-passthrough' supported='yes'/>
-    <mode name='host-model' supported='yes'/>
+    <mode name='host-model' supported='no'/>
     <mode name='custom' supported='yes'>
       <model usable='unknown'>pxa262</model>
       <model usable='unknown'>pxa270-a0</model>
index 14a087bc1a3f3f07013f8d629151fc984cfd6d58..962be6f33fc119fd209f6b309148050b62b8f258 100644 (file)
@@ -20,7 +20,9 @@
   </os>
   <cpu>
     <mode name='host-passthrough' supported='yes'/>
-    <mode name='host-model' supported='yes'/>
+    <mode name='host-model' supported='yes'>
+      <model fallback='allow'>POWER8</model>
+    </mode>
     <mode name='custom' supported='yes'>
       <model usable='unknown'>POWER8</model>
       <model usable='unknown'>POWER7</model>
index 4294c64c595e534e513bdab8a568538f9e9fb65e..a8975e8e53d927f72bee9c0731331f8c27b67255 100644 (file)
@@ -20,7 +20,9 @@
   </os>
   <cpu>
     <mode name='host-passthrough' supported='yes'/>
-    <mode name='host-model' supported='yes'/>
+    <mode name='host-model' supported='yes'>
+      <model fallback='allow'>Broadwell</model>
+    </mode>
     <mode name='custom' supported='yes'>
       <model usable='unknown'>Opteron_G5</model>
       <model usable='unknown'>Opteron_G4</model>
index 99971c27d19dade371e282dc309f3243e824c71f..e70fa05b68a17328dfcd165c0faf5c48f51f5f1e 100644 (file)
@@ -65,8 +65,14 @@ fillAllCaps(virDomainCapsPtr domCaps)
     virDomainCapsDeviceGraphicsPtr graphics = &domCaps->graphics;
     virDomainCapsDeviceVideoPtr video = &domCaps->video;
     virDomainCapsDeviceHostdevPtr hostdev = &domCaps->hostdev;
-    domCaps->maxvcpus = 255;
+    virCPUDef host = {
+        VIR_CPU_TYPE_HOST, 0, 0,
+        VIR_ARCH_X86_64, (char *) "host",
+        NULL, 0, (char *) "CPU Vendorrr",
+        0, 0, 0, 0, 0, NULL,
+    };
 
+    domCaps->maxvcpus = 255;
     os->supported = true;
 
     loader->supported = true;
@@ -79,7 +85,7 @@ fillAllCaps(virDomainCapsPtr domCaps)
         return -1;
 
     cpu->hostPassthrough = true;
-    cpu->hostModel = true;
+    cpu->hostModel = virCPUDefCopy(&host);
     if (!(cpu->custom = virDomainCapsCPUModelsNew(3)) ||
         virDomainCapsCPUModelsAdd(cpu->custom, "Model1", -1,
                                   VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||