From patchwork Thu Feb 2 16:32:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9552439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8236860236 for ; Thu, 2 Feb 2017 16:31:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 704232847F for ; Thu, 2 Feb 2017 16:31:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 652DA28481; Thu, 2 Feb 2017 16:31:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11B152847F for ; Thu, 2 Feb 2017 16:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752149AbdBBQbl (ORCPT ); Thu, 2 Feb 2017 11:31:41 -0500 Received: from foss.arm.com ([217.140.101.70]:33504 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbdBBQbi (ORCPT ); Thu, 2 Feb 2017 11:31:38 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9CCC015BE; Thu, 2 Feb 2017 08:31:27 -0800 (PST) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9C0053F24D; Thu, 2 Feb 2017 08:31:26 -0800 (PST) From: Andre Przywara To: Will Deacon , Marc Zyngier Cc: Vladimir Murzin , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [kvmtool PATCH v9 11/15] add kvm__check_vm_capability Date: Thu, 2 Feb 2017 16:32:19 +0000 Message-Id: <20170202163223.15372-12-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170202163223.15372-1-andre.przywara@arm.com> References: <20170202163223.15372-1-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP KVM capabilities can be per-VM, in this case the ioctl should be issued on the VM file descriptor, not on the system fd. Since this feature is guarded by a (system) capability itself, wrap the call into a function of its own. Signed-off-by: Andre Przywara --- include/kvm/kvm.h | 1 + kvm.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 4a76ec2..a76a25d 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -129,6 +129,7 @@ static inline bool host_ptr_in_ram(struct kvm *kvm, void *p) } bool kvm__supports_extension(struct kvm *kvm, unsigned int extension); +bool kvm__supports_vm_extension(struct kvm *kvm, unsigned int extension); static inline void kvm__set_thread_name(const char *name) { diff --git a/kvm.c b/kvm.c index 7fa76f7..665ed14 100644 --- a/kvm.c +++ b/kvm.c @@ -93,6 +93,34 @@ const char *kvm__get_dir(void) return kvm_dir; } +bool kvm__supports_vm_extension(struct kvm *kvm, unsigned int extension) +{ + static int supports_vm_ext_check = 0; + int ret; + + switch (supports_vm_ext_check) { + case 0: + ret = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, + KVM_CAP_CHECK_EXTENSION_VM); + if (ret <= 0) { + supports_vm_ext_check = -1; + return false; + } + supports_vm_ext_check = 1; + /* fall through */ + case 1: + break; + case -1: + return false; + } + + ret = ioctl(kvm->vm_fd, KVM_CHECK_EXTENSION, extension); + if (ret < 0) + return false; + + return ret; +} + bool kvm__supports_extension(struct kvm *kvm, unsigned int extension) { int ret;