[libvirt PATCH 0/5] qemu: Add support for the kvm-no-adjvtime CPU feature

This ARM-specific CPU feature has been recently added to QEMU with https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg04124.html Patch 1/5 has been trimmed quite liberally: to obtain the unabridged version of this series, use $ git fetch https://gitlab.com/abologna/libvirt kvm-no-adjvtime Andrea Bolognani (5): tests: Add capabilities for QEMU 5.0.0 on aarch64 qemu: Add the QEMU_CAPS_CPU_KVM_NO_ADJVTIME capability cpu: Add the kvm-no-adjvtime CPU feature qemu: Validate the kvm-no-adjvtime CPU feature tests: Add tests for the kvm-no-adjvtime CPU feature src/cpu_map/arm_features.xml | 3 + src/qemu/qemu_capabilities.c | 2 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_domain.c | 14 +- .../qemu_5.0.0-virt.aarch64.xml | 156 + tests/domaincapsdata/qemu_5.0.0.aarch64.xml | 150 + .../caps_5.0.0.aarch64.replies | 22717 ++++++++++++++++ .../caps_5.0.0.aarch64.xml | 457 + .../aarch64-features-misc.aarch64-latest.args | 32 + .../aarch64-features-misc.xml | 17 + tests/qemuxml2argvtest.c | 2 + 11 files changed, 23549 insertions(+), 2 deletions(-) create mode 100644 tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml create mode 100644 tests/domaincapsdata/qemu_5.0.0.aarch64.xml create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml create mode 100644 tests/qemuxml2argvdata/aarch64-features-misc.aarch64-latest.args create mode 100644 tests/qemuxml2argvdata/aarch64-features-misc.xml -- 2.24.1

This is the first QEMU version that supports the kvm-no-adjvtime CPU feature. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- This patch has been trimmed. .../qemu_5.0.0-virt.aarch64.xml | 156 + tests/domaincapsdata/qemu_5.0.0.aarch64.xml | 150 + .../caps_5.0.0.aarch64.replies | 22717 ++++++++++++++++ .../caps_5.0.0.aarch64.xml | 456 + 4 files changed, 23479 insertions(+) create mode 100644 tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml create mode 100644 tests/domaincapsdata/qemu_5.0.0.aarch64.xml create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml diff --git a/tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml b/tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml new file mode 100644 index 0000000000..f92ae951ca --- /dev/null +++ b/tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml @@ -0,0 +1,156 @@ +<domainCapabilities> + <path>/usr/bin/qemu-system-aarch64</path> + <domain>kvm</domain> + <machine>virt-5.0</machine> + <arch>aarch64</arch> [...] diff --git a/tests/domaincapsdata/qemu_5.0.0.aarch64.xml b/tests/domaincapsdata/qemu_5.0.0.aarch64.xml new file mode 100644 index 0000000000..232aacec2f --- /dev/null +++ b/tests/domaincapsdata/qemu_5.0.0.aarch64.xml @@ -0,0 +1,150 @@ +<domainCapabilities> + <path>/usr/bin/qemu-system-aarch64</path> + <domain>kvm</domain> + <machine>integratorcp</machine> + <arch>aarch64</arch> [...] diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies new file mode 100644 index 0000000000..a3136a0966 --- /dev/null +++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies @@ -0,0 +1,22717 @@ +{ + "execute": "qmp_capabilities", + "id": "libvirt-1" +} + +{ + "return": { + }, + "id": "libvirt-1" +} + +{ + "execute": "query-version", + "id": "libvirt-2" +} + +{ + "return": { + "qemu": { + "micro": 50, + "minor": 2, + "major": 4 + }, + "package": "v4.2.0-1157-gadcd6e93b9" + }, + "id": "libvirt-2" +} [...] +{ + "execute": "query-cpu-model-expansion", + "arguments": { + "type": "full", + "model": { + "name": "host" + } + }, + "id": "libvirt-42" +} + +{ + "return": { + "model": { + "name": "host", + "props": { + "sve768": false, + "sve128": false, + "sve1024": false, + "sve1280": false, + "sve896": false, + "sve256": false, + "sve1536": false, + "sve1792": false, + "sve384": false, + "sve": false, + "sve2048": false, + "kvm-no-adjvtime": false, + "sve512": false, + "aarch64": true, + "pmu": true, + "sve1920": false, + "sve1152": false, + "sve640": false, + "sve1408": false, + "sve1664": false + } + } + }, + "id": "libvirt-42" +} [...] diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml new file mode 100644 index 0000000000..538b40dd5b --- /dev/null +++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml @@ -0,0 +1,456 @@ +<qemuCaps> + <emulator>/usr/bin/qemu-system-aarch64</emulator> [...] + <version>4002050</version> + <kvmVersion>0</kvmVersion> + <microcodeVersion>61700241</microcodeVersion> + <package>v4.2.0-1157-gadcd6e93b9</package> + <arch>aarch64</arch> + <hostCPU type='kvm' model='host' migratability='no'> + <property name='sve768' type='boolean' value='false'/> + <property name='sve128' type='boolean' value='false'/> + <property name='sve1024' type='boolean' value='false'/> + <property name='sve1280' type='boolean' value='false'/> + <property name='sve896' type='boolean' value='false'/> + <property name='sve256' type='boolean' value='false'/> + <property name='sve1536' type='boolean' value='false'/> + <property name='sve1792' type='boolean' value='false'/> + <property name='sve384' type='boolean' value='false'/> + <property name='sve' type='boolean' value='false'/> + <property name='sve2048' type='boolean' value='false'/> + <property name='kvm-no-adjvtime' type='boolean' value='false'/> + <property name='sve512' type='boolean' value='false'/> + <property name='aarch64' type='boolean' value='true'/> + <property name='pmu' type='boolean' value='true'/> + <property name='sve1920' type='boolean' value='false'/> + <property name='sve1152' type='boolean' value='false'/> + <property name='sve640' type='boolean' value='false'/> + <property name='sve1408' type='boolean' value='false'/> + <property name='sve1664' type='boolean' value='false'/> + </hostCPU> [...] -- 2.24.1

