From patchwork Tue Apr 25 14:39:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9698321 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 9CB186020A for ; Tue, 25 Apr 2017 14:38:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EEBB2857D for ; Tue, 25 Apr 2017 14:38:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72577285E2; Tue, 25 Apr 2017 14:38:00 +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 23CFA2857D for ; Tue, 25 Apr 2017 14:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948174AbdDYOh6 (ORCPT ); Tue, 25 Apr 2017 10:37:58 -0400 Received: from foss.arm.com ([217.140.101.70]:42156 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1948185AbdDYOhm (ORCPT ); Tue, 25 Apr 2017 10:37:42 -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 AE1FA19F6; Tue, 25 Apr 2017 07:37:41 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 87C023F220; Tue, 25 Apr 2017 07:37:40 -0700 (PDT) From: Andre Przywara To: Will Deacon , Marc Zyngier Cc: Jean-Philippe Brucker , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [kvmtool PATCH v10 11/15] add kvm__supports_vm_extension() Date: Tue, 25 Apr 2017 15:39:28 +0100 Message-Id: <20170425143932.17235-12-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170425143932.17235-1-andre.przywara@arm.com> References: <20170425143932.17235-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;