From patchwork Wed Oct 20 08:26:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 268011 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9K8Psvt026000 for ; Wed, 20 Oct 2010 08:25:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752119Ab0JTIZj (ORCPT ); Wed, 20 Oct 2010 04:25:39 -0400 Received: from mga01.intel.com ([192.55.52.88]:24340 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751717Ab0JTIZa (ORCPT ); Wed, 20 Oct 2010 04:25:30 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 20 Oct 2010 01:25:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.57,354,1283756400"; d="scan'208";a="618483772" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.14]) by fmsmga002.fm.intel.com with ESMTP; 20 Oct 2010 01:25:28 -0700 Received: from yasker by syang10-desktop with local (Exim 4.71) (envelope-from ) id 1P8U0J-0007jO-8N; Wed, 20 Oct 2010 16:26:35 +0800 From: Sheng Yang To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Sheng Yang Subject: [PATCH 3/8] KVM: x86: Enable ENABLE_CAP capability for x86 Date: Wed, 20 Oct 2010 16:26:27 +0800 Message-Id: <1287563192-29685-4-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1287563192-29685-1-git-send-email-sheng@linux.intel.com> References: <1287563192-29685-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 20 Oct 2010 08:25:54 +0000 (UTC) diff --git a/Documentation/kvm/api.txt b/Documentation/kvm/api.txt index b336266..d82d637 100644 --- a/Documentation/kvm/api.txt +++ b/Documentation/kvm/api.txt @@ -817,7 +817,7 @@ documentation when it pops into existence). 4.36 KVM_ENABLE_CAP Capability: KVM_CAP_ENABLE_CAP -Architectures: ppc +Architectures: ppc, x86 Type: vcpu ioctl Parameters: struct kvm_enable_cap (in) Returns: 0 on success; -1 on error @@ -828,8 +828,10 @@ can enable an extension, making it available to the guest. On systems that do not support this ioctl, it always fails. On systems that do support it, it only works for extensions that are supported for enablement. -To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should -be used. +For PPC, to check if a capability can be enabled, the KVM_CHECK_EXTENSION +ioctl should be used. + +For x86, only some specific capabilities need to be enabled before use. struct kvm_enable_cap { /* in */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f3f86b2..fc62546 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1926,6 +1926,7 @@ int kvm_dev_ioctl_check_extension(long ext) case KVM_CAP_DEBUGREGS: case KVM_CAP_X86_ROBUST_SINGLESTEP: case KVM_CAP_XSAVE: + case KVM_CAP_ENABLE_CAP: r = 1; break; case KVM_CAP_COALESCED_MMIO: @@ -2707,6 +2708,23 @@ static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu, return r; } +static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, + struct kvm_enable_cap *cap) +{ + int r; + + if (cap->flags) + return -EINVAL; + + switch (cap->cap) { + default: + r = -EINVAL; + break; + } + + return r; +} + long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { @@ -2970,6 +2988,14 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r = kvm_vcpu_ioctl_x86_set_xcrs(vcpu, u.xcrs); break; } + case KVM_ENABLE_CAP: { + struct kvm_enable_cap cap; + r = -EFAULT; + if (copy_from_user(&cap, argp, sizeof(cap))) + goto out; + r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap); + break; + } default: r = -EINVAL; }