public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00 of 17] [v4] libkvm refactor
@ 2007-11-06 16:48 Jerone Young
  2007-11-06 16:48 ` [PATCH 01 of 17] Move kvm_context to kvm-common.h & add CFLAGS to config-* filese Jerone Young
                   ` (17 more replies)
  0 siblings, 18 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Here is the 4th revision of the refactoring of libkvm. This revision
changes since the 3rd revision:
	- removes libkvm-x86.h
	- keeps functions kvm_create_default_phys_mem & kvm_create_phys_mem
	  in place
	- added kvm_arch_create_default_phys_mem
	- Adds needed copyrights to new files
	- Adds void to slots() --> slots(void) decleartions

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 01 of 17] Move kvm_context to kvm-common.h & add CFLAGS to config-* filese
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 02 of 17] Make static slot & kvm_memory region funcions public Jerone Young
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367624 21600
# Node ID dc86d46f1d10fd53c332f1cb7c2f1e880616694a
# Parent  6ce27ddeb45df182e923060ae3abe699ce704ca3
Move kvm_context to kvm-common.h & add CFLAGS to config-* filese

This patch moves kvm_context from libkvm.c to kvm-common.h. This is so
other files are able to see members of kvm_context. Also you should
allways declare stuff like this in a header anyway.

Also moved are delcrations MAX_VCPU, KVM_MAX_NUM_MEM_REGIONS
to kvm-common.h. While PAGE_SIZE & PAGE_MASK where moved to kvm-x86.h.

The idea here is kvm-$(ARCH).h will be headers for interal use by
libkvm. Headers name libkvm-$(ARCH) will be functions that are
arch specific that will be exposed to a user.

Also apart of this patch is added CFLAGS to the config-$(ARCH).mak files.
Really instead there needed to be a unified make file for libkvm &
user directory. But for now this fixes the issue

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak
--- a/libkvm/config-i386.mak
+++ b/libkvm/config-i386.mak
@@ -1,2 +1,4 @@
 
 LIBDIR := /lib
+CFLAGS += -m32
+CFLAGS += -D__i386__
diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak
--- a/libkvm/config-x86_64.mak
+++ b/libkvm/config-x86_64.mak
@@ -1,2 +1,4 @@
 
 LIBDIR := /lib64
+CFLAGS += -m64
+CFLAGS += -D__x86_64__
diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
new file mode 100644
--- /dev/null
+++ b/libkvm/kvm-common.h
@@ -0,0 +1,52 @@
+/* 
+ * This header is for functions & variables that will ONLY be
+ * used inside libkvm.
+ *
+ * derived from libkvm.c
+ *
+ * Copyright (C) 2006 Qumranet, Inc.
+ *
+ * Authors:
+ *	Avi Kivity   <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
+ *	Yaniv Kamay  <yaniv-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
+ *
+ *   This work is licensed under the GNU LGPL license, version 2.
+ */
+
+#ifndef KVM_COMMON_H
+#define KVM_COMMON_H
+
+/* FIXME: share this number with kvm */
+/* FIXME: or dynamically alloc/realloc regions */
+#define KVM_MAX_NUM_MEM_REGIONS 8u
+#define MAX_VCPUS 4
+
+
+/**
+ * \brief The KVM context
+ *
+ * The verbose KVM context
+ */
+
+struct kvm_context {
+	/// Filedescriptor to /dev/kvm
+	int fd;
+	int vm_fd;
+	int vcpu_fd[MAX_VCPUS];
+	struct kvm_run *run[MAX_VCPUS];
+	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
+	struct kvm_callbacks *callbacks;
+	void *opaque;
+	/// A pointer to the memory used as the physical memory for the guest
+	void *physical_memory;
+	/// is dirty pages logging enabled for all regions or not
+	int dirty_pages_log_all;
+	/// memory regions parameters
+	struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS];
+	/// do not create in-kernel irqchip if set
+	int no_irqchip_creation;
+	/// in-kernel irqchip status
+	int irqchip_in_kernel;
+};
+
+#endif
diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
new file mode 100644
--- /dev/null
+++ b/libkvm/kvm-x86.h
@@ -0,0 +1,26 @@
+/* 
+ * This header is for functions & variables that will ONLY be
+ * used inside libkvm for x86. 
+ * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE 
+ * WITHIN LIBKVM.
+ *
+ * derived from libkvm.c
+ *
+ * Copyright (C) 2006 Qumranet, Inc.
+ *
+ * Authors:
+ *	Avi Kivity   <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
+ *	Yaniv Kamay  <yaniv-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
+ *
+ * This work is licensed under the GNU LGPL license, version 2.
+ */
+
+#ifndef KVM_X86_H
+#define KVM_X86_H
+
+#include "kvm-common.h"
+
+#define PAGE_SIZE 4096ul
+#define PAGE_MASK (~(PAGE_SIZE - 1))
+
+#endif
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -37,43 +37,14 @@
 #include "libkvm.h"
 #include "kvm-abi-10.h"
 
+#if defined(__x86_64__) || defined(__i386__)
+#include "kvm-x86.h"
+#endif
+
 static int kvm_abi = EXPECTED_KVM_API_VERSION;
 
-#define PAGE_SIZE 4096ul
-#define PAGE_MASK (~(PAGE_SIZE - 1))
-
-/* FIXME: share this number with kvm */
-/* FIXME: or dynamically alloc/realloc regions */
-#define KVM_MAX_NUM_MEM_REGIONS 8u
 int free_slots[KVM_MAX_NUM_MEM_REGIONS];
 unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS];
