All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: kvm@vger.kernel.org
Cc: avi@redhat.com
Subject: [PATCH 4/4] Use KVMState as main state container
Date: Mon,  8 Jun 2009 15:10:24 -0400	[thread overview]
Message-ID: <1244488224-31171-5-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1244488224-31171-4-git-send-email-glommer@redhat.com>

Put kvm_context inside KVMState. We can then start using
KVMState where we need to, to mid-term, start sharing
code with qemu mainline.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 kvm.h        |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 libkvm-all.c |   19 ++++++++++---------
 libkvm-all.h |   47 +----------------------------------------------
 qemu-kvm.c   |    9 +++++----
 4 files changed, 68 insertions(+), 62 deletions(-)

diff --git a/kvm.h b/kvm.h
index 553c03e..32af545 100644
--- a/kvm.h
+++ b/kvm.h
@@ -16,7 +16,53 @@
 
 #include "config.h"
 #include "sys-queue.h"
-#include "libkvm-all.h"
+
+/**
+ * \brief The KVM context
+ *
+ * The verbose KVM context
+ */
+
+struct kvm_context {
+	/// Filedescriptor to /dev/kvm
+	int fd;
+	int vm_fd;
+	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
+	struct kvm_callbacks *callbacks;
+	void *opaque;
+	/// is dirty pages logging enabled for all regions or not
+	int dirty_pages_log_all;
+	/// do not create in-kernel irqchip if set
+	int no_irqchip_creation;
+	/// in-kernel irqchip status
+	int irqchip_in_kernel;
+	/// ioctl to use to inject interrupts
+	int irqchip_inject_ioctl;
+	/// do not create in-kernel pit if set
+	int no_pit_creation;
+	/// in-kernel pit status
+	int pit_in_kernel;
+	/// in-kernel coalesced mmio
+	int coalesced_mmio;
+#ifdef KVM_CAP_IRQ_ROUTING
+	struct kvm_irq_routing *irq_routes;
+	int nr_allocated_irq_routes;
+#endif
+	void *used_gsi_bitmap;
+	int max_gsi;
+};
+
+struct kvm_vcpu_context
+{
+	int fd;
+	struct kvm_run *run;
+	struct kvm_context *kvm;
+	uint32_t id;
+};
+
+typedef struct kvm_context *kvm_context_t;
+typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
+
 
 typedef struct KVMSlot
 {
@@ -47,8 +93,13 @@ struct KVMState
 #ifdef KVM_CAP_SET_GUEST_DEBUG
     struct kvm_sw_breakpoint_head kvm_sw_breakpoints;
 #endif
+#ifdef USE_KVM
+    struct kvm_context kvm_context;
+#endif
 };
 
+typedef struct KVMState KVMState;
+
 #ifdef KVM_UPSTREAM
 
 #ifdef CONFIG_KVM
@@ -97,8 +148,6 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap);
 
 /* internal API */
 
-struct KVMState;
-typedef struct KVMState KVMState;
 
 int kvm_ioctl(KVMState *s, int type, ...);
 
diff --git a/libkvm-all.c b/libkvm-all.c
index 45679fb..32fdf96 100644
--- a/libkvm-all.c
+++ b/libkvm-all.c
@@ -288,11 +288,12 @@ int kvm_dirty_pages_log_reset(kvm_context_t kvm)
 }
 
 