On Fri, Jan 31, 2020 at 05:39:48PM +0100, Andrea Bolognani wrote:
This is the first QEMU version that supports the kvm-no-adjvtime CPU feature.
s/is/will be/ s/supports/will support/
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
FYI the sign-off is not present in the version you pushed to gitlab.
--- This patch has been trimmed.
.../qemu_5.0.0-virt.aarch64.xml | 156 + tests/domaincapsdata/qemu_5.0.0.aarch64.xml | 150 + .../caps_5.0.0.aarch64.replies | 22717 ++++++++++++++++ .../caps_5.0.0.aarch64.xml | 456 + 4 files changed, 23479 insertions(+) create mode 100644 tests/domaincapsdata/qemu_5.0.0-virt.aarch64.xml create mode 100644 tests/domaincapsdata/qemu_5.0.0.aarch64.xml create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies create mode 100644 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml
diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml new file mode 100644 index 0000000000..538b40dd5b --- /dev/null +++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml @@ -0,0 +1,456 @@ +<qemuCaps> + <emulator>/usr/bin/qemu-system-aarch64</emulator> [...] + <version>4002050</version> + <kvmVersion>0</kvmVersion> + <microcodeVersion>61700241</microcodeVersion> + <package>v4.2.0-1157-gadcd6e93b9</package>
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
+ <arch>aarch64</arch> + <hostCPU type='kvm' model='host' migratability='no'> + <property name='sve768' type='boolean' value='false'/> + <property name='sve128' type='boolean' value='false'/>

On Sun, 2020-02-02 at 14:25 +0100, Ján Tomko wrote:
On Fri, Jan 31, 2020 at 05:39:48PM +0100, Andrea Bolognani wrote:
This is the first QEMU version that supports the kvm-no-adjvtime CPU feature.
s/is/will be/ s/supports/will support/
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
FYI the sign-off is not present in the version you pushed to gitlab.
I have no signed-offs locally, and let git-publish add them at the time I post patches. It's a nice failsafe in case I type the wrong git push incantation by mistake :)
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Thanks, I'll fix the commit message and push this one patch for the moment. -- Andrea Bolognani / Red Hat / Virtualization