-#define MAX_VCPUS 4
-
-/**
- * \brief The KVM context
- *
- * The verbose KVM context
- */
-struct kvm_context {
-	/// Filedescriptor to /dev/kvm
-	int fd;
-	int vm_fd;
-	int vcpu_fd[MAX_VCPUS];
-	struct kvm_run *run[MAX_VCPUS];
-	/// Callbacks that KVM uses to emulate various unvirtualizable functionality
-	struct kvm_callbacks *callbacks;
-	void *opaque;
-	/// A pointer to the memory used as the physical memory for the guest
-	void *physical_memory;
-	/// is dirty pages logging enabled for all regions or not
-	int dirty_pages_log_all;
-	/// memory regions parameters
-	struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS];
-	/// do not create in-kernel irqchip if set
-	int no_irqchip_creation;
-	/// in-kernel irqchip status
-	int irqchip_in_kernel;
-};
 
 static void init_slots()
 {
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -1,4 +1,4 @@
-/** \file kvmctl.h
+/** \file libkvm.h
  * libkvm API
  */
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 02 of 17] Make static slot & kvm_memory region funcions public
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
  2007-11-06 16:48 ` [PATCH 01 of 17] Move kvm_context to kvm-common.h & add CFLAGS to config-* filese Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 03 of 17] Move fuction kvm_alloc_kernel_memory to libkvm-x86.c Jerone Young
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367645 21600
# Node ID e564a557782efc23428705de12cd3e8b9517e11c
# Parent  dc86d46f1d10fd53c332f1cb7c2f1e880616694a
Make static slot & kvm_memory region funcions public

This patch changes static functions for manipulation of memory slots
and regions public in libkvm.c. This also makes a decleration for these
functions in kvm-common.h.

This allow for breaking out code into other files and still keep this
functionality. These functions can later be broken up some to
move there x86 specific stuff (ex. TSS).

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -49,4 +49,14 @@ struct kvm_context {
 	int irqchip_in_kernel;
 };
 
+void init_slots(void);
+int get_free_slot(kvm_context_t kvm);
+void register_slot(int slot, unsigned long phys_addr);
+int get_slot(unsigned long phys_addr);
+void kvm_memory_region_save_params(kvm_context_t kvm,
+                                        struct kvm_memory_region *mem);
+void kvm_userspace_memory_region_save_params(kvm_context_t kvm,
+                                struct kvm_userspace_memory_region *mem);
+void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum);
+
 #endif
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -46,7 +46,7 @@ int free_slots[KVM_MAX_NUM_MEM_REGIONS];
 int free_slots[KVM_MAX_NUM_MEM_REGIONS];
 unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS];
 
-static void init_slots()
+void init_slots(void)
 {
 	int i;
 
@@ -54,7 +54,7 @@ static void init_slots()
 		free_slots[i] = 0;
 }
 
-static int get_free_slot(kvm_context_t kvm)
+int get_free_slot(kvm_context_t kvm)
 {
 	int i;
 	int tss_ext;
@@ -81,13 +81,13 @@ static int get_free_slot(kvm_context_t k
 	return -1;
 }
 
-static void register_slot(int slot, unsigned long phys_addr)
+void register_slot(int slot, unsigned long phys_addr)
 {
 	free_slots[slot] = 1;
 	phys_addr_slots[slot] = phys_addr;
 }
 
-static int get_slot(unsigned long phys_addr)
+int get_slot(unsigned long phys_addr)
 {
 	int i;
 
@@ -100,7 +100,7 @@ static int get_slot(unsigned long phys_a
 /*
  * memory regions parameters
  */
-static void kvm_memory_region_save_params(kvm_context_t kvm, 
+void kvm_memory_region_save_params(kvm_context_t kvm, 
 					 struct kvm_memory_region *mem)
 {
 	if (!mem || (mem->slot >= KVM_MAX_NUM_MEM_REGIONS)) {
@@ -112,7 +112,7 @@ static void kvm_memory_region_save_param
 
 #ifdef KVM_CAP_USER_MEMORY
 
-static void kvm_userspace_memory_region_save_params(kvm_context_t kvm,
+void kvm_userspace_memory_region_save_params(kvm_context_t kvm,
 					struct kvm_userspace_memory_region *mem)
 {
 	struct kvm_memory_region kvm_mem;
@@ -126,7 +126,7 @@ static void kvm_userspace_memory_region_
 
 #endif
 
-static void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum)
+void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum)
 {
 	if (regnum >= KVM_MAX_NUM_MEM_REGIONS) {
 		fprintf(stderr, "BUG: %s: invalid parameters\n", __FUNCTION__);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 03 of 17] Move fuction kvm_alloc_kernel_memory to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
  2007-11-06 16:48 ` [PATCH 01 of 17] Move kvm_context to kvm-common.h & add CFLAGS to config-* filese Jerone Young
  2007-11-06 16:48 ` [PATCH 02 of 17] Make static slot & kvm_memory region funcions public Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 04 of 17] Move kvm_alloc_userspace_memory " Jerone Young
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367646 21600
# Node ID e82588d0a81df7955c12bf18c27d095f46545b6e
# Parent  e564a557782efc23428705de12cd3e8b9517e11c
Move fuction kvm_alloc_kernel_memory to libkvm-x86.c

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/Makefile b/libkvm/Makefile
--- a/libkvm/Makefile
+++ b/libkvm/Makefile
@@ -21,7 +21,7 @@ autodepend-flags = -MMD -MF $(dir $*).$(
 
 all: libkvm.a
 
-libkvm.a: libkvm.o
+libkvm.a: libkvm.o $(libkvm-$(ARCH)-objs)
 	$(AR) rcs $@ $^
 
 install:
diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak
--- a/libkvm/config-i386.mak
+++ b/libkvm/config-i386.mak
@@ -2,3 +2,5 @@ LIBDIR := /lib
 LIBDIR := /lib
 CFLAGS += -m32
 CFLAGS += -D__i386__
+
+libkvm-$(ARCH)-objs := libkvm-x86.o
diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak
--- a/libkvm/config-x86_64.mak
+++ b/libkvm/config-x86_64.mak
@@ -2,3 +2,5 @@ LIBDIR := /lib64
 LIBDIR := /lib64
 CFLAGS += -m64
 CFLAGS += -D__x86_64__
+
+libkvm-$(ARCH)-objs := libkvm-x86.o
diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -23,4 +23,8 @@
 #define PAGE_SIZE 4096ul
 #define PAGE_MASK (~(PAGE_SIZE - 1))
 
+
+int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
+								void **vm_mem);
+
 #endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
new file mode 100644
--- /dev/null
+++ b/libkvm/libkvm-x86.c
@@ -0,0 +1,81 @@
+#include "libkvm.h"
+#include "kvm-x86.h"
+#include <unistd.h>
+#include <stropts.h>
+#include <sys/mman.h>
+#include <stdio.h>
+
+int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
+								void **vm_mem)
+{
+	unsigned long dosmem = 0xa0000;
+	unsigned long exmem = 0xc0000;
+	unsigned long pcimem = 0xe0000000;
+	int r;
+	int tss_ext;
+	struct kvm_memory_region low_memory = {
+		.memory_size = memory  < dosmem ? memory : dosmem,
+		.guest_phys_addr = 0,
+	};
+	struct kvm_memory_region extended_memory = {
+		.memory_size = memory < exmem ? 0 : memory - exmem,
+		.guest_phys_addr = exmem,
+	};
+	struct kvm_memory_region above_4g_memory = {
+		.memory_size = memory < pcimem ? 0 : memory - pcimem,
+		.guest_phys_addr = 0x100000000ULL,
+	};
+
+#ifdef KVM_CAP_SET_TSS_ADDR
+	tss_ext = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
+#else
+	tss_ext = 0;
+#endif
+
+	if (memory >= pcimem)
+		extended_memory.memory_size = pcimem - exmem;
+
+	/* 640K should be enough. */
+	low_memory.slot = get_free_slot(kvm);
+	r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &low_memory);
+	if (r == -1) {
+		fprintf(stderr, "kvm_create_memory_region: %m\n");
+		return -1;
+	}
+	register_slot(low_memory.slot, low_memory.guest_phys_addr);
+
+	if (extended_memory.memory_size) {
+		if (tss_ext > 0)
+			extended_memory.slot = get_free_slot(kvm);
+		else
+			extended_memory.slot = 0;
+		r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &extended_memory);
+		if (r == -1) {
+			fprintf(stderr, "kvm_create_memory_region: %m\n");
+			return -1;
+		}
+		register_slot(extended_memory.slot,
+			      extended_memory.guest_phys_addr);
+	}
+
+	if (above_4g_memory.memory_size) {
+		above_4g_memory.slot = get_free_slot(kvm);
+		r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &above_4g_memory);
+		if (r == -1) {
+			fprintf(stderr, "kvm_create_memory_region: %m\n");
+			return -1;
+		}
+		register_slot(above_4g_memory.slot,
+			      above_4g_memory.guest_phys_addr);
+	}
+
+	kvm_memory_region_save_params(kvm, &low_memory);
+	kvm_memory_region_save_params(kvm, &extended_memory);
+	kvm_memory_region_save_params(kvm, &above_4g_memory);
+	if (above_4g_memory.memory_size)
+		kvm_memory_region_save_params(kvm, &above_4g_memory);
+
+	*vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_SHARED, kvm->vm_fd, 0);
+
+	return 0;
+}
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -317,79 +317,6 @@ int kvm_get_shadow_pages(kvm_context_t k
 	return -1;
 }
 
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
-								void **vm_mem)
-{
-	unsigned long dosmem = 0xa0000;
-	unsigned long exmem = 0xc0000;
-	unsigned long pcimem = 0xe0000000;
-	int r;
-	int tss_ext;
-	struct kvm_memory_region low_memory = {
-		.memory_size = memory  < dosmem ? memory : dosmem,
-		.guest_phys_addr = 0,
-	};
-	struct kvm_memory_region extended_memory = {
-		.memory_size = memory < exmem ? 0 : memory - exmem,
-		.guest_phys_addr = exmem,
-	};
-	struct kvm_memory_region above_4g_memory = {
-		.memory_size = memory < pcimem ? 0 : memory - pcimem,
-		.guest_phys_addr = 0x100000000ULL,
-	};
-
-#ifdef KVM_CAP_SET_TSS_ADDR
-	tss_ext = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
-#else
-	tss_ext = 0;
-#endif
-
-	if (memory >= pcimem)
-		extended_memory.memory_size = pcimem - exmem;
-
-	/* 640K should be enough. */
-	low_memory.slot = get_free_slot(kvm);
-	r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &low_memory);
-	if (r == -1) {
-		fprintf(stderr, "kvm_create_memory_region: %m\n");
-		return -1;
-	}
-	register_slot(low_memory.slot, low_memory.guest_phys_addr);
-
-	if (extended_memory.memory_size) {
-		if (tss_ext > 0)
-			extended_memory.slot = get_free_slot(kvm);
-		else
-			extended_memory.slot = 0;
-		r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &extended_memory);
-		if (r == -1) {
-			fprintf(stderr, "kvm_create_memory_region: %m\n");
-			return -1;
-		}
-		register_slot(extended_memory.slot,
-			      extended_memory.guest_phys_addr);
-	}
-
-	if (above_4g_memory.memory_size) {
-		above_4g_memory.slot = get_free_slot(kvm);
-		r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &above_4g_memory);
-		if (r == -1) {
-			fprintf(stderr, "kvm_create_memory_region: %m\n");
-			return -1;
-		}
-		register_slot(above_4g_memory.slot,
-			      above_4g_memory.guest_phys_addr);
-	}
-
-	kvm_memory_region_save_params(kvm, &low_memory);
-	kvm_memory_region_save_params(kvm, &extended_memory);
-	if (above_4g_memory.memory_size)
-		kvm_memory_region_save_params(kvm, &above_4g_memory);
-
-	*vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_SHARED, kvm->vm_fd, 0);
-
-	return 0;
-}
 
 #ifdef KVM_CAP_USER_MEMORY
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 04 of 17] Move kvm_alloc_userspace_memory to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (2 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 03 of 17] Move fuction kvm_alloc_kernel_memory to libkvm-x86.c Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 05 of 17] Modify out arch specific code from kvm_create function Jerone Young
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367647 21600
# Node ID 5a8dcd2c2316ade1bcb332c57b74b8cc071cfa95
# Parent  e82588d0a81df7955c12bf18c27d095f46545b6e
Move kvm_alloc_userspace_memory to libkvm-x86.c

This moves x86 specific function kvm_alloc_userspace_memory() out
of libkvm.c into libkvm-x86.c.

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -27,4 +27,7 @@ int kvm_alloc_kernel_memory(kvm_context_
 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
 								void **vm_mem);
 
+int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
+								void **vm_mem);
+
 #endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -1,5 +1,8 @@
 #include "libkvm.h"
 #include "kvm-x86.h"
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <string.h>
 #include <unistd.h>
 #include <stropts.h>
 #include <sys/mman.h>
@@ -79,3 +82,107 @@ int kvm_alloc_kernel_memory(kvm_context_
 
 	return 0;
 }
+
+
+#ifdef KVM_CAP_USER_MEMORY
+
+int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
+								void **vm_mem)
+{
+	unsigned long dosmem = 0xa0000;
+	unsigned long exmem = 0xc0000;
+	unsigned long pcimem = 0xe0000000;
+	int r;
+	int tss_ext;
+	struct kvm_userspace_memory_region low_memory = {
+		.memory_size = memory  < dosmem ? memory : dosmem,
+		.guest_phys_addr = 0,
+	};
+	struct kvm_userspace_memory_region extended_memory = {
+		.memory_size = memory < exmem ? 0 : memory - exmem,
+		.guest_phys_addr = exmem,
+	};
+	struct kvm_userspace_memory_region above_4g_memory = {
+		.memory_size = memory < pcimem ? 0 : memory - pcimem,
+		.guest_phys_addr = 0x100000000ULL,
+	};
+
+#ifdef KVM_CAP_SET_TSS_ADDR
+	tss_ext = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
+#else
+	tss_ext = 0;
+#endif
+
+	if (memory >= pcimem) {
+		extended_memory.memory_size = pcimem - exmem;
+		*vm_mem = mmap(NULL, memory + 0x100000000ULL - pcimem,
+				PROT_READ|PROT_WRITE, MAP_ANONYMOUS |
+							MAP_SHARED, -1, 0);
+	}
+	else
+		*vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_ANONYMOUS
+							| MAP_SHARED, -1, 0);
+	if (*vm_mem == MAP_FAILED) {
+		fprintf(stderr, "kvm_alloc_userspace_memory: %s", strerror(errno));
+		return -1;
+	}
+
+	low_memory.userspace_addr = (unsigned long)*vm_mem;
+	low_memory.slot = get_free_slot(kvm);
+	/* 640K should be enough. */
+	r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &low_memory);
+	if (r == -1) {
+		fprintf(stderr, "kvm_create_memory_region: %m\n");
+		return -1;
+	}
+	register_slot(low_memory.slot, low_memory.guest_phys_addr);
+
+	if (extended_memory.memory_size) {
+		r = munmap(*vm_mem + dosmem, exmem - dosmem);
+		if (r == -1) {
+			fprintf(stderr, "kvm_alloc_userspace_memory: %s",
+							strerror(errno));
+			return -1;
+		}
+		extended_memory.userspace_addr = (unsigned long)(*vm_mem + exmem);
+		if (tss_ext > 0)
+			extended_memory.slot = get_free_slot(kvm);
+		else
+			extended_memory.slot = 0;
+		r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &extended_memory);
+		if (r == -1) {
+			fprintf(stderr, "kvm_create_memory_region: %m\n");
+			return -1;
+		}
+		register_slot(extended_memory.slot,
+			      extended_memory.guest_phys_addr);
+	}
+
+	if (above_4g_memory.memory_size) {
+		r = munmap(*vm_mem + pcimem, 0x100000000ULL - pcimem);
+		if (r == -1) {
+			fprintf(stderr, "kvm_alloc_userspace_memory: %s",
+							strerror(errno));
+			return -1;
+		}
+		above_4g_memory.userspace_addr = (unsigned long)(*vm_mem + 0x100000000ULL);
+		above_4g_memory.slot = get_free_slot(kvm);
+		r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &above_4g_memory);
+		if (r == -1) {
+			fprintf(stderr, "kvm_create_memory_region: %m\n");
+			return -1;
+		}
+		register_slot(above_4g_memory.slot,
+			      above_4g_memory.guest_phys_addr);
+	}
+
+	kvm_userspace_memory_region_save_params(kvm, &low_memory);
+	kvm_userspace_memory_region_save_params(kvm, &extended_memory);
+	if (above_4g_memory.memory_size)
+		kvm_userspace_memory_region_save_params(kvm, &above_4g_memory);
+
+	return 0;
+}
+
+#endif
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -317,108 +317,6 @@ int kvm_get_shadow_pages(kvm_context_t k
 	return -1;
 }
 
-
-#ifdef KVM_CAP_USER_MEMORY
-
-int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
-								void **vm_mem)
-{
-	unsigned long dosmem = 0xa0000;
-	unsigned long exmem = 0xc0000;
-	unsigned long pcimem = 0xe0000000;
-	int r;
-	int tss_ext;
-	struct kvm_userspace_memory_region low_memory = {
-		.memory_size = memory  < dosmem ? memory : dosmem,
-		.guest_phys_addr = 0,
-	};
-	struct kvm_userspace_memory_region extended_memory = {
-		.memory_size = memory < exmem ? 0 : memory - exmem,
-		.guest_phys_addr = exmem,
-	};
-	struct kvm_userspace_memory_region above_4g_memory = {
-		.memory_size = memory < pcimem ? 0 : memory - pcimem,
-		.guest_phys_addr = 0x100000000ULL,
-	};
-
-#ifdef KVM_CAP_SET_TSS_ADDR
-	tss_ext = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
-#else
-	tss_ext = 0;
-#endif
-
-	if (memory >= pcimem) {
-		extended_memory.memory_size = pcimem - exmem;
-		*vm_mem = mmap(NULL, memory + 0x100000000ULL - pcimem,
-				PROT_READ|PROT_WRITE, MAP_ANONYMOUS |
-							MAP_SHARED, -1, 0);
-	}
-	else
-		*vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_ANONYMOUS
-							| MAP_SHARED, -1, 0);
-	if (*vm_mem == MAP_FAILED) {
-		fprintf(stderr, "kvm_alloc_userspace_memory: %s", strerror(errno));
-		return -1;
-	}
-
-	low_memory.userspace_addr = (unsigned long)*vm_mem;
-	low_memory.slot = get_free_slot(kvm);
-	/* 640K should be enough. */
-	r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &low_memory);
-	if (r == -1) {
-		fprintf(stderr, "kvm_create_memory_region: %m\n");
-		return -1;
-	}
-	register_slot(low_memory.slot, low_memory.guest_phys_addr);
-
-	if (extended_memory.memory_size) {
-		r = munmap(*vm_mem + dosmem, exmem - dosmem);
-		if (r == -1) {
-			fprintf(stderr, "kvm_alloc_userspace_memory: %s",
-							strerror(errno));
-			return -1;
-		}
-		extended_memory.userspace_addr = (unsigned long)(*vm_mem + exmem);
-		if (tss_ext > 0)
-			extended_memory.slot = get_free_slot(kvm);
-		else
-			extended_memory.slot = 0;
-		r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &extended_memory);
-		if (r == -1) {
-			fprintf(stderr, "kvm_create_memory_region: %m\n");
-			return -1;
-		}
-		register_slot(extended_memory.slot,
-			      extended_memory.guest_phys_addr);
-	}
-
-	if (above_4g_memory.memory_size) {
-		r = munmap(*vm_mem + pcimem, 0x100000000ULL - pcimem);
-		if (r == -1) {
-			fprintf(stderr, "kvm_alloc_userspace_memory: %s",
-							strerror(errno));
-			return -1;
-		}
-		above_4g_memory.userspace_addr = (unsigned long)(*vm_mem + 0x100000000ULL);
-		above_4g_memory.slot = get_free_slot(kvm);
-		r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &above_4g_memory);
-		if (r == -1) {
-			fprintf(stderr, "kvm_create_memory_region: %m\n");
-			return -1;
-		}
-		register_slot(above_4g_memory.slot,
-			      above_4g_memory.guest_phys_addr);
-	}
-
-	kvm_userspace_memory_region_save_params(kvm, &low_memory);
-	kvm_userspace_memory_region_save_params(kvm, &extended_memory);
-	if (above_4g_memory.memory_size)
-		kvm_userspace_memory_region_save_params(kvm, &above_4g_memory);
-
-	return 0;
-}
-
-#endif
 
 int kvm_create_vm(kvm_context_t kvm)
 {

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 05 of 17] Modify out arch specific code from kvm_create function
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (3 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 04 of 17] Move kvm_alloc_userspace_memory " Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 06 of 17] Move kvm_create_kernel_phys_mem to libkvm-x86.c Jerone Young
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367648 21600
# Node ID 4bab1bb82930ade04b5a796ca79e75e392265ba7
# Parent  5a8dcd2c2316ade1bcb332c57b74b8cc071cfa95
Modify out arch specific code from kvm_create function

This function removes all x86 specific code and creates
a hook function kv_arch_create to accomidate for this code.

This patch also moves the following funcitons to libkvm-x86.c:
	kvm_set_tss_addr
	kvm_set_init_tss
	kvm_create_default_phys_mem

This patch moves function kvm_create_default_phys_mem to libkvm-x86.
This function is arch specific to x86 and also today no one allocates
guest memory in the kernel. To remove confusion the function has
been renameed kvm_x86_create_default_phys_mem

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -59,4 +59,10 @@ void kvm_userspace_memory_region_save_pa
                                 struct kvm_userspace_memory_region *mem);
 void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum);
 
+int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
+                        void **vm_mem);
+int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
+                                       unsigned long phys_mem_bytes,
+                                       void **vm_mem);
+
 #endif
diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -30,4 +30,7 @@ int kvm_alloc_userspace_memory(kvm_conte
 int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
 								void **vm_mem);
 
+int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr);
+
+
 #endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -7,6 +7,10 @@
 #include <stropts.h>
 #include <sys/mman.h>
 #include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
 								void **vm_mem)
@@ -186,3 +190,75 @@ int kvm_alloc_userspace_memory(kvm_conte
 
 #endif
 
+int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
+{
+#ifdef KVM_CAP_SET_TSS_ADDR
+	int r;
+
+	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
+	if (r > 0) {
+		r = ioctl(kvm->vm_fd, KVM_SET_TSS_ADDR, addr);
+		if (r == -1) {
+			fprintf(stderr, "kvm_set_tss_addr: %m\n");
+			return -errno;
+		}
+		return 0;
+	}
+#endif
+	return -ENOSYS;
+}
+
+static int kvm_init_tss(kvm_context_t kvm)
+{
+#ifdef KVM_CAP_SET_TSS_ADDR
+	int r;
+
+	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
+	if (r > 0) {
+		/*
+		 * this address is 3 pages before the bios, and the bios should present
+		 * as unavaible memory
+		 */
+		r = kvm_set_tss_addr(kvm, 0xfffbd000);
+		if (r < 0) {
+			printf("kvm_init_tss: unable to set tss addr\n");
+			return r;
+		}
+
+	}
+#endif
+	return 0;
+}
+
+int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
+				       unsigned long phys_mem_bytes,
+				       void **vm_mem)
+{
+	int zfd;
+
+	zfd = open("/dev/zero", O_RDONLY);
+	if (zfd == -1) {
+		perror("open /dev/zero");
+		return -1;
+	}
+        mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
+             MAP_PRIVATE|MAP_FIXED, zfd, 0);
+        close(zfd);
+
+	return 0;
+}
+
+
+int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
+ 			void **vm_mem)
+{
+	int r = 0;
+
+	r = kvm_init_tss(kvm);
+	if (r < 0)
+		return r;
+
+	return 0;
+}
+
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -333,52 +333,11 @@ int kvm_create_vm(kvm_context_t kvm)
 	return 0;
 }
 
-int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
-{
-#ifdef KVM_CAP_SET_TSS_ADDR
-	int r;
-
-	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
-	if (r > 0) {
-		r = ioctl(kvm->vm_fd, KVM_SET_TSS_ADDR, addr);
-		if (r == -1) {
-			fprintf(stderr, "kvm_set_tss_addr: %m\n");
-			return -errno;
-		}
-		return 0;
-	}
-#endif
-	return -ENOSYS;
-}
-
-static int kvm_init_tss(kvm_context_t kvm)
-{
-#ifdef KVM_CAP_SET_TSS_ADDR
-	int r;
-
-	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
-	if (r > 0) {
-		/*
-		 * this address is 3 pages before the bios, and the bios should present
-		 * as unavaible memory
-		 */
-		r = kvm_set_tss_addr(kvm, 0xfffbd000);
-		if (r < 0) {
-			printf("kvm_init_tss: unable to set tss addr\n");
-			return r;
-		}
-
-	}
-#endif
-	return 0;
-}
-
 static int kvm_create_default_phys_mem(kvm_context_t kvm,
 				       unsigned long phys_mem_bytes,
 				       void **vm_mem)
 {
 	unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK;
-	int zfd;
 	int r;
 
 #ifdef KVM_CAP_USER_MEMORY
@@ -391,10 +350,9 @@ static int kvm_create_default_phys_mem(k
 	if (r < 0)
 		return r;
 
-        zfd = open("/dev/zero", O_RDONLY);
-        mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
-             MAP_PRIVATE|MAP_FIXED, zfd, 0);
-        close(zfd);
+	r = kvm_arch_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
+	if (r < 0)
+		return r;
 
 	kvm->physical_memory = *vm_mem;
 	return 0;
@@ -426,7 +384,7 @@ int kvm_create(kvm_context_t kvm, unsign
 	r = kvm_create_vm(kvm);
 	if (r < 0)
 	        return r;
-	r = kvm_init_tss(kvm);
+	r = kvm_arch_create(kvm, phys_mem_bytes, vm_mem);
 	if (r < 0)
 		return r;
 	init_slots();
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -412,7 +412,6 @@ int kvm_dump_vcpu(kvm_context_t kvm, int
  */
 void kvm_show_regs(kvm_context_t kvm, int vcpu);
 
-int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr);
 
 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, 
 			  unsigned long len, int log, int writable);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 06 of 17] Move kvm_create_kernel_phys_mem to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (4 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 05 of 17] Modify out arch specific code from kvm_create function Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 07 of 17] Move kvm_create_memory_alias & kvm_destroy_memory_alias " Jerone Young
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367649 21600
# Node ID 7ea01f673a05fe66cb0d9c514b5a43ddcd72c07f
# Parent  4bab1bb82930ade04b5a796ca79e75e392265ba7
Move kvm_create_kernel_phys_mem to libkvm-x86.c

This patch moves kvm_create_kernel_phys_mem to x86 as this is
the only arch that will be allocating memory for guest in the
kernel (at least for older kvm versions).

Signed-off-by: Jerone Young <jeroney-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -20,6 +20,8 @@
 
 #include "kvm-common.h"
 
+#include "kvm-common.h"
+
 #define PAGE_SIZE 4096ul
 #define PAGE_MASK (~(PAGE_SIZE - 1))
 
@@ -33,4 +35,7 @@ int kvm_set_tss_addr(kvm_context_t kvm, 
 int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr);
 
 
+void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
+			unsigned long len, int log, int writable);
+
 #endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -261,4 +261,36 @@ int kvm_arch_create(kvm_context_t kvm, u
 	return 0;
 }
 
-
+void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
+			unsigned long len, int log, int writable)
+{
+	int r;
+	int prot = PROT_READ;
+	void *ptr;
+	struct kvm_memory_region memory = {
+		.memory_size = len,
+		.guest_phys_addr = phys_start,
+		.flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0,
+	};
+
+	memory.slot = get_free_slot(kvm);
+	r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &memory);
+	if (r == -1) {
+		fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
+		return 0;
+	}
+	register_slot(memory.slot, memory.guest_phys_addr);
+	kvm_memory_region_save_params(kvm, &memory);
+
+	if (writable)
+		prot |= PROT_WRITE;
+
+	ptr = mmap(NULL, len, prot, MAP_SHARED, kvm->vm_fd, phys_start);
+	if (ptr == MAP_FAILED) {
+		fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
+		return 0;
+	}
+
+	return ptr;
+}
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -399,38 +399,6 @@ int kvm_create(kvm_context_t kvm, unsign
 	return 0;
 }
 
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
-			unsigned long len, int log, int writable)
-{
-	int r;
-	int prot = PROT_READ;
-	void *ptr;
-	struct kvm_memory_region memory = {
-		.memory_size = len,
-		.guest_phys_addr = phys_start,
-		.flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0,
-	};
-
-	memory.slot = get_free_slot(kvm);
-	r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &memory);
-	if (r == -1) {
-		fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
-		return 0;
-	}
-	register_slot(memory.slot, memory.guest_phys_addr);
-	kvm_memory_region_save_params(kvm, &memory);
-
-	if (writable)
-		prot |= PROT_WRITE;
-
-	ptr = mmap(NULL, len, prot, MAP_SHARED, kvm->vm_fd, phys_start);
-	if (ptr == MAP_FAILED) {
-		fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
-		return 0;
-	}
-
-	return ptr;
-}
 
 #ifdef KVM_CAP_USER_MEMORY
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 07 of 17] Move kvm_create_memory_alias & kvm_destroy_memory_alias to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (5 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 06 of 17] Move kvm_create_kernel_phys_mem to libkvm-x86.c Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-07 13:52   ` Avi Kivity
  2007-11-06 16:48 ` [PATCH 08 of 17] Move kvm_get & kmv_set_lapci functions " Jerone Young
                   ` (10 subsequent siblings)
  17 siblings, 1 reply; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367649 21600
