Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 579

kvm-83-270.el5_11.src.rpm

From 6219b51bca6f03f96922b5d3a537a7a034a18efc Mon Sep 17 00:00:00 2001
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Fri, 2 Oct 2009 14:15:29 -0300
Subject: [PATCH 01/10] kvm: libkvm: Add a wrapper for an ioctl for the KVM_SET_CPUID2 interface

RH-Author: Gleb Natapov <gleb@redhat.com>
Message-id: <1253608839-4319-2-git-send-email-gleb@redhat.com>
Patchwork-id: 3483
O-Subject: [PATCH 1/7] kvm: libkvm: Add a wrapper for an ioctl for the
	KVM_SET_CPUID2 interface
Bugzilla: 508040
RH-Acked-by: Mark McLoughlin <markmc@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>

kvm_set_cpuid2() builds on top of kvm_set_cpuid() and correctly populates
cpuid functions that have sub-leaves.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 libkvm/libkvm-x86.c |   21 +++++++++++++++++++++
 libkvm/libkvm.h     |   16 ++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 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 f68e5b6..94ad31d 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.3.rc4.29.g8146