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@xxxxxxxxxx> --- docs/formatdomaincaps.html.in | 21 +++++++++++++++++++-- docs/schemas/domaincaps.rng | 10 ++++++++++ src/conf/domain_capabilities.c | 16 +++++++++++++--- src/conf/domain_capabilities.h | 2 +- src/qemu/qemu_capabilities.c | 4 +--- tests/domaincapsschemadata/full.xml | 5 ++++- tests/domaincapsschemadata/qemu_1.7.0.x86_64.xml | 4 +++- .../qemu_2.6.0-gicv2-virt.aarch64.xml | 2 +- .../qemu_2.6.0-gicv3-virt.aarch64.xml | 2 +- tests/domaincapsschemadata/qemu_2.6.0.aarch64.xml | 2 +- tests/domaincapsschemadata/qemu_2.6.0.ppc64le.xml | 4 +++- tests/domaincapsschemadata/qemu_2.6.0.x86_64.xml | 4 +++- tests/domaincapstest.c | 10 ++++++++-- 13 files changed, 68 insertions(+), 18 deletions(-) diff --git a/docs/formatdomaincaps.html.in b/docs/formatdomaincaps.html.in index 49ccbfc..34eb777 100644 --- a/docs/formatdomaincaps.html.in +++ b/docs/formatdomaincaps.html.in @@ -154,7 +154,12 @@ ... <cpu> <mode name='host-passthrough' supported='yes'/> - <mode name='host-model' supported='yes'/> + <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> <mode name='custom' supported='yes'> <model usable='no'>Broadwell</model> <model usable='yes'>Broadwell-noTSX</model> @@ -177,7 +182,19 @@ <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> says that the CPU a guest will see + should match this CPU definition. + </dd> <dt><code>custom</code></dt> <dd> diff --git a/docs/schemas/domaincaps.rng b/docs/schemas/domaincaps.rng index 5a605a7..20cbc4e 100644 --- a/docs/schemas/domaincaps.rng +++ b/docs/schemas/domaincaps.rng @@ -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> @@ -94,6 +95,15 @@ <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> diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index c9e3a28..34379e9 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -404,9 +404,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)); diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h index 7498f89..36693d7 100644 --- a/src/conf/domain_capabilities.h +++ b/src/conf/domain_capabilities.h @@ -132,7 +132,7 @@ typedef struct _virDomainCapsCPU virDomainCapsCPU; typedef virDomainCapsCPU *virDomainCapsCPUPtr; struct _virDomainCapsCPU { bool hostPassthrough; - bool hostModel; + virCPUDefPtr hostModel; virDomainCapsCPUModelsPtr custom; }; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 97dc877..5197180 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4260,9 +4260,7 @@ virQEMUCapsFillDomainCPUCaps(virCapsPtr caps, virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch)) domCaps->cpu.hostPassthrough = true; - if (qemuCaps->cpuDefinitions && caps && caps->host.cpu) - domCaps->cpu.hostModel = virQEMUCapsGuestIsNative(caps->host.arch, - qemuCaps->arch); + domCaps->cpu.hostModel = virCPUDefCopy(qemuCaps->cpuModel); if (qemuCaps->cpuDefinitions && cpuGetModels(domCaps->arch, &models) >= 0) { diff --git a/tests/domaincapsschemadata/full.xml b/tests/domaincapsschemadata/full.xml index 1d58e57..5853151 100644 --- a/tests/domaincapsschemadata/full.xml +++ b/tests/domaincapsschemadata/full.xml @@ -21,7 +21,10 @@ </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='yes'>Model3</model> <model usable='no'>Model2</model> diff --git a/tests/domaincapsschemadata/qemu_1.7.0.x86_64.xml b/tests/domaincapsschemadata/qemu_1.7.0.x86_64.xml index 2b17dd0..4aa475c 100644 --- a/tests/domaincapsschemadata/qemu_1.7.0.x86_64.xml +++ b/tests/domaincapsschemadata/qemu_1.7.0.x86_64.xml @@ -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> diff --git a/tests/domaincapsschemadata/qemu_2.6.0-gicv2-virt.aarch64.xml b/tests/domaincapsschemadata/qemu_2.6.0-gicv2-virt.aarch64.xml index 8a54f9e..796c3af 100644 --- a/tests/domaincapsschemadata/qemu_2.6.0-gicv2-virt.aarch64.xml +++ b/tests/domaincapsschemadata/qemu_2.6.0-gicv2-virt.aarch64.xml @@ -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> diff --git a/tests/domaincapsschemadata/qemu_2.6.0-gicv3-virt.aarch64.xml b/tests/domaincapsschemadata/qemu_2.6.0-gicv3-virt.aarch64.xml index 8d8087f..5a5f82c 100644 --- a/tests/domaincapsschemadata/qemu_2.6.0-gicv3-virt.aarch64.xml +++ b/tests/domaincapsschemadata/qemu_2.6.0-gicv3-virt.aarch64.xml @@ -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> diff --git a/tests/domaincapsschemadata/qemu_2.6.0.aarch64.xml b/tests/domaincapsschemadata/qemu_2.6.0.aarch64.xml index 83c03db..90b57ff 100644 --- a/tests/domaincapsschemadata/qemu_2.6.0.aarch64.xml +++ b/tests/domaincapsschemadata/qemu_2.6.0.aarch64.xml @@ -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> diff --git a/tests/domaincapsschemadata/qemu_2.6.0.ppc64le.xml b/tests/domaincapsschemadata/qemu_2.6.0.ppc64le.xml index 14a087b..962be6f 100644 --- a/tests/domaincapsschemadata/qemu_2.6.0.ppc64le.xml +++ b/tests/domaincapsschemadata/qemu_2.6.0.ppc64le.xml @@ -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> diff --git a/tests/domaincapsschemadata/qemu_2.6.0.x86_64.xml b/tests/domaincapsschemadata/qemu_2.6.0.x86_64.xml index 4294c64..a8975e8 100644 --- a/tests/domaincapsschemadata/qemu_2.6.0.x86_64.xml +++ b/tests/domaincapsschemadata/qemu_2.6.0.x86_64.xml @@ -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> diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 99971c2..e70fa05 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -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 || -- 2.9.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list