# Node ID cb186258bc6ecf05ded03d81a3d2ee820e58f605
# Parent  7ea01f673a05fe66cb0d9c514b5a43ddcd72c07f
Move kvm_create_memory_alias & kvm_destroy_memory_alias to libkvm-x86.c

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -294,3 +294,32 @@ void *kvm_create_kernel_phys_mem(kvm_con
 	return ptr;
 }
 
+int kvm_create_memory_alias(kvm_context_t kvm,
+			    uint64_t phys_addr,
+			    uint64_t phys_start,
+			    uint64_t len,
+			    uint64_t target_phys)
+{
+	struct kvm_memory_alias alias = {
+		.flags = 0,
+		.guest_phys_addr = phys_start,
+		.memory_size = len,
+		.target_phys_addr = target_phys,
+	};
+	int fd = kvm->vm_fd;
+	int r;
+
+	alias.slot = get_slot(phys_addr);
+
+	r = ioctl(fd, KVM_SET_MEMORY_ALIAS, &alias);
+	if (r == -1)
+	    return -errno;
+
+	return 0;
+}
+
+int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_addr)
+{
+	return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0);
+}
+

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 08 of 17] Move kvm_get & kmv_set_lapci functions to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (6 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 07 of 17] Move kvm_create_memory_alias & kvm_destroy_memory_alias " Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 09 of 17] Make functions in libkvm.c nonstatic Jerone Young
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367650 21600
# Node ID 739af911ff85420dc4bb367584a1113ca5c82551
# Parent  cb186258bc6ecf05ded03d81a3d2ee820e58f605
Move kvm_get & kmv_set_lapci functions to libkvm-x86.c

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -323,3 +323,34 @@ int kvm_destroy_memory_alias(kvm_context
 	return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0);
 }
 