-kvm_context_t kvm_init(struct kvm_callbacks *callbacks,
+KVMState *kvm_init(struct kvm_callbacks *callbacks,
 		       void *opaque)
 {
 	int fd;
 	kvm_context_t kvm;
+    KVMState *s;
 	int r, gsi_count;
 
 	fd = open("/dev/kvm", O_RDWR);
@@ -319,10 +320,9 @@ kvm_context_t kvm_init(struct kvm_callbacks *callbacks,
 	}
 	kvm_abi = r;
 	kvm_page_size = getpagesize();
-	kvm = malloc(sizeof(*kvm));
-	if (kvm == NULL)
-		goto out_close;
-	memset(kvm, 0, sizeof(*kvm));
+	s = qemu_malloc(sizeof(*s));
+	memset(s, 0, sizeof(*s));
+    kvm = &s->kvm_context;
 	kvm->fd = fd;
 	kvm->vm_fd = -1;
 	kvm->callbacks = callbacks;
@@ -348,10 +348,11 @@ kvm_context_t kvm_init(struct kvm_callbacks *callbacks,
 			set_gsi(kvm, i);
 	}
 
-	return kvm;
- out_close:
-	close(fd);
-	return NULL;
+	return s;
+
+out_close:
+    close(fd);
+    return NULL;
 }
 
 void kvm_finalize(kvm_context_t kvm)
diff --git a/libkvm-all.h b/libkvm-all.h
index d647ef1..251dede 100644
--- a/libkvm-all.h
+++ b/libkvm-all.h
@@ -36,51 +36,6 @@
 /* kvm abi verison variable */
 extern int kvm_abi;
 
-/**
- * \brief The KVM context
- *
- * The verbose KVM context
- */
-
-struct kvm_context {
-	/// Filedescriptor to /dev/kvm
-	int fd;
-	int vm_fd;
-	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
-	struct kvm_callbacks *callbacks;
-	void *opaque;
-	/// is dirty pages logging enabled for all regions or not
-	int dirty_pages_log_all;
-	/// do not create in-kernel irqchip if set
-	int no_irqchip_creation;
-	/// in-kernel irqchip status
-	int irqchip_in_kernel;
-	/// ioctl to use to inject interrupts
-	int irqchip_inject_ioctl;
-	/// do not create in-kernel pit if set
-	int no_pit_creation;
-	/// in-kernel pit status
-	int pit_in_kernel;
-	/// in-kernel coalesced mmio
-	int coalesced_mmio;
-#ifdef KVM_CAP_IRQ_ROUTING
-	struct kvm_irq_routing *irq_routes;
-	int nr_allocated_irq_routes;
-#endif
-	void *used_gsi_bitmap;
-	int max_gsi;
-};
-
-struct kvm_vcpu_context
-{
-	int fd;
-	struct kvm_run *run;
-	struct kvm_context *kvm;
-	uint32_t id;
-};
-
-typedef struct kvm_context *kvm_context_t;
-typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
 
 #include "kvm.h"
 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
@@ -181,7 +136,7 @@ struct kvm_callbacks {
  * \param opaque Not used
  * \return NULL on failure
  */
-kvm_context_t kvm_init(struct kvm_callbacks *callbacks,
+KVMState *kvm_init(struct kvm_callbacks *callbacks,
 		       void *opaque);
 
 /*!
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 2aeb17c..b441970 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -33,6 +33,8 @@ int kvm_irqchip = 1;
 int kvm_pit = 1;
 int kvm_pit_reinject = 1;
 int kvm_nested = 0;
+KVMState *kvm_state;
+
 kvm_context_t kvm_context;
 
 pthread_mutex_t qemu_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -780,10 +782,9 @@ static struct kvm_callbacks qemu_kvm_ops = {
 int kvm_qemu_init()
 {
     /* Try to initialize kvm */
-    kvm_context = kvm_init(&qemu_kvm_ops, cpu_single_env);
-    if (!kvm_context) {
-      	return -1;
-    }
+    kvm_state = kvm_init(&qemu_kvm_ops, cpu_single_env);
+    kvm_context = &kvm_state->kvm_context;
+
     pthread_mutex_lock(&qemu_mutex);
 
     return 0;
-- 
1.5.6.6


  reply	other threads:[~2009-06-08 19:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-08 19:10 [PATCH 0/4] Start using KVMState Glauber Costa
2009-06-08 19:10 ` [PATCH 1/4] get rid of libkvm-common.h Glauber Costa
2009-06-08 19:10   ` [PATCH 2/4] pull qemu headers into libkvm Glauber Costa
2009-06-08 19:10     ` [PATCH 3/4] Move KVMState to common header Glauber Costa
2009-06-08 19:10       ` Glauber Costa [this message]
2009-06-08 19:54       ` Jan Kiszka
2009-06-08 20:14         ` Glauber Costa
2009-06-08 22:01           ` Anthony Liguori
2009-06-18  9:15 ` [PATCH 0/4] Start using KVMState Avi Kivity
2009-06-18 13:29   ` Glauber Costa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1244488224-31171-5-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.