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

2019-10-16 Thread Ján Tomko

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;
+

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

2019-10-15 Thread Jiri Denemark
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;
+virCPUDefPtr cpu = def->cpu;
+con