From patchwork Wed Jul 20 17:04:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9240039 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 6156C60867 for ; Wed, 20 Jul 2016 17:04:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AC9427D29 for ; Wed, 20 Jul 2016 17:04:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F03527D5D; Wed, 20 Jul 2016 17:04:48 +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 E61E827D85 for ; Wed, 20 Jul 2016 17:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754824AbcGTREX (ORCPT ); Wed, 20 Jul 2016 13:04:23 -0400 Received: from foss.arm.com ([217.140.101.70]:43658 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754659AbcGTRED (ORCPT ); Wed, 20 Jul 2016 13:04:03 -0400 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 E4B81BBC; Wed, 20 Jul 2016 10:05:13 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3D1763F387; Wed, 20 Jul 2016 10:04:02 -0700 (PDT) From: Andre Przywara To: Will Deacon , Marc Zyngier Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 10/15] add kvm__check_vm_capability Date: Wed, 20 Jul 2016 18:04:30 +0100 Message-Id: <20160720170435.28090-11-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160720170435.28090-1-andre.przywara@arm.com> References: <20160720170435.28090-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;