diff -Nru qemu-2.5+dfsg/debian/changelog qemu-2.5+dfsg/debian/changelog --- qemu-2.5+dfsg/debian/changelog 2016-05-10 17:15:08.000000000 +0000 +++ qemu-2.5+dfsg/debian/changelog 2016-05-19 19:11:26.000000000 +0000 @@ -1,3 +1,10 @@ +qemu (1:2.5+dfsg-5ubuntu10.2) UNRELEASED; urgency=medium + + * Cherrypick upstream patches to support the query-gic-version QMP command + (LP: #1566564) + + -- dann frazier Thu, 19 May 2016 13:00:21 -0600 + qemu (1:2.5+dfsg-5ubuntu10.1) xenial-security; urgency=medium * SECURITY UPDATE: denial of service via multiple eof_timers in ohci diff -Nru qemu-2.5+dfsg/debian/patches/series qemu-2.5+dfsg/debian/patches/series --- qemu-2.5+dfsg/debian/patches/series 2016-05-10 16:58:52.000000000 +0000 +++ qemu-2.5+dfsg/debian/patches/series 2016-05-19 18:59:11.000000000 +0000 @@ -40,3 +40,7 @@ CVE-2016-4002.patch CVE-2016-4020.patch CVE-2016-4037.patch +ubuntu/arm-qmp-add-query-gic-capabilities-interface.patch +ubuntu/arm-enhance-kvm_arm_create_scratch_host_vcpu.patch +ubuntu/kvm-add-kvm_device_supported-helper-function.patch +ubuntu/arm-implement-query-gic-capabilities.patch diff -Nru qemu-2.5+dfsg/debian/patches/ubuntu/arm-enhance-kvm_arm_create_scratch_host_vcpu.patch qemu-2.5+dfsg/debian/patches/ubuntu/arm-enhance-kvm_arm_create_scratch_host_vcpu.patch --- qemu-2.5+dfsg/debian/patches/ubuntu/arm-enhance-kvm_arm_create_scratch_host_vcpu.patch 1970-01-01 00:00:00.000000000 +0000 +++ qemu-2.5+dfsg/debian/patches/ubuntu/arm-enhance-kvm_arm_create_scratch_host_vcpu.patch 2016-05-19 19:27:06.000000000 +0000 @@ -0,0 +1,78 @@ +From: Peter Xu +Date: Wed, 30 Mar 2016 17:27:24 +0100 +Subject: [PATCH] arm: enhance kvm_arm_create_scratch_host_vcpu + +Support passing NULL for the first parameter (with the same effect +as passing an empty array) and for the third parameter (meaning +that we should not attempt to init the vcpu). + +Signed-off-by: Peter Xu +Acked-by: Sergey Fedorov +Message-id: 1458788142-17509-3-git-send-email-peterx@redhat.com +[PMM: tweaked commit message, comment] +Reviewed-by: Peter Maydell +Signed-off-by: Peter Maydell + +Origin: http://git.qemu.org/?p=qemu.git;a=commitdiff;h=2f340e9c24e3af17ad376d27a41830387999c285 +Bug-Ubuntu: http://bugs.launchpad.net/bugs/1566564 +Last-Updated: 2016-05-19 + +diff --git a/target-arm/kvm.c b/target-arm/kvm.c +index 969ab0b..3671032 100644 +--- a/target-arm/kvm.c ++++ b/target-arm/kvm.c +@@ -62,13 +62,18 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, + goto err; + } + ++ if (!init) { ++ /* Caller doesn't want the VCPU to be initialized, so skip it */ ++ goto finish; ++ } ++ + ret = ioctl(vmfd, KVM_ARM_PREFERRED_TARGET, init); + if (ret >= 0) { + ret = ioctl(cpufd, KVM_ARM_VCPU_INIT, init); + if (ret < 0) { + goto err; + } +- } else { ++ } else if (cpus_to_try) { + /* Old kernel which doesn't know about the + * PREFERRED_TARGET ioctl: we know it will only support + * creating one kind of guest CPU which is its preferred +@@ -85,8 +90,15 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, + if (ret < 0) { + goto err; + } ++ } else { ++ /* Treat a NULL cpus_to_try argument the same as an empty ++ * list, which means we will fail the call since this must ++ * be an old kernel which doesn't support PREFERRED_TARGET. ++ */ ++ goto err; + } + ++finish: + fdarray[0] = kvmfd; + fdarray[1] = vmfd; + fdarray[2] = cpufd; +diff --git a/target-arm/kvm_arm.h b/target-arm/kvm_arm.h +index 07f0c72..345233c 100644 +--- a/target-arm/kvm_arm.h ++++ b/target-arm/kvm_arm.h +@@ -124,9 +124,12 @@ void kvm_arm_reset_vcpu(ARMCPU *cpu); + * kvm_arm_create_scratch_host_vcpu: + * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with + * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not +- * know the PREFERRED_TARGET ioctl ++ * know the PREFERRED_TARGET ioctl. Passing NULL is the same as passing ++ * an empty array. + * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order +- * @init: filled in with the necessary values for creating a host vcpu ++ * @init: filled in with the necessary values for creating a host ++ * vcpu. If NULL is provided, will not init the vCPU (though the cpufd ++ * will still be set up). + * + * Create a scratch vcpu in its own VM of the type preferred by the host + * kernel (as would be used for '-cpu host'), for purposes of probing it diff -Nru qemu-2.5+dfsg/debian/patches/ubuntu/arm-implement-query-gic-capabilities.patch qemu-2.5+dfsg/debian/patches/ubuntu/arm-implement-query-gic-capabilities.patch --- qemu-2.5+dfsg/debian/patches/ubuntu/arm-implement-query-gic-capabilities.patch 1970-01-01 00:00:00.000000000 +0000 +++ qemu-2.5+dfsg/debian/patches/ubuntu/arm-implement-query-gic-capabilities.patch 2016-05-19 19:24:29.000000000 +0000 @@ -0,0 +1,88 @@ +From: Peter Xu +Date: Wed, 30 Mar 2016 17:27:24 +0100 +Subject: [PATCH] arm: implement query-gic-capabilities + +For emulated GIC capabilities, currently only gicv2 is supported. We +need to add gicv3 in when emulated gicv3 ready. For KVM accelerated ARM +VM, we detect the capability bits by creating a scratch VM. + +Signed-off-by: Peter Xu +Acked-by: Sergey Fedorov +Message-id: 1458788142-17509-5-git-send-email-peterx@redhat.com +Reviewed-by: Peter Maydell +Signed-off-by: Peter Maydell + +Origin: http://git.qemu.org/?p=qemu.git;a=commitdiff;h=db31e49a565fc4c165fd98201721b313c3412c1f +Bug-Ubuntu: http://bugs.launchpad.net/bugs/1566564 +Last-Updated: 2016-05-19 + +diff --git a/target-arm/monitor.c b/target-arm/monitor.c +index 4c9bef3..1ee59a2 100644 +--- a/target-arm/monitor.c ++++ b/target-arm/monitor.c +@@ -21,8 +21,64 @@ + */ + #include "qemu/osdep.h" + #include "qmp-commands.h" ++#include "hw/boards.h" ++#include "kvm_arm.h" ++ ++static GICCapability *gic_cap_new(int version) ++{ ++ GICCapability *cap = g_new0(GICCapability, 1); ++ cap->version = version; ++ /* by default, support none */ ++ cap->emulated = false; ++ cap->kernel = false; ++ return cap; ++} ++ ++static GICCapabilityList *gic_cap_list_add(GICCapabilityList *head, ++ GICCapability *cap) ++{ ++ GICCapabilityList *item = g_new0(GICCapabilityList, 1); ++ item->value = cap; ++ item->next = head; ++ return item; ++} ++ ++static inline void gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3) ++{ ++#ifdef CONFIG_KVM ++ int fdarray[3]; ++ ++ if (!kvm_arm_create_scratch_host_vcpu(NULL, fdarray, NULL)) { ++ return; ++ } ++ ++ /* Test KVM GICv2 */ ++ if (kvm_device_supported(fdarray[1], KVM_DEV_TYPE_ARM_VGIC_V2)) { ++ v2->kernel = true; ++ } ++ ++ /* Test KVM GICv3 */ ++ if (kvm_device_supported(fdarray[1], KVM_DEV_TYPE_ARM_VGIC_V3)) { ++ v3->kernel = true; ++ } ++ ++ kvm_arm_destroy_scratch_host_vcpu(fdarray); ++#endif ++} + + GICCapabilityList *qmp_query_gic_capabilities(Error **errp) + { +- return NULL; ++ GICCapabilityList *head = NULL; ++ GICCapability *v2 = gic_cap_new(2), *v3 = gic_cap_new(3); ++ ++ v2->emulated = true; ++ /* TODO: we'd change to true after we get emulated GICv3. */ ++ v3->emulated = false; ++ ++ gic_cap_kvm_probe(v2, v3); ++ ++ head = gic_cap_list_add(head, v2); ++ head = gic_cap_list_add(head, v3); ++ ++ return head; + } diff -Nru qemu-2.5+dfsg/debian/patches/ubuntu/arm-qmp-add-query-gic-capabilities-interface.patch qemu-2.5+dfsg/debian/patches/ubuntu/arm-qmp-add-query-gic-capabilities-interface.patch --- qemu-2.5+dfsg/debian/patches/ubuntu/arm-qmp-add-query-gic-capabilities-interface.patch 1970-01-01 00:00:00.000000000 +0000 +++ qemu-2.5+dfsg/debian/patches/ubuntu/arm-qmp-add-query-gic-capabilities-interface.patch 2016-05-19 19:28:36.000000000 +0000 @@ -0,0 +1,194 @@ +From: Peter Xu +Date: Wed, 30 Mar 2016 17:27:24 +0100 +Subject: [PATCH] arm: qmp: add query-gic-capabilities interface + +This patch add "query-gic-capabilities" but does not implement it. The +command is ARM-only. The command will return a list of GICCapability +structs that describes all GIC versions that current QEMU and system +support. + +Libvirt is possibly the first consumer of this new command. + +Before this patch, a libvirt user can successfully configure all kinds +of GIC devices for ARM guests, no matter whether current QEMU/kernel +supports them. If the specified GIC version/type is not supported, the +user will get an ambiguous "QEMU boot failure" error when trying to start +the VM. This is not user-friendly. + +With this patch, libvirt should be able to query which type (and which +version) of GIC device is supported. Using this information, libvirt +can warn the user during configuration of guests when specified GIC +device type is not supported. Or better, we can just list those versions +that we support, and filter out the unsupported ones. + +For example, if we got the query result: + +{"return": [{"emulated": false, "version": 3, "kernel": true}, + {"emulated": true, "version": 2, "kernel": false}]} + +then it means that we support emulated GIC version 2 using: + + qemu-system-aarch64 -M virt,accel=tcg,gic-version=2 ... + +or KVM-accelerated GIC version 3 using: + + qemu-system-aarch64 -M virt,accel=kvm,gic-version=3 ... + +If we specify other explicit GIC versions rather than the above, QEMU +will not be able to boot. + +The community is working on a more generic way to query these kinds of +information about valid values of machine properties. However, due to +the importance of supporting this specific use case, weecided to first +implement this ad-hoc one; then when the generic method is ready, we +can move on to that one smoothly. + +Signed-off-by: Peter Xu +Reviewed-by: Eric Blake +Message-id: 1458788142-17509-2-git-send-email-peterx@redhat.com +[PMM: tweaked commit message a bit; monitor.o is CONFIG_SOFTMMU only] +Signed-off-by: Peter Maydell + +Origin: http://git.qemu.org/?p=qemu.git;a=commitdiff;h=ae50a7702c871638c5b650f501325031dfc511cb +Bug-Ubuntu: http://bugs.launchpad.net/bugs/1566564 +Last-Updated: 2016-05-19 + +Index: qemu.debian/monitor.c +=================================================================== +--- qemu.debian.orig/monitor.c ++++ qemu.debian/monitor.c +@@ -4243,3 +4243,11 @@ void qmp_dump_skeys(const char *filename + error_setg(errp, QERR_FEATURE_DISABLED, "dump-skeys"); + } + #endif ++ ++#ifndef TARGET_ARM ++GICCapabilityList *qmp_query_gic_capabilities(Error **errp) ++{ ++ error_setg(errp, QERR_FEATURE_DISABLED, "query-gic-capabilities"); ++ return NULL; ++} ++#endif +Index: qemu.debian/qapi-schema.json +=================================================================== +--- qemu.debian.orig/qapi-schema.json ++++ qemu.debian/qapi-schema.json +@@ -3971,3 +3971,39 @@ + ## + { 'enum': 'ReplayMode', + 'data': [ 'none', 'record', 'play' ] } ++ ++## ++# @GICCapability: ++# ++# The struct describes capability for a specific GIC (Generic ++# Interrupt Controller) version. These bits are not only decided by ++# QEMU/KVM software version, but also decided by the hardware that ++# the program is running upon. ++# ++# @version: version of GIC to be described. Currently, only 2 and 3 ++# are supported. ++# ++# @emulated: whether current QEMU/hardware supports emulated GIC ++# device in user space. ++# ++# @kernel: whether current QEMU/hardware supports hardware ++# accelerated GIC device in kernel. ++# ++# Since: 2.6 ++## ++{ 'struct': 'GICCapability', ++ 'data': { 'version': 'int', ++ 'emulated': 'bool', ++ 'kernel': 'bool' } } ++ ++## ++# @query-gic-capabilities: ++# ++# This command is ARM-only. It will return a list of GICCapability ++# objects that describe its capability bits. ++# ++# Returns: a list of GICCapability objects. ++# ++# Since: 2.6 ++## ++{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] } +Index: qemu.debian/qmp-commands.hx +=================================================================== +--- qemu.debian.orig/qmp-commands.hx ++++ qemu.debian/qmp-commands.hx +@@ -4745,3 +4745,30 @@ Example: + {"type": 0, "out-pport": 0, "pport": 0, "vlan-id": 3840, + "pop-vlan": 1, "id": 251658240} + ]} ++ ++EQMP ++ ++#if defined TARGET_ARM ++ { ++ .name = "query-gic-capabilities", ++ .args_type = "", ++ .mhandler.cmd_new = qmp_marshal_query_gic_capabilities, ++ }, ++#endif ++ ++SQMP ++query-gic-capabilities ++--------------- ++ ++Return a list of GICCapability objects, describing supported GIC ++(Generic Interrupt Controller) versions. ++ ++Arguments: None ++ ++Example: ++ ++-> { "execute": "query-gic-capabilities" } ++<- { "return": [{ "version": 2, "emulated": true, "kernel": false }, ++ { "version": 3, "emulated": false, "kernel": true } ] } ++ ++EQMP +Index: qemu.debian/target-arm/monitor.c +=================================================================== +--- /dev/null ++++ qemu.debian/target-arm/monitor.c +@@ -0,0 +1,28 @@ ++/* ++ * QEMU monitor.c for ARM. ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a copy ++ * of this software and associated documentation files (the "Software"), to deal ++ * in the Software without restriction, including without limitation the rights ++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++ * copies of the Software, and to permit persons to whom the Software is ++ * furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ++ * THE SOFTWARE. ++ */ ++#include "qemu/osdep.h" ++#include "qmp-commands.h" ++ ++GICCapabilityList *qmp_query_gic_capabilities(Error **errp) ++{ ++ return NULL; ++} +Index: qemu.debian/target-arm/Makefile.objs +=================================================================== +--- qemu.debian.orig/target-arm/Makefile.objs ++++ qemu.debian/target-arm/Makefile.objs +@@ -1,5 +1,5 @@ + obj-y += arm-semi.o +-obj-$(CONFIG_SOFTMMU) += machine.o ++obj-$(CONFIG_SOFTMMU) += machine.o monitor.o + obj-$(CONFIG_KVM) += kvm.o + obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o + obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o diff -Nru qemu-2.5+dfsg/debian/patches/ubuntu/kvm-add-kvm_device_supported-helper-function.patch qemu-2.5+dfsg/debian/patches/ubuntu/kvm-add-kvm_device_supported-helper-function.patch --- qemu-2.5+dfsg/debian/patches/ubuntu/kvm-add-kvm_device_supported-helper-function.patch 1970-01-01 00:00:00.000000000 +0000 +++ qemu-2.5+dfsg/debian/patches/ubuntu/kvm-add-kvm_device_supported-helper-function.patch 2016-05-19 19:25:30.000000000 +0000 @@ -0,0 +1,63 @@ +From: Peter Xu +Date: Wed, 30 Mar 2016 17:27:24 +0100 +Subject: [PATCH] kvm: add kvm_device_supported() helper function + +This can be used when probing whether KVM support specific device. Here, +a raw vmfd is used. + +Signed-off-by: Peter Xu +Acked-by: Sergey Fedorov +Message-id: 1458788142-17509-4-git-send-email-peterx@redhat.com +Reviewed-by: Peter Maydell +Signed-off-by: Peter Maydell + +Origin: http://git.qemu.org/?p=qemu.git;a=commitdiff;h=29039acf585615c6c37f8a1863a0a318ddd455cc +Bug-Ubuntu: http://bugs.launchpad.net/bugs/1566564 +Last-Updated: 2016-05-19 + +diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h +index 6695fa7..0e18f15 100644 +--- a/include/sysemu/kvm.h ++++ b/include/sysemu/kvm.h +@@ -306,6 +306,15 @@ void kvm_device_access(int fd, int group, uint64_t attr, + */ + int kvm_create_device(KVMState *s, uint64_t type, bool test); + ++/** ++ * kvm_device_supported - probe whether KVM supports specific device ++ * ++ * @vmfd: The fd handler for VM ++ * @type: type of device ++ * ++ * @return: true if supported, otherwise false. ++ */ ++bool kvm_device_supported(int vmfd, uint64_t type); + + /* Arch specific hooks */ + +diff --git a/kvm-all.c b/kvm-all.c +index 44c0464..e7b66df 100644 +--- a/kvm-all.c ++++ b/kvm-all.c +@@ -2339,6 +2339,21 @@ int kvm_create_device(KVMState *s, uint64_t type, bool test) + return test ? 0 : create_dev.fd; + } + ++bool kvm_device_supported(int vmfd, uint64_t type) ++{ ++ struct kvm_create_device create_dev = { ++ .type = type, ++ .fd = -1, ++ .flags = KVM_CREATE_DEVICE_TEST, ++ }; ++ ++ if (ioctl(vmfd, KVM_CHECK_EXTENSION, KVM_CAP_DEVICE_CTRL) <= 0) { ++ return false; ++ } ++ ++ return (ioctl(vmfd, KVM_CREATE_DEVICE, &create_dev) >= 0); ++} ++ + int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source) + { + struct kvm_one_reg reg;