From patchwork Wed Jan 14 16:51:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 2350 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n0EGlqca029652 for ; Wed, 14 Jan 2009 08:47:52 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758937AbZANQv4 (ORCPT ); Wed, 14 Jan 2009 11:51:56 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1761995AbZANQv4 (ORCPT ); Wed, 14 Jan 2009 11:51:56 -0500 Received: from hera.kernel.org ([140.211.167.34]:33782 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758937AbZANQvz (ORCPT ); Wed, 14 Jan 2009 11:51:55 -0500 Received: from hera.kernel.org (IDENT:U2FsdGVkX1/hVq1XGAWDHz5gFBkucuWwwFiuqAjME3c@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n0EGpnXj028750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Jan 2009 16:51:49 GMT Received: (from amit@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n0EGpmNn028749; Wed, 14 Jan 2009 16:51:48 GMT From: Amit Shah To: avi@redhat.com Cc: kvm@vger.kernel.org, Amit Shah Subject: [PATCH] kvm: libkvm: Add a wrapper for an ioctl for the KVM_SET_CPUID2 interface Date: Wed, 14 Jan 2009 16:51:45 +0000 Message-Id: <1231951906-28145-2-git-send-email-amit.shah@redhat.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1231951906-28145-1-git-send-email-amit.shah@redhat.com> References: <1231951906-28145-1-git-send-email-amit.shah@redhat.com> X-Virus-Scanned: ClamAV 0.93.3/8864/Wed Jan 14 12:50:32 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Wed, 14 Jan 2009 16:51:50 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org kvm_set_cpuid2() builds on top of kvm_set_cpuid() and correctly populates cpuid functions that have sub-leaves. Signed-off-by: Amit Shah --- libkvm/libkvm-x86.c | 21 +++++++++++++++++++++ libkvm/libkvm.h | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-) diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c index a8cca15..dcef548 100644 --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -475,6 +475,27 @@ int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, return r; } +int kvm_setup_cpuid2(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry2 *entries) +{ + struct kvm_cpuid2 *cpuid; + int r; + + cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries)); + if (!cpuid) + return -ENOMEM; + + cpuid->nent = nent; + memcpy(cpuid->entries, entries, nent * sizeof(*entries)); + r = ioctl(kvm->vcpu_fd[vcpu], KVM_SET_CPUID2, cpuid); + if (r == -1) { + fprintf(stderr, "kvm_setup_cpuid2: %m\n"); + return -errno; + } + free(cpuid); + return r; +} + int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages) { #ifdef KVM_CAP_MMU_SHADOW_CACHE_CONTROL diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h index ee1ba68..5728b1c 100644 --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -373,6 +373,22 @@ int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, struct kvm_cpuid_entry *entries); /*! + * \brief Setup a vcpu's cpuid instruction emulation + * + * Set up a table of cpuid function to cpuid outputs. + * This call replaces the older kvm_setup_cpuid interface by adding a few + * parameters to support cpuid functions that have sub-leaf values. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be initialized + * \param nent number of entries to be installed + * \param entries cpuid function entries table + * \return 0 on success, or -errno on error + */ +int kvm_setup_cpuid2(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry2 *entries); + +/*! * \brief Setting the number of shadow pages to be allocated to the vm * * \param kvm pointer to kvm_context