We will use this capability to detect whether the QEMU binary supports the kvm-no-adjvtime CPU feature. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml | 1 + 3 files changed, 4 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 8b7fde2bcc..4aa77c787d 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -559,6 +559,7 @@ VIR_ENUM_IMPL(virQEMUCaps, "i8042", "rng-builtin", "virtio-net.failover", + "cpu.kvm-no-adjvtime", ); @@ -1561,6 +1562,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsMemoryBackendMemfd[] static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsMaxCPU[] = { { "unavailable-features", QEMU_CAPS_CPU_UNAVAILABLE_FEATURES }, + { "kvm-no-adjvtime", QEMU_CAPS_CPU_KVM_NO_ADJVTIME }, }; static virQEMUCapsObjectTypeProps virQEMUCapsObjectProps[] = { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index d86f54a481..db2334d4bf 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -540,6 +540,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */ QEMU_CAPS_DEVICE_I8042, /* PS/2 controller */ QEMU_CAPS_OBJECT_RNG_BUILTIN, /* -object rng-builtin */ QEMU_CAPS_VIRTIO_NET_FAILOVER, /* virtio-net-*.failover */ + QEMU_CAPS_CPU_KVM_NO_ADJVTIME, /* -cpu ...,kvm-no-adjvtime */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml index 538b40dd5b..c05cea2eb7 100644 --- a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml @@ -179,6 +179,7 @@ <flag name='smp-dies'/> <flag name='rng-builtin'/> <flag name='virtio-net.failover'/> + <flag name='cpu.kvm-no-adjvtime'/> <version>4002050</version> <kvmVersion>0</kvmVersion> <microcodeVersion>61700241</microcodeVersion> -- 2.24.1

On Fri, Jan 31, 2020 at 05:39:49PM +0100, Andrea Bolognani wrote:
We will use this capability to detect whether the QEMU binary supports the kvm-no-adjvtime CPU feature.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml | 1 + 3 files changed, 4 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The feature is currently available on ARM only, and so it only needs to be known to the corresponding CPU driver. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/cpu_map/arm_features.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cpu_map/arm_features.xml b/src/cpu_map/arm_features.xml index 8a53384463..13d00f07a8 100644 --- a/src/cpu_map/arm_features.xml +++ b/src/cpu_map/arm_features.xml @@ -19,4 +19,7 @@ <feature name='sve1920'/> <feature name='sve2048'/> + <!-- Other features --> + <feature name='kvm-no-adjvtime'/> + </cpus> -- 2.24.1

On Fri, Jan 31, 2020 at 05:39:50PM +0100, Andrea Bolognani wrote:
The feature is currently available on ARM only, and so it only needs to be known to the corresponding CPU driver.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/cpu_map/arm_features.xml | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/src/cpu_map/arm_features.xml b/src/cpu_map/arm_features.xml index 8a53384463..13d00f07a8 100644 --- a/src/cpu_map/arm_features.xml +++ b/src/cpu_map/arm_features.xml @@ -19,4 +19,7 @@ <feature name='sve1920'/> <feature name='sve2048'/>
+ <!-- Other features --> + <feature name='kvm-no-adjvtime'/>
I think just like other kvm* features, this would fit better in the hypervisor features element, not the CPU driver. Jano
+ </cpus> -- 2.24.1

On Sun, 2020-02-02 at 14:40 +0100, Ján Tomko wrote:
On Fri, Jan 31, 2020 at 05:39:50PM +0100, Andrea Bolognani wrote:
+ <!-- Other features --> + <feature name='kvm-no-adjvtime'/>
I think just like other kvm* features, this would fit better in the hypervisor features element, not the CPU driver.
You're right, it does sound like a better fit. I'll look into it. -- Andrea Bolognani / Red Hat / Virtualization

Error out if the QEMU binary doesn't support it. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_domain.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d3045b4bcd..8b0c91d6c1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4625,7 +4625,8 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def, static int -qemuDomainDefCPUPostParse(virDomainDefPtr def) +qemuDomainDefCPUPostParse(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps) { virCPUFeatureDefPtr sveFeature = NULL; bool sveVectorLengthsProvided = false; @@ -4696,6 +4697,15 @@ qemuDomainDefCPUPostParse(virDomainDefPtr def) } else if (STRPREFIX(feature->name, "sve")) { sveVectorLengthsProvided = true; } + + if (STREQ(feature->name, "kvm-no-adjvtime") && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_KVM_NO_ADJVTIME)) + { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("The '%s' feature is not supported by this " + "QEMU binary"), feature->name); + return -1; + } } if (sveVectorLengthsProvided) { @@ -4858,7 +4868,7 @@ qemuDomainDefPostParse(virDomainDefPtr def, if (qemuDomainDefVcpusPostParse(def) < 0) return -1; - if (qemuDomainDefCPUPostParse(def) < 0) + if (qemuDomainDefCPUPostParse(def, qemuCaps) < 0) return -1; if (qemuDomainDefTsegPostParse(def, qemuCaps) < 0) -- 2.24.1

On Fri, Jan 31, 2020 at 05:39:51PM +0100, Andrea Bolognani wrote:
Error out if the QEMU binary doesn't support it.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_domain.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d3045b4bcd..8b0c91d6c1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4625,7 +4625,8 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
static int -qemuDomainDefCPUPostParse(virDomainDefPtr def) +qemuDomainDefCPUPostParse(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps) { virCPUFeatureDefPtr sveFeature = NULL; bool sveVectorLengthsProvided = false; @@ -4696,6 +4697,15 @@ qemuDomainDefCPUPostParse(virDomainDefPtr def) } else if (STRPREFIX(feature->name, "sve")) { sveVectorLengthsProvided = true; } + + if (STREQ(feature->name, "kvm-no-adjvtime") && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_KVM_NO_ADJVTIME)) + { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("The '%s' feature is not supported by this " + "QEMU binary"), feature->name); + return -1;
Either qemuDomain.*Validate or qemuProcessVerifyCPU would be a better place for this check. Jano
+ } }

Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- .../aarch64-features-misc.aarch64-latest.args | 32 +++++++++++++++++++ .../aarch64-features-misc.xml | 17 ++++++++++ tests/qemuxml2argvtest.c | 2 ++ 3 files changed, 51 insertions(+) create mode 100644 tests/qemuxml2argvdata/aarch64-features-misc.aarch64-latest.args create mode 100644 tests/qemuxml2argvdata/aarch64-features-misc.xml diff --git a/tests/qemuxml2argvdata/aarch64-features-misc.aarch64-latest.args b/tests/qemuxml2argvdata/aarch64-features-misc.aarch64-latest.args new file mode 100644 index 0000000000..f1d1017d59 --- /dev/null +++ b/tests/qemuxml2argvdata/aarch64-features-misc.aarch64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-guest \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-guest/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-guest/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-aarch64 \ +-name guest=guest,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-guest/master-key.aes \ +-machine virt,accel=kvm,usb=off,dump-guest-core=off,gic-version=3 \ +-cpu host,kvm-no-adjvtime=on \ +-m 1024 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/aarch64-features-misc.xml b/tests/qemuxml2argvdata/aarch64-features-misc.xml new file mode 100644 index 0000000000..49e197ad87 --- /dev/null +++ b/tests/qemuxml2argvdata/aarch64-features-misc.xml @@ -0,0 +1,17 @@ +<domain type='kvm'> + <name>guest</name> + <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid> + <memory unit='KiB'>1048576</memory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='aarch64' machine='virt'>hvm</type> + </os> + <cpu mode='host-passthrough'> + <feature policy='require' name='kvm-no-adjvtime'/> + </cpu> + <devices> + <emulator>/usr/bin/qemu-system-aarch64</emulator> + <controller type='usb' model='none'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index a36183bf34..81b82bcd1f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2725,6 +2725,8 @@ mymain(void) /* SVE aarch64 CPU features work on modern QEMU */ DO_TEST_CAPS_ARCH_LATEST("aarch64-features-sve", "aarch64"); + DO_TEST_CAPS_ARCH_LATEST("aarch64-features-misc", "aarch64"); + qemuTestSetHostArch(&driver, VIR_ARCH_NONE); DO_TEST("kvm-pit-delay", QEMU_CAPS_KVM_PIT_TICK_POLICY); -- 2.24.1
participants (2)
-
Andrea Bolognani
-
Ján Tomko