public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH 05 of 20] Modify out arch specific code from kvm_create	function
Date: Fri, 02 Nov 2007 05:36:41 -0500	[thread overview]
Message-ID: <e3def9892f39527f216a.1193999801@thinkpad> (raw)
In-Reply-To: <patchbomb.1193999796@thinkpad>

# HG changeset patch
# User Jerone Young <jyoung5-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1193997379 18000
# Node ID e3def9892f39527f216acbde2de4dad0e8501183
# Parent  5ad14643e8eccb6aec15a5b7779f9a026dd2d204
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-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -31,4 +31,9 @@ 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);
+
+int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
+			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
@@ -8,6 +8,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)
@@ -187,3 +191,87 @@ 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;
+}
+
+static int kvm_x86_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
+	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
+	if (r > 0)
+		r = kvm_alloc_userspace_memory(kvm, memory, vm_mem);
+	else
+#endif
+ 		r = kvm_alloc_kernel_memory(kvm, memory, vm_mem);
+	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);
+
+	kvm->physical_memory = *vm_mem;
+	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;
+	r = kvm_x86_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
+	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
@@ -335,72 +335,7 @@ 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
-	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
-	if (r > 0)
-		r = kvm_alloc_userspace_memory(kvm, memory, vm_mem);
-	else
-#endif
-		r = kvm_alloc_kernel_memory(kvm, memory, vm_mem);
-	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);
-
-	kvm->physical_memory = *vm_mem;
-	return 0;
-}
+
 
 void kvm_create_irqchip(kvm_context_t kvm)
 {
@@ -428,13 +363,10 @@ 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();
-	r = kvm_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
-	if (r < 0)
-	        return r;
 	kvm_create_irqchip(kvm);
 	r = kvm_create_vcpu(kvm, 0);
 	if (r < 0)
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/

  parent reply	other threads:[~2007-11-02 10:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-02 10:36 [PATCH 00 of 20] [RESEND] Refactor libkvm code Phase 1 Jerone Young
2007-11-02 10:36 ` [PATCH 01 of 20] Move kvm_context to kvmctl.h Jerone Young
2007-11-02 17:28   ` [kvm-ppc-devel] " Hollis Blanchard
2007-11-02 17:42     ` Jerone Young
2007-11-02 10:36 ` [PATCH 02 of 20] Make static slot & kvm_memory region funcions public Jerone Young
2007-11-02 10:36 ` [PATCH 03 of 20] Move fuction kvm_alloc_kernel_memory to libkvm-x86.c Jerone Young
2007-11-02 10:36 ` [PATCH 04 of 20] Move kvm_alloc_userspace_memory " Jerone Young
2007-11-02 10:36 ` Jerone Young [this message]
2007-11-02 10:36 ` [PATCH 06 of 20] Move kvm_create_kernel_phys_mem " Jerone Young
2007-11-02 10:36 ` [PATCH 07 of 20] Move kvm_create_phys_mem " Jerone Young
2007-11-02 10:36 ` [PATCH 08 of 20] Move kvm_destroy_phys_mem " Jerone Young
2007-11-02 10:36 ` [PATCH 09 of 20] Move kvm_create_memory_alias & kvm_destroy_memory_alias " Jerone Young
2007-11-02 10:36 ` [PATCH 10 of 20] Move kvm_get & kmv_set_lapci functions " Jerone Young
2007-11-02 10:36 ` [PATCH 11 of 20] Make functions in libkvm.c nonstatic Jerone Young
2007-11-02 10:36 ` [PATCH 12 of 20] Move abi 10 functions to libkvm-x86.c Jerone Young
2007-11-02 10:36 ` [PATCH 13 of 20] Move msrs " Jerone Young
2007-11-02 10:36 ` [PATCH 14 of 20] Move print_seg & Move kvm_show_regs to kvmctl-x86.c Jerone Young
2007-11-02 10:36 ` [PATCH 15 of 20] Declare kvm_abi as a global variable in libkvm.h Jerone Young
2007-11-02 10:36 ` [PATCH 16 of 20] Move kvm_get_apic to libkvm-x86.c Jerone Young
2007-11-02 10:36 ` [PATCH 17 of 20] Move cr8 functions " Jerone Young
2007-11-02 10:36 ` [PATCH 18 of 20] Move kvm_setup_cpuid " Jerone Young
2007-11-02 10:36 ` [PATCH 19 of 20] Move kvm_show_code " Jerone Young
2007-11-02 10:36 ` [PATCH 20 of 20] Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h Jerone Young

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=e3def9892f39527f216a.1193999801@thinkpad \
    --to=jyoung5-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

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

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