On s390 machines host-passthrough and host-model CPUs result in the same guest ABI (with QEMU new enough to be able to tell us what "host" CPU is expanded to, which was implemented around 2.9.0). So instead of using host-passthrough CPU when there's no CPU specified in a domain XML we can safely use host-model and benefit from CPU compatibility checks during migration, snapshot restore and similar operations. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/qemu/qemu_domain.c | 33 ++++++++++++------- ...t-cpu-kvm-ccw-virtio-4.2.s390x-latest.args | 4 ++- ...lt-cpu-kvm-ccw-virtio-4.2.s390x-latest.xml | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8bd05f4058..e5269e6300 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4440,6 +4440,7 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def) static int qemuDomainDefSetDefaultCPU(virDomainDefPtr def, + virCapsPtr caps, virQEMUCapsPtr qemuCaps) { const char *model; @@ -4470,26 +4471,36 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def, 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; + if (ARCH_IS_S390(def->os.arch) && + virQEMUCapsIsCPUModeSupported(qemuCaps, caps, def->virtType, + VIR_CPU_MODE_HOST_MODEL)) { + def->cpu->mode = VIR_CPU_MODE_HOST_MODEL; + } else { + def->cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH; + } + + VIR_DEBUG("Setting default CPU mode for domain '%s' to %s", + def->name, virCPUModeTypeToString(def->cpu->mode)); } else { + /* 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->check = VIR_CPU_CHECK_NONE; 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); + + VIR_DEBUG("Setting default CPU model for domain '%s' to %s", + def->name, model); } return 0; @@ -4674,7 +4685,7 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def, static int qemuDomainDefPostParse(virDomainDefPtr def, - virCapsPtr caps G_GNUC_UNUSED, + virCapsPtr caps, unsigned int parseFlags, void *opaque, void *parseOpaque) @@ -4706,7 +4717,7 @@ qemuDomainDefPostParse(virDomainDefPtr def, if (qemuCanonicalizeMachine(def, qemuCaps) < 0) return -1; - if (qemuDomainDefSetDefaultCPU(def, qemuCaps) < 0) + if (qemuDomainDefSetDefaultCPU(def, caps, qemuCaps) < 0) return -1; qemuDomainDefEnableDefaultFeatures(def, qemuCaps); diff --git a/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args b/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args index 4b7345630b..0386019418 100644 --- a/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args +++ b/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args @@ -13,7 +13,9 @@ 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 \ +-cpu z13.2-base,aen=on,aefsi=on,msa5=on,msa4=on,msa3=on,msa2=on,msa1=on,\ +sthyi=on,edat=on,ri=on,edat2=on,vx=on,ipter=on,ap=on,esop=on,apft=on,apqci=on,\ +cte=on,bpb=on,ppa15=on,zpci=on,sea_esop2=on,te=on,cmm=on \ -m 256 \ -overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ diff --git a/tests/qemuxml2xmloutdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.xml b/tests/qemuxml2xmloutdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.xml index eec5051934..1cc2edd893 100644 --- a/tests/qemuxml2xmloutdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.xml +++ b/tests/qemuxml2xmloutdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.xml @@ -8,7 +8,7 @@ <type arch='s390x' machine='s390-ccw-virtio-4.2'>hvm</type> <boot dev='hd'/> </os> - <cpu mode='host-passthrough' check='none'/> + <cpu mode='host-model' check='partial'/> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> -- 2.24.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list