From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXSD2-00059P-6f for qemu-devel@nongnu.org; Mon, 16 Mar 2015 06:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXSCx-0001pm-7p for qemu-devel@nongnu.org; Mon, 16 Mar 2015 06:25:20 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:37453) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXRwk-0004T4-SH for qemu-devel@nongnu.org; Mon, 16 Mar 2015 06:08:31 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Mar 2015 10:08:30 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 141371B08061 for ; Mon, 16 Mar 2015 10:08:50 +0000 (GMT) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t2GA8RSc64552976 for ; Mon, 16 Mar 2015 10:08:27 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t2GA8QMA004609 for ; Mon, 16 Mar 2015 04:08:27 -0600 From: Cornelia Huck Date: Mon, 16 Mar 2015 11:08:12 +0100 Message-Id: <1426500498-24129-5-git-send-email-cornelia.huck@de.ibm.com> In-Reply-To: <1426500498-24129-1-git-send-email-cornelia.huck@de.ibm.com> References: <1426500498-24129-1-git-send-email-cornelia.huck@de.ibm.com> Subject: [Qemu-devel] [PULL for-2.3 04/10] kvm: encapsulate HAS_DEVICE for vm attrs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, Dominik Dingel , agraf@suse.de, borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, Cornelia Huck , Paolo Bonzini From: Dominik Dingel More and more virtual machine specifics between kvm and qemu will be transferred with vm attributes. So we encapsulate the common logic in a generic function. Additionally we need only to check during initialization if kvm supports virtual machine attributes. Cc: Paolo Bonzini Suggested-by: Thomas Huth Reviewed-by: Thomas Huth Signed-off-by: Dominik Dingel Signed-off-by: Jens Freimann Message-Id: <1426164834-38648-2-git-send-email-jfrei@linux.vnet.ibm.com> Acked-by: Paolo Bonzini Signed-off-by: Cornelia Huck --- include/sysemu/kvm.h | 12 ++++++++++++ kvm-all.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 3792463..197e6c0 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -225,6 +225,18 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...); int kvm_device_ioctl(int fd, int type, ...); /** + * kvm_vm_check_attr - check for existence of a specific vm attribute + * @s: The KVMState pointer + * @group: the group + * @attr: the attribute of that group to query for + * + * Returns: 1 if the attribute exists + * 0 if the attribute either does not exist or if the vm device + * interface is unavailable + */ +int kvm_vm_check_attr(KVMState *s, uint32_t group, uint64_t attr); + +/** * kvm_create_device - create a KVM device for the device control API * @KVMState: The KVMState pointer * @type: The KVM device type (see Documentation/virtual/kvm/devices in the diff --git a/kvm-all.c b/kvm-all.c index cbedc25..55025cc 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -126,6 +126,7 @@ bool kvm_gsi_routing_allowed; bool kvm_gsi_direct_mapping; bool kvm_allowed; bool kvm_readonly_mem_allowed; +bool kvm_vm_attributes_allowed; static const KVMCapabilityInfo kvm_required_capabilites[] = { KVM_CAP_INFO(USER_MEMORY), @@ -1598,6 +1599,9 @@ static int kvm_init(MachineState *ms) kvm_resamplefds_allowed = (kvm_check_extension(s, KVM_CAP_IRQFD_RESAMPLE) > 0); + kvm_vm_attributes_allowed = + (kvm_check_extension(s, KVM_CAP_VM_ATTRIBUTES) > 0); + ret = kvm_arch_init(ms, s); if (ret < 0) { goto err; @@ -1936,6 +1940,23 @@ int kvm_device_ioctl(int fd, int type, ...) return ret; } +int kvm_vm_check_attr(KVMState *s, uint32_t group, uint64_t attr) +{ + int ret; + struct kvm_device_attr attribute = { + .group = group, + .attr = attr, + }; + + if (!kvm_vm_attributes_allowed) { + return 0; + } + + ret = kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &attribute); + /* kvm returns 0 on success for HAS_DEVICE_ATTR */ + return ret ? 0 : 1; +} + int kvm_has_sync_mmu(void) { return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU); -- 2.3.3