+#ifdef KVM_CAP_IRQCHIP
+
+int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s)
+{
+	int r;
+	if (!kvm->irqchip_in_kernel)
+		return 0;
+	r = ioctl(kvm->vcpu_fd[vcpu], KVM_GET_LAPIC, s);
+	if (r == -1) {
+		r = -errno;
+		perror("kvm_get_lapic");
+	}
+	return r;
+}
+
+int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s)
+{
+	int r;
+	if (!kvm->irqchip_in_kernel)
+		return 0;
+	r = ioctl(kvm->vcpu_fd[vcpu], KVM_SET_LAPIC, s);
+	if (r == -1) {
+		r = -errno;
+		perror("kvm_set_lapic");
+	}
+	return r;
+}
+
+#endif
+
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -636,32 +636,6 @@ int kvm_set_irqchip(kvm_context_t kvm, s
 	if (r == -1) {
 		r = -errno;
 		perror("kvm_set_irqchip\n");
-	}
-	return r;
-}
-
-int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s)
-{
-	int r;
-	if (!kvm->irqchip_in_kernel)
-		return 0;
-	r = ioctl(kvm->vcpu_fd[vcpu], KVM_GET_LAPIC, s);
-	if (r == -1) {
-		r = -errno;
-		perror("kvm_get_lapic");
-	}
-	return r;
-}
-
-int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s)
-{
-	int r;
-	if (!kvm->irqchip_in_kernel)
-		return 0;
-	r = ioctl(kvm->vcpu_fd[vcpu], KVM_SET_LAPIC, s);
-	if (r == -1) {
-		r = -errno;
-		perror("kvm_set_lapic");
 	}
 	return r;
 }

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 09 of 17] Make functions in libkvm.c nonstatic
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (7 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 08 of 17] Move kvm_get & kmv_set_lapci functions " Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 10 of 17] Move abi 10 functions to libkvm-x86.c Jerone Young
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367651 21600
# Node ID b0f337ae377c7e9050251057a88219d4877c159f
# Parent  739af911ff85420dc4bb367584a1113ca5c82551
Make functions in libkvm.c nonstatic.

This patch makes the following functions nonstatic. These
functions are potentially reusable by other archs, but are
need by arch specific code in libkvm-x86.c.

These functions include:
	handle_halt
	handle_shutdown
	post_kvm_run
	pre_kvm_run
	handle_io_window
	handle_debug

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -65,4 +65,12 @@ int kvm_arch_create_default_phys_mem(kvm
                                        unsigned long phys_mem_bytes,
                                        void **vm_mem);
 
+int handle_halt(kvm_context_t kvm, int vcpu);
+int handle_shutdown(kvm_context_t kvm, int vcpu);
+void post_kvm_run(kvm_context_t kvm, int vcpu);
+int pre_kvm_run(kvm_context_t kvm, int vcpu);
+int handle_io_window(kvm_context_t kvm);
+int handle_debug(kvm_context_t kvm, int vcpu);
+int try_push_interrupts(kvm_context_t kvm);
+
 #endif
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -754,7 +754,7 @@ static int handle_io(kvm_context_t kvm, 
 	return 0;
 }
 
-static int handle_debug(kvm_context_t kvm, int vcpu)
+int handle_debug(kvm_context_t kvm, int vcpu)
 {
 	return kvm->callbacks->debug(kvm->opaque, vcpu);
 }
@@ -1039,17 +1039,17 @@ static int handle_mmio(kvm_context_t kvm
 	return r;
 }
 
-static int handle_io_window(kvm_context_t kvm)
+int handle_io_window(kvm_context_t kvm)
 {
 	return kvm->callbacks->io_window(kvm->opaque);
 }
 
-static int handle_halt(kvm_context_t kvm, int vcpu)
+int handle_halt(kvm_context_t kvm, int vcpu)
 {
 	return kvm->callbacks->halt(kvm->opaque, vcpu);
 }
 
-static int handle_shutdown(kvm_context_t kvm, int vcpu)
+int handle_shutdown(kvm_context_t kvm, int vcpu)
 {
 	return kvm->callbacks->shutdown(kvm->opaque, vcpu);
 }
@@ -1059,12 +1059,12 @@ int try_push_interrupts(kvm_context_t kv
 	return kvm->callbacks->try_push_interrupts(kvm->opaque);
 }
 
-static void post_kvm_run(kvm_context_t kvm, int vcpu)
+void post_kvm_run(kvm_context_t kvm, int vcpu)
 {
 	kvm->callbacks->post_kvm_run(kvm->opaque, vcpu);
 }
 
-static int pre_kvm_run(kvm_context_t kvm, int vcpu)
+int pre_kvm_run(kvm_context_t kvm, int vcpu)
 {
 	return kvm->callbacks->pre_kvm_run(kvm->opaque, vcpu);
 }

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 10 of 17] Move abi 10 functions to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (8 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 09 of 17] Make functions in libkvm.c nonstatic Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 11 of 17] Move msrs " Jerone Young
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367652 21600
# Node ID b1154d12bcc774520ed334f0b84934f1f4db7ce4
# Parent  b0f337ae377c7e9050251057a88219d4877c159f
Move abi 10 functions to libkvm-x86.c

Move handle_io_abi_10 to libkvm-x86.c

Move handle_mmio_abi10 to libkvm-x86.c

Move kvm_run_abi10 to libkvm-x86.c

Move kvm_show_code to libkvm-x86.c

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -38,4 +38,8 @@ void *kvm_create_kernel_phys_mem(kvm_con
 void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
 			unsigned long len, int log, int writable);
 
+int kvm_run_abi10(kvm_context_t kvm, int vcpu);
+
+void kvm_show_code(kvm_context_t kvm, int vcpu);
+
 #endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -1,5 +1,6 @@
 #include "libkvm.h"
 #include "kvm-x86.h"
+#include "kvm-abi-10.h"
 #include <errno.h>
 #include <sys/ioctl.h>
 #include <string.h>
@@ -11,6 +12,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <stdlib.h>
 
 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
 								void **vm_mem)
