From: Amit Shah Subject: [PATCH 1/2] kvm: libkvm: Add a wrapper for an ioctl for the KVM_SET_CPUID2 interface Date: Tue, 13 Jan 2009 10:47:53 +0000 Message-ID: <1231843674-11333-3-git-send-email-amit.shah@redhat.com> References: <1231843674-11333-1-git-send-email-amit.shah@redhat.com> <1231843674-11333-2-git-send-email-amit.shah@redhat.com> Cc: kvm@vger.kernel.org, Amit Shah To: avi@redhat.com Return-path: Received: from hera.kernel.org ([140.211.167.34]:33956 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752387AbZAMKsH (ORCPT ); Tue, 13 Jan 2009 05:48:07 -0500 In-Reply-To: <1231843674-11333-2-git-send-email-amit.shah@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 | 18 ++++++++++++++++++ libkvm/libkvm.h | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c index a8cca15..93a9c4e 100644 --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -475,6 +475,24 @@ 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); + + 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 -- 1.6.0.6