Re: [PATCH v2 31/31] qemu: Store default CPU in domain XML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 15, 2019 at 05:35:07PM +0200, Jiri Denemark wrote:
When starting a domain without a CPU model specified in the domain XML,
QEMU will choose a default one. Which is fine unless the domain gets
migrated to another host because libvirt doesn't perform any CPU ABI
checks and the virtual CPU provided by QEMU on the destination host can
differ from the one on the source host.

With QEMU 4.2.0 we can probe for the default CPU model used by QEMU for
a particular machine type and store it in the domain XML. This way the
chosen CPU model is more visible to users and libvirt will make sure
the guest will see the exact same CPU after migration.

Architecture specific notes
- aarch64: We only set the default CPU for TCG domains as KVM requires
 -cpu host to work.

- ppc64: (to be checked with QEMU developers) Default CPU data reported
 by QEMU is unusable for KVM. QEMU would effectively use -cpu host by
 default and it even rewrites typename of the current host CPU model to
 host-powerpc64-cpu. The default CPU type reported by query-machines is
 still power*-powerpc64-cpu, which may not even exist due to the
 changed typename. For example, on a Power8 host, power8 CPU model is
 of host-powerpc64-cpu type (according to query-cpu-definitions), while
 the default CPU type name for pseries-3.1 machine type is reported as
 power8_v2.0-powerpc64-cpu. What's even worse, pseries-4.2 says the
 default CPU type is power9_v2.0-powerpc64-cpu, which cannot be started
 on older host at all. So again, we only set the default CPU for TCG
 domains.

- s390x: (to be checked with QEMU developers) The default CPU is said to
 be "qemu", which works fine for TCG domains, but it doesn't work on
 KVM because QEMU complains that some features requested in the CPU
 model are not available.

- x86_64: The default CPU model (qemu64) is not runnable on any host
 with KVM, but in contrast to s390x QEMU just disables unavailable
 features and starts happily.

https://bugzilla.redhat.com/show_bug.cgi?id=1598151
https://bugzilla.redhat.com/show_bug.cgi?id=1598162
---

Notes:
   This patch should not be merged yet as we need to confirm what to do
   on s390x and ppc64 architectures.

   Version 2:
   - new test cases

src/qemu/qemu_domain.c                        | 56 +++++++++++++++++++
...fault-cpu-tcg-virt-4.2.aarch64-latest.args |  1 +
.../disk-cache.x86_64-latest.args             |  1 +
.../disk-cdrom-network.x86_64-latest.args     |  1 +
.../disk-cdrom-tray.x86_64-latest.args        |  1 +
.../disk-copy_on_read.x86_64-latest.args      |  1 +
.../disk-detect-zeroes.x86_64-latest.args     |  1 +
.../disk-floppy-q35-2_11.x86_64-latest.args   |  1 +
.../disk-floppy-q35-2_9.x86_64-latest.args    |  1 +
.../os-firmware-bios.x86_64-latest.args       |  1 +
...os-firmware-efi-secboot.x86_64-latest.args |  1 +
.../os-firmware-efi.x86_64-latest.args        |  1 +
...ault-cpu-tcg-pseries-2.7.ppc64-latest.args |  1 +
...ault-cpu-tcg-pseries-3.1.ppc64-latest.args |  1 +
...ault-cpu-tcg-pseries-4.2.ppc64-latest.args |  1 +
...t-cpu-tcg-ccw-virtio-4.2.s390x-latest.args |  1 +
.../tpm-emulator-tpm2-enc.x86_64-latest.args  |  1 +
.../tpm-emulator-tpm2.x86_64-latest.args      |  1 +
.../tpm-emulator.x86_64-latest.args           |  1 +
.../tseg-explicit-size.x86_64-latest.args     |  1 +
.../vhost-vsock-auto.x86_64-latest.args       |  1 +
.../vhost-vsock.x86_64-latest.args            |  1 +
...-default-cpu-kvm-pc-4.2.x86_64-latest.args |  1 +
...default-cpu-kvm-q35-4.2.x86_64-latest.args |  1 +
...-default-cpu-tcg-pc-4.2.x86_64-latest.args |  1 +
...default-cpu-tcg-q35-4.2.x86_64-latest.args |  1 +
...efault-cpu-tcg-virt-4.2.aarch64-latest.xml |  3 +
.../os-firmware-bios.x86_64-latest.xml        |  3 +
.../os-firmware-efi-secboot.x86_64-latest.xml |  3 +
.../os-firmware-efi.x86_64-latest.xml         |  3 +
...fault-cpu-tcg-pseries-2.7.ppc64-latest.xml |  3 +
...fault-cpu-tcg-pseries-3.1.ppc64-latest.xml |  3 +
...fault-cpu-tcg-pseries-4.2.ppc64-latest.xml |  3 +
...lt-cpu-tcg-ccw-virtio-4.2.s390x-latest.xml |  3 +
.../tpm-emulator-tpm2-enc.x86_64-latest.xml   |  3 +
.../tpm-emulator-tpm2.x86_64-latest.xml       |  3 +
.../tpm-emulator.x86_64-latest.xml            |  3 +
.../tpm-passthrough-crb.x86_64-latest.xml     |  3 +
.../tpm-passthrough.x86_64-latest.xml         |  3 +
...4-default-cpu-kvm-pc-4.2.x86_64-latest.xml |  3 +
...-default-cpu-kvm-q35-4.2.x86_64-latest.xml |  3 +
...4-default-cpu-tcg-pc-4.2.x86_64-latest.xml |  3 +
...-default-cpu-tcg-q35-4.2.x86_64-latest.xml |  3 +
43 files changed, 132 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9dcba4ef38..438f003186 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4470,6 +4470,59 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def)
}