@@ -353,4 +355,224 @@ int kvm_set_lapic(kvm_context_t kvm, int
 
 #endif
 
-
+static int handle_io_abi10(kvm_context_t kvm, struct kvm_run_abi10 *run,
+			   int vcpu)
+{
+	uint16_t addr = run->io.port;
+	int r;
+	int i;
+	void *p = (void *)run + run->io.data_offset;
+
+	for (i = 0; i < run->io.count; ++i) {
+		switch (run->io.direction) {
+		case KVM_EXIT_IO_IN:
+			switch (run->io.size) {
+			case 1:
+				r = kvm->callbacks->inb(kvm->opaque, addr, p);
+				break;
+			case 2:
+				r = kvm->callbacks->inw(kvm->opaque, addr, p);
+				break;
+			case 4:
+				r = kvm->callbacks->inl(kvm->opaque, addr, p);
+				break;
+			default:
+				fprintf(stderr, "bad I/O size %d\n", run->io.size);
+				return -EMSGSIZE;
+			}
+			break;
+		case KVM_EXIT_IO_OUT:
+		    	switch (run->io.size) {
+			case 1:
+				r = kvm->callbacks->outb(kvm->opaque, addr,
+						     *(uint8_t *)p);
+				break;
+			case 2:
+				r = kvm->callbacks->outw(kvm->opaque, addr,
+						     *(uint16_t *)p);
+				break;
+			case 4:
+				r = kvm->callbacks->outl(kvm->opaque, addr,
+						     *(uint32_t *)p);
+				break;
+			default:
+				fprintf(stderr, "bad I/O size %d\n", run->io.size);
+				return -EMSGSIZE;
+			}
+			break;
+		default:
+			fprintf(stderr, "bad I/O direction %d\n", run->io.direction);
+			return -EPROTO;
+		}
+
+		p += run->io.size;
+	}
+	run->io_completed = 1;
+
+	return 0;
+}
+
+static int handle_mmio_abi10(kvm_context_t kvm, struct kvm_run_abi10 *kvm_run)
+{
+	unsigned long addr = kvm_run->mmio.phys_addr;
+	void *data = kvm_run->mmio.data;
+	int r = -1;
+
+	if (kvm_run->mmio.is_write) {
+		switch (kvm_run->mmio.len) {
+		case 1:
+			r = kvm->callbacks->writeb(kvm->opaque, addr,
+							*(uint8_t *)data);
+			break;
+		case 2:
+			r = kvm->callbacks->writew(kvm->opaque, addr,
+							*(uint16_t *)data);
+			break;
+		case 4:
+			r = kvm->callbacks->writel(kvm->opaque, addr,
+							*(uint32_t *)data);
+			break;
+		case 8:
+			r = kvm->callbacks->writeq(kvm->opaque, addr,
+							*(uint64_t *)data);
+			break;
+		}
+	} else {
+		switch (kvm_run->mmio.len) {
+		case 1:
+			r = kvm->callbacks->readb(kvm->opaque, addr,
+							(uint8_t *)data);
+			break;
+		case 2:
+			r = kvm->callbacks->readw(kvm->opaque, addr,
+							(uint16_t *)data);
+			break;
+		case 4:
+			r = kvm->callbacks->readl(kvm->opaque, addr,
+							(uint32_t *)data);
+			break;
+		case 8:
+			r = kvm->callbacks->readq(kvm->opaque, addr,
+							(uint64_t *)data);
+			break;
+		}
+		kvm_run->io_completed = 1;
+	}
+	return r;
+}
+
+int kvm_run_abi10(kvm_context_t kvm, int vcpu)
+{
+	int r;
+	int fd = kvm->vcpu_fd[vcpu];
+	struct kvm_run_abi10 *run = (struct kvm_run_abi10 *)kvm->run[vcpu];
+
+again:
+	run->request_interrupt_window = try_push_interrupts(kvm);
+	r = pre_kvm_run(kvm, vcpu);
+	if (r)
+	    return r;
+	r = ioctl(fd, KVM_RUN, 0);
+	post_kvm_run(kvm, vcpu);
+
+	run->io_completed = 0;
+	if (r == -1 && errno != EINTR) {
+		r = -errno;
+		printf("kvm_run: %m\n");
+		return r;
+	}
+	if (r == -1) {
+		r = handle_io_window(kvm);
+		goto more;
+	}
+	if (1) {
+		switch (run->exit_reason) {
+		case KVM_EXIT_UNKNOWN:
+			fprintf(stderr, "unhandled vm exit: 0x%x vcpu_id %d\n",
+				(unsigned)run->hw.hardware_exit_reason, vcpu);
+			kvm_show_regs(kvm, vcpu);
+			abort();
+			break;
+		case KVM_EXIT_FAIL_ENTRY:
+			fprintf(stderr, "kvm_run: failed entry, reason %u\n", 
+				(unsigned)run->fail_entry.hardware_entry_failure_reason & 0xffff);
+			return -ENOEXEC;
+			break;
+		case KVM_EXIT_EXCEPTION:
+			fprintf(stderr, "exception %d (%x)\n", 
+			       run->ex.exception,
+			       run->ex.error_code);
+			kvm_show_regs(kvm, vcpu);
+			kvm_show_code(kvm, vcpu);
+			abort();
+			break;
+		case KVM_EXIT_IO:
+			r = handle_io_abi10(kvm, run, vcpu);
+			break;
+		case KVM_EXIT_DEBUG:
+			r = handle_debug(kvm, vcpu);
+			break;
+		case KVM_EXIT_MMIO:
+			r = handle_mmio_abi10(kvm, run);
+			break;
+		case KVM_EXIT_HLT:
+			r = handle_halt(kvm, vcpu);
+			break;
+		case KVM_EXIT_IRQ_WINDOW_OPEN:
+			break;
+		case KVM_EXIT_SHUTDOWN:
+			r = handle_shutdown(kvm, vcpu);
+			break;
+		default:
+			fprintf(stderr, "unhandled vm exit: 0x%x\n", run->exit_reason);
+			kvm_show_regs(kvm, vcpu);
+			abort();
+			break;
+		}
+	}
+more:
+	if (!r)
+		goto again;
+	return r;
+}
+
+
+void kvm_show_code(kvm_context_t kvm, int vcpu)
+{
+#define CR0_PE_MASK	(1ULL<<0)
+	int fd = kvm->vcpu_fd[vcpu];
+	struct kvm_regs regs;
+	struct kvm_sregs sregs;
+	int r;
+	unsigned char code[50];
+	int back_offset;
+	char code_str[sizeof(code) * 3 + 1];
+	unsigned long rip;
+
+	r = ioctl(fd, KVM_GET_SREGS, &sregs);
+	if (r == -1) {
+		perror("KVM_GET_SREGS");
+		return;
+	}
+	if (sregs.cr0 & CR0_PE_MASK)
+		return;
+
+	r = ioctl(fd, KVM_GET_REGS, &regs);
+	if (r == -1) {
+		perror("KVM_GET_REGS");
+		return;
+	}
+	rip = sregs.cs.base + regs.rip;
+	back_offset = regs.rip;
+	if (back_offset > 20)
+	    back_offset = 20;
+	memcpy(code, kvm->physical_memory + rip - back_offset, sizeof code);
+	*code_str = 0;
+	for (r = 0; r < sizeof code; ++r) {
+	    	if (r == back_offset)
+			strcat(code_str, " -->");
+		sprintf(code_str + strlen(code_str), " %02x", code[r]);
+	}
+	fprintf(stderr, "code:%s\n", code_str);
+}
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -642,8 +642,7 @@ int kvm_set_irqchip(kvm_context_t kvm, s
 
 #endif
 
-static int handle_io_abi10(kvm_context_t kvm, struct kvm_run_abi10 *run,
-			   int vcpu)
+static int handle_io(kvm_context_t kvm, struct kvm_run *run, int vcpu)
 {
 	uint16_t addr = run->io.port;
 	int r;
@@ -694,62 +693,6 @@ static int handle_io_abi10(kvm_context_t
 
 		p += run->io.size;
 	}
-	run->io_completed = 1;
-
-	return 0;
-}
-
-static int handle_io(kvm_context_t kvm, struct kvm_run *run, int vcpu)
-{
-	uint16_t addr = run->io.port;
-	int r;
-	int i;
-	void *p = (void *)run + run->io.data_offset;
-
-	for (i = 0; i < run->io.count; ++i) {
-		switch (run->io.direction) {
-		case KVM_EXIT_IO_IN:
-			switch (run->io.size) {
-			case 1:
-				r = kvm->callbacks->inb(kvm->opaque, addr, p);
-				break;
-			case 2:
-				r = kvm->callbacks->inw(kvm->opaque, addr, p);
-				break;
-			case 4:
-				r = kvm->callbacks->inl(kvm->opaque, addr, p);
-				break;
-			default:
-				fprintf(stderr, "bad I/O size %d\n", run->io.size);
-				return -EMSGSIZE;
-			}
-			break;
-		case KVM_EXIT_IO_OUT:
-		    	switch (run->io.size) {
-			case 1:
-				r = kvm->callbacks->outb(kvm->opaque, addr,
-						     *(uint8_t *)p);
-				break;
-			case 2:
-				r = kvm->callbacks->outw(kvm->opaque, addr,
-						     *(uint16_t *)p);
-				break;
-			case 4:
-				r = kvm->callbacks->outl(kvm->opaque, addr,
-						     *(uint32_t *)p);
-				break;
-			default:
-				fprintf(stderr, "bad I/O size %d\n", run->io.size);
-				return -EMSGSIZE;
-			}
-			break;
-		default:
-			fprintf(stderr, "bad I/O direction %d\n", run->io.direction);
-			return -EPROTO;
-		}
-
-		p += run->io.size;
-	}
 
 	return 0;
 }
@@ -915,50 +858,15 @@ void kvm_show_regs(kvm_context_t kvm, in
 		sregs.efer);
 }
 
-static void kvm_show_code(kvm_context_t kvm, int vcpu)
-{
-#define CR0_PE_MASK	(1ULL<<0)
-	int fd = kvm->vcpu_fd[vcpu];
-	struct kvm_regs regs;
-	struct kvm_sregs sregs;
-	int r;
-	unsigned char code[50];
-	int back_offset;
-	char code_str[sizeof(code) * 3 + 1];
-	unsigned long rip;
-
-	r = ioctl(fd, KVM_GET_SREGS, &sregs);
-	if (r == -1) {
-		perror("KVM_GET_SREGS");
-		return;
-	}
-	if (sregs.cr0 & CR0_PE_MASK)
-		return;
-
-	r = ioctl(fd, KVM_GET_REGS, &regs);
-	if (r == -1) {
-		perror("KVM_GET_REGS");
-		return;
-	}
-	rip = sregs.cs.base + regs.rip;
-	back_offset = regs.rip;
-	if (back_offset > 20)
-	    back_offset = 20;
-	memcpy(code, kvm->physical_memory + rip - back_offset, sizeof code);
-	*code_str = 0;
-	for (r = 0; r < sizeof code; ++r) {
-	    	if (r == back_offset)
-			strcat(code_str, " -->");
-		sprintf(code_str + strlen(code_str), " %02x", code[r]);
-	}
-	fprintf(stderr, "code:%s\n", code_str);
-}
-
-static int handle_mmio_abi10(kvm_context_t kvm, struct kvm_run_abi10 *kvm_run)
+static int handle_mmio(kvm_context_t kvm, struct kvm_run *kvm_run)
 {
 	unsigned long addr = kvm_run->mmio.phys_addr;
 	void *data = kvm_run->mmio.data;
 	int r = -1;
+
+	/* hack: Red Hat 7.1 generates these wierd accesses. */
+	if (addr == 0xa0000 && kvm_run->mmio.len == 3)
+	    return 0;
 
 	if (kvm_run->mmio.is_write) {
 		switch (kvm_run->mmio.len) {
@@ -990,51 +898,6 @@ static int handle_mmio_abi10(kvm_context
 			r = kvm->callbacks->readq(kvm->opaque, addr, (uint64_t *)data);
 			break;
 		}
-		kvm_run->io_completed = 1;
-	}
-	return r;
-}
-
-static int handle_mmio(kvm_context_t kvm, struct kvm_run *kvm_run)
-{
-	unsigned long addr = kvm_run->mmio.phys_addr;
-	void *data = kvm_run->mmio.data;
-	int r = -1;
-
-	/* hack: Red Hat 7.1 generates these wierd accesses. */
-	if (addr == 0xa0000 && kvm_run->mmio.len == 3)
-	    return 0;
-
-	if (kvm_run->mmio.is_write) {
-		switch (kvm_run->mmio.len) {
-		case 1:
-			r = kvm->callbacks->writeb(kvm->opaque, addr, *(uint8_t *)data);
-			break;
-		case 2:
-			r = kvm->callbacks->writew(kvm->opaque, addr, *(uint16_t *)data);
-			break;
-		case 4:
-			r = kvm->callbacks->writel(kvm->opaque, addr, *(uint32_t *)data);
-			break;
-		case 8:
-			r = kvm->callbacks->writeq(kvm->opaque, addr, *(uint64_t *)data);
-			break;
-		}
-	} else {
-		switch (kvm_run->mmio.len) {
-		case 1:
-			r = kvm->callbacks->readb(kvm->opaque, addr, (uint8_t *)data);
-			break;
-		case 2:
-			r = kvm->callbacks->readw(kvm->opaque, addr, (uint16_t *)data);
-			break;
-		case 4:
-			r = kvm->callbacks->readl(kvm->opaque, addr, (uint32_t *)data);
-			break;
-		case 8:
-			r = kvm->callbacks->readq(kvm->opaque, addr, (uint64_t *)data);
-			break;
-		}
 	}
 	return r;
 }
@@ -1110,81 +973,6 @@ __u64 kvm_get_cr8(kvm_context_t kvm, int
 __u64 kvm_get_cr8(kvm_context_t kvm, int vcpu)
 {
 	return kvm->run[vcpu]->cr8;
-}
-
-static int kvm_run_abi10(kvm_context_t kvm, int vcpu)
-{
-	int r;
-	int fd = kvm->vcpu_fd[vcpu];
-	struct kvm_run_abi10 *run = (struct kvm_run_abi10 *)kvm->run[vcpu];
-
-again:
-	run->request_interrupt_window = try_push_interrupts(kvm);
-	r = pre_kvm_run(kvm, vcpu);
-	if (r)
-	    return r;
-	r = ioctl(fd, KVM_RUN, 0);
-	post_kvm_run(kvm, vcpu);
-
-	run->io_completed = 0;
-	if (r == -1 && errno != EINTR) {
-		r = -errno;
-		printf("kvm_run: %m\n");
-		return r;
-	}
-	if (r == -1) {
-		r = handle_io_window(kvm);
-		goto more;
-	}
-	if (1) {
-		switch (run->exit_reason) {
-		case KVM_EXIT_UNKNOWN:
-			fprintf(stderr, "unhandled vm exit: 0x%x vcpu_id %d\n",
-				(unsigned)run->hw.hardware_exit_reason, vcpu);
-			kvm_show_regs(kvm, vcpu);
-			abort();
-			break;
-		case KVM_EXIT_FAIL_ENTRY:
-			fprintf(stderr, "kvm_run: failed entry, reason %u\n", 
-				(unsigned)run->fail_entry.hardware_entry_failure_reason & 0xffff);
-			return -ENOEXEC;
-			break;
-		case KVM_EXIT_EXCEPTION:
-			fprintf(stderr, "exception %d (%x)\n", 
-			       run->ex.exception,
-			       run->ex.error_code);
-			kvm_show_regs(kvm, vcpu);
-			kvm_show_code(kvm, vcpu);
-			abort();
-			break;
-		case KVM_EXIT_IO:
-			r = handle_io_abi10(kvm, run, vcpu);
-			break;
-		case KVM_EXIT_DEBUG:
-			r = handle_debug(kvm, vcpu);
-			break;
-		case KVM_EXIT_MMIO:
-			r = handle_mmio_abi10(kvm, run);
-			break;
-		case KVM_EXIT_HLT:
-			r = handle_halt(kvm, vcpu);
-			break;
-		case KVM_EXIT_IRQ_WINDOW_OPEN:
-			break;
-		case KVM_EXIT_SHUTDOWN:
-			r = handle_shutdown(kvm, vcpu);
-			break;
-		default:
-			fprintf(stderr, "unhandled vm exit: 0x%x\n", run->exit_reason);
-			kvm_show_regs(kvm, vcpu);
-			abort();
-			break;
-		}
-	}
-more:
-	if (!r)
-		goto again;
-	return r;
 }
 
 int kvm_run(kvm_context_t kvm, int vcpu)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 11 of 17] Move msrs functions to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (9 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 10 of 17] Move abi 10 functions to libkvm-x86.c Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-08  5:57   ` Carlo Marcelo Arenas Belon
  2007-11-06 16:48 ` [PATCH 12 of 17] Move print_seg & Move kvm_show_regs " Jerone Young
                   ` (6 subsequent siblings)
  17 siblings, 1 reply; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367653 21600
# Node ID cbe4ad07343fc1ef904f02734c68d0fb8506cb9e
# Parent  b1154d12bcc774520ed334f0b84934f1f4db7ce4
Move msrs functions to libkvm-x86.c

This patch moves functions:
	kvm_msr_list
	move kvm_get_msrs
	move kvm_set_msrs

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -42,4 +42,8 @@ int kvm_run_abi10(kvm_context_t kvm, int
 
 void kvm_show_code(kvm_context_t kvm, int vcpu);
 
+struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
+int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
+int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
+
 #endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -576,3 +576,71 @@ void kvm_show_code(kvm_context_t kvm, in
 	fprintf(stderr, "code:%s\n", code_str);
 }
 
+
+/*
+ * Returns available msr list.  User must free.
+ */
+struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm)
+{
+	struct kvm_msr_list sizer, *msrs;
+	int r, e;
+
+	sizer.nmsrs = 0;
+	r = ioctl(kvm->fd, KVM_GET_MSR_INDEX_LIST, &sizer);
+	if (r == -1 && errno != E2BIG)
+		return NULL;
+	msrs = malloc(sizeof *msrs + sizer.nmsrs * sizeof *msrs->indices);
+	if (!msrs) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	msrs->nmsrs = sizer.nmsrs;
+	r = ioctl(kvm->fd, KVM_GET_MSR_INDEX_LIST, msrs);
+	if (r == -1) {
+		e = errno;
+		free(msrs);
+		errno = e;
+		return NULL;
+	}
+	return msrs;
+}
+
+int kvm_get_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs,
+		 int n)
+{
+    struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs);
+    int r, e;
+
+    if (!kmsrs) {
+	errno = ENOMEM;
+	return -1;
+    }
+    kmsrs->nmsrs = n;
+    memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
+    r = ioctl(kvm->vcpu_fd[vcpu], KVM_GET_MSRS, kmsrs);
+    e = errno;
+    memcpy(msrs, kmsrs->entries, n * sizeof *msrs);
+    free(kmsrs);
+    errno = e;
+    return r;
+}
+
+int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs,
+		 int n)
+{
+    struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs);
+    int r, e;
+
+    if (!kmsrs) {
+	errno = ENOMEM;
+	return -1;
+    }
+    kmsrs->nmsrs = n;
+    memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
+    r = ioctl(kvm->vcpu_fd[vcpu], KVM_SET_MSRS, kmsrs);
+    e = errno;
+    free(kmsrs);
+    errno = e;
+    return r;
+}
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -732,73 +732,6 @@ int kvm_set_sregs(kvm_context_t kvm, int
     return ioctl(kvm->vcpu_fd[vcpu], KVM_SET_SREGS, sregs);
 }
 
-/*
- * Returns available msr list.  User must free.
- */
-struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm)
-{
-	struct kvm_msr_list sizer, *msrs;
-	int r, e;
-
-	sizer.nmsrs = 0;
-	r = ioctl(kvm->fd, KVM_GET_MSR_INDEX_LIST, &sizer);
-	if (r == -1 && errno != E2BIG)
-		return NULL;
-	msrs = malloc(sizeof *msrs + sizer.nmsrs * sizeof *msrs->indices);
-	if (!msrs) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	msrs->nmsrs = sizer.nmsrs;
-	r = ioctl(kvm->fd, KVM_GET_MSR_INDEX_LIST, msrs);
-	if (r == -1) {
-		e = errno;
-		free(msrs);
-		errno = e;
-		return NULL;
-	}
-	return msrs;
-}
-
-int kvm_get_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs,
-		 int n)
-{
-    struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs);
-    int r, e;
-
-    if (!kmsrs) {
-	errno = ENOMEM;
-	return -1;
-    }
-    kmsrs->nmsrs = n;
-    memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
-    r = ioctl(kvm->vcpu_fd[vcpu], KVM_GET_MSRS, kmsrs);
-    e = errno;
-    memcpy(msrs, kmsrs->entries, n * sizeof *msrs);
-    free(kmsrs);
-    errno = e;
-    return r;
-}
-
-int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs,
-		 int n)
-{
-    struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs);
-    int r, e;
-
-    if (!kmsrs) {
-	errno = ENOMEM;
-	return -1;
-    }
-    kmsrs->nmsrs = n;
-    memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
-    r = ioctl(kvm->vcpu_fd[vcpu], KVM_SET_MSRS, kmsrs);
-    e = errno;
-    free(kmsrs);
-    errno = e;
-    return r;
-}
-
 static void print_seg(FILE *file, const char *name, struct kvm_segment *seg)
 {
     	fprintf(stderr,
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -335,10 +335,6 @@ int kvm_get_sregs(kvm_context_t kvm, int
  */
 int kvm_set_sregs(kvm_context_t kvm, int vcpu, struct kvm_sregs *regs);
 
-struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
-int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
-int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
-
 /*!
  * \brief Simulate an external vectored interrupt
  *

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 12 of 17] Move print_seg & Move kvm_show_regs to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (10 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 11 of 17] Move msrs " Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 13 of 17] Declare kvm_abi as a global variable in kvm-common.h Jerone Young
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367653 21600
# Node ID 5148847d713a7108527906df774e35a042853ad1
# Parent  cbe4ad07343fc1ef904f02734c68d0fb8506cb9e
Move print_seg & Move kvm_show_regs to libkvm-x86.c

This patch moves functions print_seg, kvm_show_regs, & print_dt
to libkvm-x86.c. Since kvm_show_regs really has little
to no shared code (besides an ioctl call and variable
declarations), it is best that this be moved into
arch specific code.

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -644,3 +644,63 @@ int kvm_set_msrs(kvm_context_t kvm, int 
     return r;
 }
 
+static void print_seg(FILE *file, const char *name, struct kvm_segment *seg)
+{
+    	fprintf(stderr,
+		"%s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d"
+		" g %d avl %d)\n",
+		name, seg->selector, seg->base, seg->limit, seg->present,
+		seg->dpl, seg->db, seg->s, seg->type, seg->l, seg->g,
+		seg->avl);
+}
+
+static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt)
+{
+    	fprintf(stderr, "%s %llx/%x\n", name, dt->base, dt->limit);
+}
+
+void kvm_show_regs(kvm_context_t kvm, int vcpu)
+{
+	int fd = kvm->vcpu_fd[vcpu];
+	struct kvm_regs regs;
+	struct kvm_sregs sregs;
+	int r;
+
+	r = ioctl(fd, KVM_GET_REGS, &regs);
+	if (r == -1) {
+		perror("KVM_GET_REGS");
+		return;
+	}
+	fprintf(stderr,
+		"rax %016llx rbx %016llx rcx %016llx rdx %016llx\n"
+		"rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n"
+		"r8  %016llx r9  %016llx r10 %016llx r11 %016llx\n"
+		"r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n"
+		"rip %016llx rflags %08llx\n",
+		regs.rax, regs.rbx, regs.rcx, regs.rdx,
+		regs.rsi, regs.rdi, regs.rsp, regs.rbp,
+		regs.r8,  regs.r9,  regs.r10, regs.r11,
+		regs.r12, regs.r13, regs.r14, regs.r15,
+		regs.rip, regs.rflags);
+	r = ioctl(fd, KVM_GET_SREGS, &sregs);
+	if (r == -1) {
+		perror("KVM_GET_SREGS");
+		return;
+	}
+	print_seg(stderr, "cs", &sregs.cs);
+	print_seg(stderr, "ds", &sregs.ds);
+	print_seg(stderr, "es", &sregs.es);
+	print_seg(stderr, "ss", &sregs.ss);
+	print_seg(stderr, "fs", &sregs.fs);
+	print_seg(stderr, "gs", &sregs.gs);
+	print_seg(stderr, "tr", &sregs.tr);
+	print_seg(stderr, "ldt", &sregs.ldt);
+	print_dt(stderr, "gdt", &sregs.gdt);
+	print_dt(stderr, "idt", &sregs.idt);
+	fprintf(stderr, "cr0 %llx cr2 %llx cr3 %llx cr4 %llx cr8 %llx"
+		" efer %llx\n",
+		sregs.cr0, sregs.cr2, sregs.cr3, sregs.cr4, sregs.cr8,
+		sregs.efer);
+}
+
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -732,65 +732,6 @@ int kvm_set_sregs(kvm_context_t kvm, int
     return ioctl(kvm->vcpu_fd[vcpu], KVM_SET_SREGS, sregs);
 }
 
-static void print_seg(FILE *file, const char *name, struct kvm_segment *seg)
-{
-    	fprintf(stderr,
-		"%s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d"
-		" g %d avl %d)\n",
-		name, seg->selector, seg->base, seg->limit, seg->present,
-		seg->dpl, seg->db, seg->s, seg->type, seg->l, seg->g,
-		seg->avl);
-}
-
-static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt)
-{
-    	fprintf(stderr, "%s %llx/%x\n", name, dt->base, dt->limit);
-}
-
-void kvm_show_regs(kvm_context_t kvm, int vcpu)
-{
-	int fd = kvm->vcpu_fd[vcpu];
-	struct kvm_regs regs;
-	struct kvm_sregs sregs;
-	int r;
-
-	r = ioctl(fd, KVM_GET_REGS, &regs);
-	if (r == -1) {
-		perror("KVM_GET_REGS");
-		return;
-	}
-	fprintf(stderr,
-		"rax %016llx rbx %016llx rcx %016llx rdx %016llx\n"
-		"rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n"
-		"r8  %016llx r9  %016llx r10 %016llx r11 %016llx\n"
-		"r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n"
-		"rip %016llx rflags %08llx\n",
-		regs.rax, regs.rbx, regs.rcx, regs.rdx,
-		regs.rsi, regs.rdi, regs.rsp, regs.rbp,
-		regs.r8,  regs.r9,  regs.r10, regs.r11,
-		regs.r12, regs.r13, regs.r14, regs.r15,
-		regs.rip, regs.rflags);
-	r = ioctl(fd, KVM_GET_SREGS, &sregs);
-	if (r == -1) {
-		perror("KVM_GET_SREGS");
-		return;
-	}
-	print_seg(stderr, "cs", &sregs.cs);
-	print_seg(stderr, "ds", &sregs.ds);
-	print_seg(stderr, "es", &sregs.es);
-	print_seg(stderr, "ss", &sregs.ss);
-	print_seg(stderr, "fs", &sregs.fs);
-	print_seg(stderr, "gs", &sregs.gs);
-	print_seg(stderr, "tr", &sregs.tr);
-	print_seg(stderr, "ldt", &sregs.ldt);
-	print_dt(stderr, "gdt", &sregs.gdt);
-	print_dt(stderr, "idt", &sregs.idt);
-	fprintf(stderr, "cr0 %llx cr2 %llx cr3 %llx cr4 %llx cr8 %llx"
-		" efer %llx\n",
-		sregs.cr0, sregs.cr2, sregs.cr3, sregs.cr4, sregs.cr8,
-		sregs.efer);
-}
-
 static int handle_mmio(kvm_context_t kvm, struct kvm_run *kvm_run)
 {
 	unsigned long addr = kvm_run->mmio.phys_addr;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 13 of 17] Declare kvm_abi as a global variable in kvm-common.h
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (11 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 12 of 17] Move print_seg & Move kvm_show_regs " Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 14 of 17] Move kvm_get_apic to libkvm-x86.c Jerone Young
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367654 21600
# Node ID 3c691b26a79c2e589e20d5c8245a7c30ec456976
# Parent  5148847d713a7108527906df774e35a042853ad1
Declare kvm_abi as a global variable in kvm-common.h

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -21,6 +21,8 @@
 #define KVM_MAX_NUM_MEM_REGIONS 8u
 #define MAX_VCPUS 4
 
+/* kvm abi verison variable */
+extern int kvm_abi;
 
 /**
  * \brief The KVM context
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -41,7 +41,7 @@
 #include "kvm-x86.h"
 #endif
 
-static int kvm_abi = EXPECTED_KVM_API_VERSION;
+int kvm_abi = EXPECTED_KVM_API_VERSION;
 
 int free_slots[KVM_MAX_NUM_MEM_REGIONS];
 unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS];

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 14 of 17] Move kvm_get_apic to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (12 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 13 of 17] Declare kvm_abi as a global variable in kvm-common.h Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 15 of 17] Move cr8 functions " Jerone Young
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367655 21600
# Node ID 7ef9d60771ef7e6d32919ace92d078a482b9d589
# Parent  3c691b26a79c2e589e20d5c8245a7c30ec456976
Move kvm_get_apic to libkvm-x86.c

Moves apic function since it is x86 only.

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -703,4 +703,12 @@ void kvm_show_regs(kvm_context_t kvm, in
 		sregs.efer);
 }
 
-
+uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu)
+{
+	struct kvm_run *run = kvm->run[vcpu];
+
+	if (kvm_abi == 10)
+		return ((struct kvm_run_abi10 *)run)->apic_base;
+	return run->apic_base;
+}
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -815,15 +815,6 @@ int kvm_get_interrupt_flag(kvm_context_t
 	return run->if_flag;
 }
 
-uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu)
-{
-	struct kvm_run *run = kvm->run[vcpu];
-
-	if (kvm_abi == 10)
-		return ((struct kvm_run_abi10 *)run)->apic_base;
-	return run->apic_base;
-}
-
 int kvm_is_ready_for_interrupt_injection(kvm_context_t kvm, int vcpu)
 {
 	struct kvm_run *run = kvm->run[vcpu];

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 15 of 17] Move cr8 functions to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (13 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 14 of 17] Move kvm_get_apic to libkvm-x86.c Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 16 of 17] Move kvm_setup_cpuid " Jerone Young
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367666 21600
# Node ID f610c78e9f363a53b3e9677aa84873b05a692acb
# Parent  7ef9d60771ef7e6d32919ace92d078a482b9d589
Move cr8 functions to libkvm-x86.c

This patch moves functions:
	kvm_set_cr8
	kvm_get_cr8

cr8 is an x86 only register.

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -712,3 +712,19 @@ uint64_t kvm_get_apic_base(kvm_context_t
 	return run->apic_base;
 }
 
+void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8)
+{
+	struct kvm_run *run = kvm->run[vcpu];
+
+	if (kvm_abi == 10) {
+		((struct kvm_run_abi10 *)run)->cr8 = cr8;
+		return;
+	}
+	run->cr8 = cr8;
+}
+
+__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu)
+{
+	return kvm->run[vcpu]->cr8;
+}
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -824,22 +824,6 @@ int kvm_is_ready_for_interrupt_injection
 	return run->ready_for_interrupt_injection;
 }
 
-void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8)
-{
-	struct kvm_run *run = kvm->run[vcpu];
-
-	if (kvm_abi == 10) {
-		((struct kvm_run_abi10 *)run)->cr8 = cr8;
-		return;
-	}
-	run->cr8 = cr8;
-}
-
-__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu)
-{
-	return kvm->run[vcpu]->cr8;
-}
-
 int kvm_run(kvm_context_t kvm, int vcpu)
 {
 	int r;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 16 of 17] Move kvm_setup_cpuid to libkvm-x86.c
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (14 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 15 of 17] Move cr8 functions " Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-06 16:48 ` [PATCH 17 of 17] Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h Jerone Young
  2007-11-07 13:52 ` [PATCH 00 of 17] [v4] libkvm refactor Avi Kivity
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367666 21600
# Node ID 43dc6f59e0944c18b2cbd092c819b4141889ee61
# Parent  f610c78e9f363a53b3e9677aa84873b05a692acb
Move kvm_setup_cpuid to libkvm-x86.c

cpuid is an x86 instruction, so needs to go
in the approriate place.

Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -728,3 +728,21 @@ __u64 kvm_get_cr8(kvm_context_t kvm, int
 	return kvm->run[vcpu]->cr8;
 }
 
+int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent,
+		    struct kvm_cpuid_entry *entries)
+{
+	struct kvm_cpuid *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_CPUID, cpuid);
+
+	free(cpuid);
+	return r;
+}
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -919,24 +919,6 @@ int kvm_guest_debug(kvm_context_t kvm, i
 	return ioctl(kvm->vcpu_fd[vcpu], KVM_DEBUG_GUEST, dbg);
 }
 
-int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent,
-		    struct kvm_cpuid_entry *entries)
-{
-	struct kvm_cpuid *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_CPUID, cpuid);
-
-	free(cpuid);
-	return r;
-}
-
 int kvm_set_signal_mask(kvm_context_t kvm, int vcpu, const sigset_t *sigset)
 {
 	struct kvm_signal_mask *sigmask;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 17 of 17] Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (15 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 16 of 17] Move kvm_setup_cpuid " Jerone Young
@ 2007-11-06 16:48 ` Jerone Young
  2007-11-07 13:52 ` [PATCH 00 of 17] [v4] libkvm refactor Avi Kivity
  17 siblings, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-06 16:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1194367666 21600
# Node ID 93b712e019dcfa0fa425353e972fb404b4750278
# Parent  43dc6f59e0944c18b2cbd092c819b4141889ee61
Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h

This remove unused code from libkvm.h.

Signed-off-by: Jerone Young <jyoug5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -12,14 +12,6 @@
 #endif
 
 #include <linux/kvm.h>
-
-#define u32 uint32_t  /* older kvm_para.h had a u32 exposed */
-#define u64 uint32_t  /* older kvm_para.h had a u32 exposed */
-#define PAGE_SIZE 4096
-#include <linux/kvm_para.h>
-#undef u32
-#undef u64
-#undef PAGE_SIZE
 
 #include <signal.h>
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 07 of 17] Move kvm_create_memory_alias & kvm_destroy_memory_alias to libkvm-x86.c
  2007-11-06 16:48 ` [PATCH 07 of 17] Move kvm_create_memory_alias & kvm_destroy_memory_alias " Jerone Young
@ 2007-11-07 13:52   ` Avi Kivity
  0 siblings, 0 replies; 27+ messages in thread
From: Avi Kivity @ 2007-11-07 13:52 UTC (permalink / raw)
  To: Jerone Young
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Jerone Young wrote:
> # HG changeset patch
> # User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
> # Date 1194367649 21600
> # Node ID cb186258bc6ecf05ded03d81a3d2ee820e58f605
> # Parent  7ea01f673a05fe66cb0d9c514b5a43ddcd72c07f
> Move kvm_create_memory_alias & kvm_destroy_memory_alias to libkvm-x86.c
>
> Signed-off-by: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
>
> diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
> --- a/libkvm/libkvm-x86.c
> +++ b/libkvm/libkvm-x86.c
> @@ -294,3 +294,32 @@ void *kvm_create_kernel_phys_mem(kvm_con
>  	return ptr;
>  }
>  
> +int kvm_create_memory_alias(kvm_context_t kvm,
> +			    uint64_t phys_addr,
> +			    uint64_t phys_start,
> +			    uint64_t len,
> +			    uint64_t target_phys)
> +{
> +	struct kvm_memory_alias alias = {
> +		.flags = 0,
> +		.guest_phys_addr = phys_start,
> +		.memory_size = len,
> +		.target_phys_addr = target_phys,
> +	};
> +	int fd = kvm->vm_fd;
> +	int r;
> +
> +	alias.slot = get_slot(phys_addr);
> +
> +	r = ioctl(fd, KVM_SET_MEMORY_ALIAS, &alias);
> +	if (r == -1)
> +	    return -errno;
> +
> +	return 0;
> +}
> +
> +int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_addr)
> +{
> +	return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0);
> +}
> +
>
>   

This is missing the delete part of the move.  I supplied it.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 00 of 17] [v4] libkvm refactor
  2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
                   ` (16 preceding siblings ...)
  2007-11-06 16:48 ` [PATCH 17 of 17] Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h Jerone Young
@ 2007-11-07 13:52 ` Avi Kivity
  17 siblings, 0 replies; 27+ messages in thread
From: Avi Kivity @ 2007-11-07 13:52 UTC (permalink / raw)
  To: Jerone Young
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Jerone Young wrote:
> Here is the 4th revision of the refactoring of libkvm. This revision
> changes since the 3rd revision:
> 	- removes libkvm-x86.h
> 	- keeps functions kvm_create_default_phys_mem & kvm_create_phys_mem
> 	  in place
> 	- added kvm_arch_create_default_phys_mem
> 	- Adds needed copyrights to new files
> 	- Adds void to slots() --> slots(void) decleartions
>
>   

Applied the lot; thanks.


-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 11 of 17] Move msrs functions to libkvm-x86.c
  2007-11-08  5:57   ` Carlo Marcelo Arenas Belon
@ 2007-11-08  5:54     ` Avi Kivity
       [not found]       ` <4732A4AE.30100-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 27+ messages in thread
From: Avi Kivity @ 2007-11-08  5:54 UTC (permalink / raw)
  To: Carlo Marcelo Arenas Belon
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jerone Young

Carlo Marcelo Arenas Belon wrote:
> On Tue, Nov 06, 2007 at 10:48:52AM -0600, Jerone Young wrote:
>   
>> Move msrs functions to libkvm-x86.c
>>
>> This patch moves functions:
>> 	kvm_msr_list
>> 	move kvm_get_msrs
>> 	move kvm_set_msrs
>>     
>
> the problem is that with this the definitions were moved as well from libkvm.h
> to kvm-x86.h which is private and not meant to be exported outside of libkvm
> but those 3 functions are used by qemu-kvm.c as shown by :
>
>   

They need to be moved back to libkvm.h with a #ifdef.  And to the #ifdef
purists I say: deorbit.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 11 of 17] Move msrs functions to libkvm-x86.c
  2007-11-06 16:48 ` [PATCH 11 of 17] Move msrs " Jerone Young
@ 2007-11-08  5:57   ` Carlo Marcelo Arenas Belon
  2007-11-08  5:54     ` Avi Kivity
  0 siblings, 1 reply; 27+ messages in thread
From: Carlo Marcelo Arenas Belon @ 2007-11-08  5:57 UTC (permalink / raw)
  To: Jerone Young
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Tue, Nov 06, 2007 at 10:48:52AM -0600, Jerone Young wrote:
> Move msrs functions to libkvm-x86.c
> 
> This patch moves functions:
> 	kvm_msr_list
> 	move kvm_get_msrs
> 	move kvm_set_msrs

the problem is that with this the definitions were moved as well from libkvm.h
to kvm-x86.h which is private and not meant to be exported outside of libkvm
but those 3 functions are used by qemu-kvm.c as shown by :

/var/tmp/portage/app-emulation/kvm-51/work/kvm-51/qemu/qemu-kvm.c: In function
`load_regs':
/var/tmp/portage/app-emulation/kvm-51/work/kvm-51/qemu/qemu-kvm.c:319:
warning: implicit declaration of function `kvm_set_msrs'
/var/tmp/portage/app-emulation/kvm-51/work/kvm-51/qemu/qemu-kvm.c: In function
`save_regs':
/var/tmp/portage/app-emulation/kvm-51/work/kvm-51/qemu/qemu-kvm.c:457:
warning: implicit declaration of function `kvm_get_msrs'
/var/tmp/portage/app-emulation/kvm-51/work/kvm-51/qemu/qemu-kvm.c: In function
`kvm_qemu_create_context':
/var/tmp/portage/app-emulation/kvm-51/work/kvm-51/qemu/qemu-kvm.c:1020:
warning: implicit declaration of function `kvm_get_msr_list'
/var/tmp/portage/app-emulation/kvm-51/work/kvm-51/qemu/qemu-kvm.c:1020:
warning: assignment makes pointer from integer without a cast

the following patch moves them to a new public arch specific header for libkvm
named libkvm-x86.h and that needs to be installed in userspace as well but is
not completely independent and would had been as well ifdef inside libkvm.h
for simplicity.

Jerone or anyone else that is working in the architectural work care to
comment?

Carlo

PS. tested in amd64
--
diff --git a/libkvm/Makefile b/libkvm/Makefile
index 65efb3a..bbeb564 100644
--- a/libkvm/Makefile
+++ b/libkvm/Makefile
@@ -26,6 +26,7 @@ libkvm.a: libkvm.o $(libkvm-$(ARCH)-objs)
 
 install:
 	install -D libkvm.h $(DESTDIR)/$(PREFIX)/include/libkvm.h
+	install -D libkvm-x86.h $(DESTDIR)/$(PREFIX)/include/libkvm-x86.h
 	install -D $(KERNELDIR)/include/linux/kvm.h \
 		$(DESTDIR)/$(PREFIX)/include/linux/kvm.h
 	install -D $(KERNELDIR)/include/linux/kvm_para.h \
diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
index b531a3b..1e1c718 100644
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -19,8 +19,7 @@
 #define KVM_X86_H
 
 #include "kvm-common.h"
-
-#include "kvm-common.h"
+#include "libkvm-x86.h"
 
 #define PAGE_SIZE 4096ul
 #define PAGE_MASK (~(PAGE_SIZE - 1))
@@ -42,8 +41,4 @@ int kvm_run_abi10(kvm_context_t kvm, int vcpu);
 
 void kvm_show_code(kvm_context_t kvm, int vcpu);
 
-struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
-int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
-int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
-
 #endif
diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h
new file mode 100644
index 0000000..6531d1f
--- /dev/null
+++ b/libkvm/libkvm-x86.h
@@ -0,0 +1,12 @@
+/** \file libkvm-x86.h
+ * libkvm for x86 API
+ */
+
+#ifndef LIBKVM_X86_H
+#define LIBKVM_X86_H
+
+struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm);
+int kvm_get_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, int n);
+int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, int n);
+
+#endif
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
index b00d658..173566f 100644
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -19,6 +19,10 @@ struct kvm_context;
 
 typedef struct kvm_context *kvm_context_t;
 
+#if defined(__x86_64__) || defined(__i386__)
+#include <libkvm-x86.h>
+#endif
+
 /*!
  * \brief KVM callbacks structure
  *

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH] make msrs functions public for x86
       [not found]       ` <4732A4AE.30100-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
@ 2007-11-08  6:34         ` Carlo Marcelo Arenas Belon
  2007-11-08  8:30           ` Avi Kivity
  2007-11-08 17:10           ` Jerone Young
  2007-11-08 18:59         ` [PATCH 11 of 17] Move msrs functions to libkvm-x86.c Hollis Blanchard
  1 sibling, 2 replies; 27+ messages in thread
From: Carlo Marcelo Arenas Belon @ 2007-11-08  6:34 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jerone Young

This patch partially reverts 9105435f46ca4e110237eae57272e4f5deaf8dd6 so that
kvm_msr_list, kvm_get_msrs and kvm_set_msrs are again public and visible in
userspace for x86 as they are used by qemu-kvm

Signed-off-by: Carlo Marcelo Arenas Belon <carenas-kLeDWSohozoJb6fo7hG9ng@public.gmane.org>
---
 libkvm/kvm-x86.h |    4 ----
 libkvm/libkvm.h  |    6 ++++++
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
index b531a3b..bcc6981 100644
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -42,8 +42,4 @@ int kvm_run_abi10(kvm_context_t kvm, int vcpu);
 
 void kvm_show_code(kvm_context_t kvm, int vcpu);
 
-struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
-int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
-int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
-
 #endif
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
index b00d658..8a41df7 100644
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -19,6 +19,12 @@ struct kvm_context;
 
 typedef struct kvm_context *kvm_context_t;
 
+#if defined(__x86_64__) || defined(__i386__)
+struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
+int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
+int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
+#endif
+
 /*!
  * \brief KVM callbacks structure
  *
-- 
1.5.2.5


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH] make msrs functions public for x86
  2007-11-08  6:34         ` [PATCH] make msrs functions public for x86 Carlo Marcelo Arenas Belon
@ 2007-11-08  8:30           ` Avi Kivity
  2007-11-08 17:10           ` Jerone Young
  1 sibling, 0 replies; 27+ messages in thread
From: Avi Kivity @ 2007-11-08  8:30 UTC (permalink / raw)
  To: Carlo Marcelo Arenas Belon
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jerone Young

Carlo Marcelo Arenas Belon wrote:
> This patch partially reverts 9105435f46ca4e110237eae57272e4f5deaf8dd6 so that
> kvm_msr_list, kvm_get_msrs and kvm_set_msrs are again public and visible in
> userspace for x86 as they are used by qemu-kvm
>   

Applied, thanks.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] make msrs functions public for x86
  2007-11-08  6:34         ` [PATCH] make msrs functions public for x86 Carlo Marcelo Arenas Belon
  2007-11-08  8:30           ` Avi Kivity
@ 2007-11-08 17:10           ` Jerone Young
  1 sibling, 0 replies; 27+ messages in thread
From: Jerone Young @ 2007-11-08 17:10 UTC (permalink / raw)
  To: Carlo Marcelo Arenas Belon
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Avi Kivity

This would be my bad. Things kept changing and I didn't put these back
into libkvm.h.

On Thu, 2007-11-08 at 00:34 -0600, Carlo Marcelo Arenas Belon wrote:
> This patch partially reverts 9105435f46ca4e110237eae57272e4f5deaf8dd6 so that
> kvm_msr_list, kvm_get_msrs and kvm_set_msrs are again public and visible in
> userspace for x86 as they are used by qemu-kvm
> 
> Signed-off-by: Carlo Marcelo Arenas Belon <carenas-kLeDWSohozoJb6fo7hG9ng@public.gmane.org>
> ---
>  libkvm/kvm-x86.h |    4 ----
>  libkvm/libkvm.h  |    6 ++++++
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
> index b531a3b..bcc6981 100644
> --- a/libkvm/kvm-x86.h
> +++ b/libkvm/kvm-x86.h
> @@ -42,8 +42,4 @@ int kvm_run_abi10(kvm_context_t kvm, int vcpu);
> 
>  void kvm_show_code(kvm_context_t kvm, int vcpu);
> 
> -struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
> -int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
> -int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
> -
>  #endif
> diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
> index b00d658..8a41df7 100644
> --- a/libkvm/libkvm.h
> +++ b/libkvm/libkvm.h
> @@ -19,6 +19,12 @@ struct kvm_context;
> 
>  typedef struct kvm_context *kvm_context_t;
> 
> +#if defined(__x86_64__) || defined(__i386__)
> +struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
> +int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
> +int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
> +#endif
> +
>  /*!
>   * \brief KVM callbacks structure
>   *


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 11 of 17] Move msrs functions to libkvm-x86.c
       [not found]       ` <4732A4AE.30100-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  2007-11-08  6:34         ` [PATCH] make msrs functions public for x86 Carlo Marcelo Arenas Belon
@ 2007-11-08 18:59         ` Hollis Blanchard
  2007-11-11 10:01           ` Avi Kivity
  1 sibling, 1 reply; 27+ messages in thread
From: Hollis Blanchard @ 2007-11-08 18:59 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jerone Young,
	Carlo Marcelo Arenas Belon

On Thu, 2007-11-08 at 07:54 +0200, Avi Kivity wrote:
> Carlo Marcelo Arenas Belon wrote:
> > On Tue, Nov 06, 2007 at 10:48:52AM -0600, Jerone Young wrote:
> >   
> >> Move msrs functions to libkvm-x86.c
> >>
> >> This patch moves functions:
> >> 	kvm_msr_list
> >> 	move kvm_get_msrs
> >> 	move kvm_set_msrs
> >>     
> >
> > the problem is that with this the definitions were moved as well from libkvm.h
> > to kvm-x86.h which is private and not meant to be exported outside of libkvm
> > but those 3 functions are used by qemu-kvm.c as shown by :
> >
> >   
> 
> They need to be moved back to libkvm.h with a #ifdef.  And to the #ifdef
> purists I say: deorbit.

Re-entry is looking rough; things are much better up here. ;)

Anyways, you don't need to ifdef a prototype; just don't call it.

Also, naming them kvm_x86_get_msrs() and kvm_x86_set_msrs() would be a
much better warning sign for callers.

-- 
Hollis Blanchard
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 11 of 17] Move msrs functions to libkvm-x86.c
  2007-11-08 18:59         ` [PATCH 11 of 17] Move msrs functions to libkvm-x86.c Hollis Blanchard
@ 2007-11-11 10:01           ` Avi Kivity
  0 siblings, 0 replies; 27+ messages in thread
From: Avi Kivity @ 2007-11-11 10:01 UTC (permalink / raw)
  To: Hollis Blanchard
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Jerone Young,
	Carlo Marcelo Arenas Belon

Hollis Blanchard wrote:
> On Thu, 2007-11-08 at 07:54 +0200, Avi Kivity wrote:
>   
>> Carlo Marcelo Arenas Belon wrote:
>>     
>>> On Tue, Nov 06, 2007 at 10:48:52AM -0600, Jerone Young wrote:
>>>   
>>>       
>>>> Move msrs functions to libkvm-x86.c
>>>>
>>>> This patch moves functions:
>>>> 	kvm_msr_list
>>>> 	move kvm_get_msrs
>>>> 	move kvm_set_msrs
>>>>     
>>>>         
>>> the problem is that with this the definitions were moved as well from libkvm.h
>>> to kvm-x86.h which is private and not meant to be exported outside of libkvm
>>> but those 3 functions are used by qemu-kvm.c as shown by :
>>>
>>>   
>>>       
>> They need to be moved back to libkvm.h with a #ifdef.  And to the #ifdef
>> purists I say: deorbit.
>>     
>
> Re-entry is looking rough; things are much better up here. ;)
>
> Anyways, you don't need to ifdef a prototype; just don't call it.
>   

See, that's what I meant:  you're willing to turn a compile error into a 
link error just because you dislike #ifdefs.

There are some things the preprocessor does well, there's no need to ban 
it just because it is often abused.

> Also, naming them kvm_x86_get_msrs() and kvm_x86_set_msrs() would be a
> much better warning sign for callers.
>   

The rename makes sense, in addition to guarding the prototypes.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2007-11-11 10:01 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-06 16:48 [PATCH 00 of 17] [v4] libkvm refactor Jerone Young
2007-11-06 16:48 ` [PATCH 01 of 17] Move kvm_context to kvm-common.h & add CFLAGS to config-* filese Jerone Young
2007-11-06 16:48 ` [PATCH 02 of 17] Make static slot & kvm_memory region funcions public Jerone Young
2007-11-06 16:48 ` [PATCH 03 of 17] Move fuction kvm_alloc_kernel_memory to libkvm-x86.c Jerone Young
2007-11-06 16:48 ` [PATCH 04 of 17] Move kvm_alloc_userspace_memory " Jerone Young
2007-11-06 16:48 ` [PATCH 05 of 17] Modify out arch specific code from kvm_create function Jerone Young
2007-11-06 16:48 ` [PATCH 06 of 17] Move kvm_create_kernel_phys_mem to libkvm-x86.c Jerone Young
2007-11-06 16:48 ` [PATCH 07 of 17] Move kvm_create_memory_alias & kvm_destroy_memory_alias " Jerone Young
2007-11-07 13:52   ` Avi Kivity
2007-11-06 16:48 ` [PATCH 08 of 17] Move kvm_get & kmv_set_lapci functions " Jerone Young
2007-11-06 16:48 ` [PATCH 09 of 17] Make functions in libkvm.c nonstatic Jerone Young
2007-11-06 16:48 ` [PATCH 10 of 17] Move abi 10 functions to libkvm-x86.c Jerone Young
2007-11-06 16:48 ` [PATCH 11 of 17] Move msrs " Jerone Young
2007-11-08  5:57   ` Carlo Marcelo Arenas Belon
2007-11-08  5:54     ` Avi Kivity
     [not found]       ` <4732A4AE.30100-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-08  6:34         ` [PATCH] make msrs functions public for x86 Carlo Marcelo Arenas Belon
2007-11-08  8:30           ` Avi Kivity
2007-11-08 17:10           ` Jerone Young
2007-11-08 18:59         ` [PATCH 11 of 17] Move msrs functions to libkvm-x86.c Hollis Blanchard
2007-11-11 10:01           ` Avi Kivity
2007-11-06 16:48 ` [PATCH 12 of 17] Move print_seg & Move kvm_show_regs " Jerone Young
2007-11-06 16:48 ` [PATCH 13 of 17] Declare kvm_abi as a global variable in kvm-common.h Jerone Young
2007-11-06 16:48 ` [PATCH 14 of 17] Move kvm_get_apic to libkvm-x86.c Jerone Young
2007-11-06 16:48 ` [PATCH 15 of 17] Move cr8 functions " Jerone Young
2007-11-06 16:48 ` [PATCH 16 of 17] Move kvm_setup_cpuid " Jerone Young
2007-11-06 16:48 ` [PATCH 17 of 17] Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h Jerone Young
2007-11-07 13:52 ` [PATCH 00 of 17] [v4] libkvm refactor Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox