提交 5e939cea 编写于 作者: J Jiri Denemark

qemu: Store default CPU in domain XML

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
  explicit "-cpu host" to work.

- ppc64: The default CPU for KVM is "host" thanks to some hacks in QEMU,
  we will translate the default model to the model corresponding to the
  host CPU ("POWER8" on a Power8 host, "POWER9" on Power9 host, etc.).
  This is not a problem as the corresponding CPU model is in fact an
  alias for "host". This is probably not ideal, but it's not wrong and
  the default virtual CPU configured by libvirt is the same QEMU would
  use. TCG uses various CPU models depending on machine type and its
  version.

- s390x: The default CPU for KVM is "host" while TCG defaults to "qemu".

- x86_64: The default CPU model (qemu64) is not runnable on any host
  with KVM, but 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=1598162Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 4a79d391
......@@ -4429,6 +4429,64 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def)
}
static int
qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps)
{
const char *model;
if (def->cpu &&
(def->cpu->mode != VIR_CPU_MODE_CUSTOM ||
def->cpu->model))
return 0;
/* Default CPU model info from QEMU is usable for TCG only except for
* x86, s390, and ppc64. */
if (!ARCH_IS_X86(def->os.arch) &&
!ARCH_IS_S390(def->os.arch) &&
!ARCH_IS_PPC64(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;
}
if (STREQ(model, "host") && def->virtType != VIR_DOMAIN_VIRT_KVM) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("QEMU reports invalid default CPU model \"host\" "
"for non-kvm domain virt type"));
return -1;
}
VIR_DEBUG("Setting default CPU model for domain '%s' to %s",
def->name, model);
if (!def->cpu)
def->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. */
def->cpu->type = VIR_CPU_TYPE_GUEST;
def->cpu->check = VIR_CPU_CHECK_NONE;
if (STREQ(model, "host")) {
def->cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH;
} else {
def->cpu->mode = VIR_CPU_MODE_CUSTOM;
def->cpu->match = VIR_CPU_MATCH_EXACT;
def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
def->cpu->model = g_strdup(model);
}
return 0;
}
static int
qemuDomainDefCPUPostParse(virDomainDefPtr def)
{
......@@ -4639,6 +4697,9 @@ qemuDomainDefPostParse(virDomainDefPtr def,
if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
return -1;
if (qemuDomainDefSetDefaultCPU(def, qemuCaps) < 0)
return -1;
qemuDomainDefEnableDefaultFeatures(def, qemuCaps);
if (qemuDomainRecheckInternalPaths(def, cfg, parseFlags) < 0)
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine virt-4.2,accel=tcg,usb=off,dump-guest-core=off,gic-version=2 \
-cpu cortex-a15 \
-m 4096 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-machine pc-i440fx-2.6,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 214 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-machine pc-1.2,accel=kvm,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 1024 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-test/master-key.aes \
-machine pc-0.13,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 1024 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-test/master-key.aes \
-machine pc-0.13,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 1024 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-test/master-key.aes \
-machine pc-0.13,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 1024 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-machine pc-q35-2.11,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 214 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-machine pc-q35-2.9,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 214 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-fedora/master-key.aes \
-machine pc-q35-4.0,accel=kvm,usb=off,dump-guest-core=off \
-cpu qemu64 \
-bios /usr/share/seabios/bios-256k.bin \
-m 8 \
-overcommit mem-lock=off \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-fedora/master-key.aes \
-machine pc-q35-4.0,accel=kvm,usb=off,smm=on,dump-guest-core=off \
-cpu qemu64 \
-global driver=cfi.pflash01,property=secure,value=on \
-drive file=/usr/share/OVMF/OVMF_CODE.secboot.fd,if=pflash,format=raw,unit=0,\
readonly=on \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-fedora/master-key.aes \
-machine pc-q35-4.0,accel=kvm,usb=off,smm=on,dump-guest-core=off \
-cpu qemu64 \
-drive file=/usr/share/OVMF/OVMF_CODE.secboot.fd,if=pflash,format=raw,unit=0,\
readonly=on \
-drive file=/var/lib/libvirt/qemu/nvram/fedora_VARS.fd,if=pflash,format=raw,\
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pseries-2.7,accel=kvm,usb=off,dump-guest-core=off \
-cpu POWER8 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pseries-3.1,accel=kvm,usb=off,dump-guest-core=off \
-cpu POWER8 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pseries-4.2,accel=kvm,usb=off,dump-guest-core=off \
-cpu POWER8 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pseries-2.7,accel=tcg,usb=off,dump-guest-core=off \
-cpu POWER7 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pseries-3.1,accel=tcg,usb=off,dump-guest-core=off \
-cpu POWER8 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pseries-4.2,accel=tcg,usb=off,dump-guest-core=off \
-cpu POWER9 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-test/master-key.aes \
-machine s390-ccw-virtio-4.2,accel=kvm,usb=off,dump-guest-core=off \
-cpu host \
-m 256 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-test/master-key.aes \
-machine s390-ccw-virtio-4.2,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu \
-m 256 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-TPM-VM/master-key.aes \
-machine pc-i440fx-2.12,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 2048 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-TPM-VM/master-key.aes \
-machine pc-i440fx-2.12,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 2048 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-TPM-VM/master-key.aes \
-machine pc-i440fx-2.12,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 2048 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -14,6 +14,7 @@ QEMU_AUDIO_DRV=none \
file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-machine pc-q35-2.10,accel=tcg,usb=off,smm=on,dump-guest-core=off \
-global mch.extended-tseg-mbytes=48 \
-cpu qemu64 \
-m 214 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-test/master-key.aes \
-machine pc-i440fx-2.9,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 1024 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-test/master-key.aes \
-machine pc-0.13,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 1024 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pc-i440fx-4.2,accel=kvm,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pc-q35-4.2,accel=kvm,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pc-i440fx-4.2,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-guest/master-key.aes \
-machine pc-q35-4.2,accel=tcg,usb=off,dump-guest-core=off \
-cpu qemu64 \
-m 4096 \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
......
......@@ -11,6 +11,9 @@
<features>
<gic version='2'/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>cortex-a15</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -16,6 +16,9 @@
<apic/>
<pae/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -16,6 +16,9 @@
<apic/>
<pae/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -16,6 +16,9 @@
<apic/>
<pae/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,9 @@
<type arch='ppc64' machine='pseries-2.7'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>POWER8</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,9 @@
<type arch='ppc64' machine='pseries-3.1'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>POWER8</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,9 @@
<type arch='ppc64' machine='pseries-4.2'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>POWER8</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,9 @@
<type arch='ppc64' machine='pseries-2.7'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>POWER7</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,9 @@
<type arch='ppc64' machine='pseries-3.1'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>POWER8</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,9 @@
<type arch='ppc64' machine='pseries-4.2'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>POWER9</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,7 @@
<type arch='s390x' machine='s390-ccw-virtio-4.2'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='host-passthrough' check='none'/>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -8,6 +8,9 @@
<type arch='s390x' machine='s390-ccw-virtio-4.2'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<features>
<acpi/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<features>
<acpi/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<features>
<acpi/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<features>
<acpi/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<features>
<acpi/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
......@@ -12,6 +12,9 @@
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册