+static int
+qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
+                           virQEMUCapsPtr qemuCaps)
+{
+    VIR_AUTOPTR(virCPUDef) newCPU = NULL;

g_autoptr

+    virCPUDefPtr cpu = def->cpu;
+    const char *model;
+
+    if (cpu &&
+        (cpu->mode != VIR_CPU_MODE_CUSTOM ||
+         cpu->model))
+        return 0;
+
+    /* Default CPU model info from QEMU is usable for TCG only on non-Intel
+     * architectures. */
+    if (!ARCH_IS_X86(def->os.arch) && def->virtType != VIR_DOMAIN_VIRT_QEMU)
+        return 0;
+
+    model = virQEMUCapsGetMachineDefaultCPU(qemuCaps, def->os.machine, def->virtType);
+    if (!model) {
+        VIR_DEBUG("Unknown default CPU model for domain '%s'", def->name);
+        return 0;
+    }
+
+    VIR_DEBUG("Setting default CPU model for domain '%s' to %s",
+              def->name, model);
+
+    if (!cpu) {
+        if (VIR_ALLOC(newCPU) < 0)
+            return -1;
+        cpu = newCPU;

cpu = g_new0(virCPUDef, 1);

+    }
+
+    /* We need to turn off all CPU checks when the domain is started because
+     * the default CPU (e.g., qemu64) may not be runnable on any host. QEMU
+     * will just disable the unavailable features and we will update the CPU
+     * definition accordingly and set check to FULL when starting the domain. */
+    cpu->type = VIR_CPU_TYPE_GUEST;
+    cpu->mode = VIR_CPU_MODE_CUSTOM;
+    cpu->match = VIR_CPU_MATCH_EXACT;
+    cpu->check = VIR_CPU_CHECK_NONE;
+    cpu->fallback = VIR_CPU_FALLBACK_FORBID;
+
+    if (VIR_STRDUP(cpu->model, model) < 0)
+        return -1;

g_strdup

+
+    if (newCPU)
+        VIR_STEAL_PTR(def->cpu, newCPU);

g_strdup_pointer, or just don't steal it and use def->cpu directly

+
+    return 0;
+}
+
+
static int
qemuDomainDefCPUPostParse(virDomainDefPtr def)
{

Jano

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux