All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]0/5 Patch to split x86 specific code from kvm_main.c
@ 2007-11-08  7:21 Zhang, Xiantao
       [not found] ` <42DFA526FC41B1429CE7279EF83C6BDC905003-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang, Xiantao @ 2007-11-08  7:21 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	carsteno-tA70FqPdS9bQT0dZR+AlfA, Hollis Blanchard

Hi Avi,
This series of patches are intended to further split x86 specific code
from kvm_main.c, and make kvm_main.c arch-independent.  
For easy review, I splitted them into small patches. With these patches,
we almost finish the first stage work for code split. 

[1/5] Remove unused header files include from kvm_main.c since the
corresponding functions have been moved to x86.c
[2/5] Move kvm_x86_ops definition to x86, and prepare for next step's
work.
[3/5] Using kvm_arch prefix to redefine kvm_x86_ops->ops in x86.c. and
make kvm_x86_ops as x86_specific part.
[4/5] Combine kvm_init and kvm_init_x86 into one kvm_init function, and
meanwhile, remove module_init and module_exit function since kvm_init
will called by svm and vmx.
[5/5] Make kvm_init as arch-indepenent, through defining a void pointer
type parameter . All archs will register their corresponding functions
into kvm module. For example, x86 will use this parameter to register
vmx/svm's ops. 

CC to Hollis and Carste to check whether they block your sides. :) 

Thanks 
Xiantao

-------------------------------------------------------------------------
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] 4+ messages in thread

* Re: [PATCH]0/5 Patch to split x86 specific code from kvm_main.c
       [not found] ` <42DFA526FC41B1429CE7279EF83C6BDC905003-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2007-11-08 12:06   ` Carsten Otte
       [not found]     ` <4732FBC1.3030301-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Otte @ 2007-11-08 12:06 UTC (permalink / raw)
  To: Zhang, Xiantao
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	carsteno-tA70FqPdS9bQT0dZR+AlfA, Hollis Blanchard, Avi Kivity

Zhang, Xiantao wrote:
> This series of patches are intended to further split x86 specific code
> from kvm_main.c, and make kvm_main.c arch-independent.  
> For easy review, I splitted them into small patches. With these patches,
> we almost finish the first stage work for code split. 

These patches don't apply on top of my git tree:
Wende Patch 01-xiantao.patch an
patching file drivers/kvm/kvm_main.c
Hunk #1 succeeded at 17 with fuzz 2.
Hunk #2 succeeded at 43 with fuzz 2.
patching file drivers/kvm/x86.c
Hunk #1 succeeded at 16 with fuzz 1.
Hunk #2 FAILED at 26.
1 out of 2 hunks FAILED -- rejects in file drivers/kvm/x86.c

-------------------------------------------------------------------------
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] 4+ messages in thread

* Re: [PATCH]0/5 Patch to split x86 specific code from kvm_main.c
       [not found]     ` <4732FBC1.3030301-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
@ 2007-11-08 12:59       ` Zhang, Xiantao
       [not found]         ` <42DFA526FC41B1429CE7279EF83C6BDC94EE2B-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang, Xiantao @ 2007-11-08 12:59 UTC (permalink / raw)
  To: carsteno-tA70FqPdS9bQT0dZR+AlfA
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Hollis Blanchard,
	Avi Kivity

[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]

 Hi,Carste 
	Maybe some new commits  block it.  I will rebase them to latest commit, and resend :)
Thanks for you try.
Xiantao

-----Original Message-----
From: Carsten Otte [mailto:cotte-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org] 
Sent: 2007年11月8日 20:06
To: Zhang, Xiantao
Cc: Avi Kivity; kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org; Hollis Blanchard; carsteno-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH]0/5 Patch to split x86 specific code from kvm_main.c

Zhang, Xiantao wrote:
> This series of patches are intended to further split x86 specific code
> from kvm_main.c, and make kvm_main.c arch-independent.  
> For easy review, I splitted them into small patches. With these patches,
> we almost finish the first stage work for code split. 

These patches don't apply on top of my git tree:
Wende Patch 01-xiantao.patch an
patching file drivers/kvm/kvm_main.c
Hunk #1 succeeded at 17 with fuzz 2.
Hunk #2 succeeded at 43 with fuzz 2.
patching file drivers/kvm/x86.c
Hunk #1 succeeded at 16 with fuzz 1.
Hunk #2 FAILED at 26.
1 out of 2 hunks FAILED -- rejects in file drivers/kvm/x86.c


[-- Attachment #2: Type: text/plain, Size: 314 bytes --]

-------------------------------------------------------------------------
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/

[-- Attachment #3: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

* [Resend ] [PATCH]0/5 Patch to split x86 specific code fromkvm_main.c, rebase to latest commits
       [not found]         ` <42DFA526FC41B1429CE7279EF83C6BDC94EE2B-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2007-11-08 13:36           ` Zhang, Xiantao
  0 siblings, 0 replies; 4+ messages in thread
From: Zhang, Xiantao @ 2007-11-08 13:36 UTC (permalink / raw)
  To: Zhang, Xiantao, carsteno-tA70FqPdS9bQT0dZR+AlfA
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Avi Kivity,
	Hollis Blanchard

[-- Attachment #1: Type: text/plain, Size: 1673 bytes --]

Rebased to latest commits. 
Thanks 
Xiantao

-----Original Message-----
From: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org [mailto:kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] On Behalf Of Zhang, Xiantao
Sent: 2007年11月8日 21:00
To: carsteno-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org; Hollis Blanchard; Avi Kivity
Subject: Re: [kvm-devel] [PATCH]0/5 Patch to split x86 specific code fromkvm_main.c

 Hi,Carste 
	Maybe some new commits  block it.  I will rebase them to latest commit, and resend :)
Thanks for you try.
Xiantao

-----Original Message-----
From: Carsten Otte [mailto:cotte-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org] 
Sent: 2007年11月8日 20:06
To: Zhang, Xiantao
Cc: Avi Kivity; kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org; Hollis Blanchard; carsteno-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH]0/5 Patch to split x86 specific code from kvm_main.c

Zhang, Xiantao wrote:
> This series of patches are intended to further split x86 specific code
> from kvm_main.c, and make kvm_main.c arch-independent.  
> For easy review, I splitted them into small patches. With these patches,
> we almost finish the first stage work for code split. 

These patches don't apply on top of my git tree:
Wende Patch 01-xiantao.patch an
patching file drivers/kvm/kvm_main.c
Hunk #1 succeeded at 17 with fuzz 2.
Hunk #2 succeeded at 43 with fuzz 2.
patching file drivers/kvm/x86.c
Hunk #1 succeeded at 16 with fuzz 1.
Hunk #2 FAILED at 26.
1 out of 2 hunks FAILED -- rejects in file drivers/kvm/x86.c


[-- Attachment #2: 0001-Move-some-includes-to-x86.c-from-kvm_main.c-since-t.patch --]
[-- Type: application/octet-stream, Size: 1320 bytes --]

From e119cb6a06632e4ac0b2e0fc33054d6b07efdda3 Mon Sep 17 00:00:00 2001
From: Zhang Xiantao <xiantao.zhang@intel.com>
Date: Thu, 8 Nov 2007 21:09:17 +0800
Subject: [PATCH] Move some includes to x86.c from kvm_main.c, since the related functions have been moved to x86.c
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
---
 drivers/kvm/kvm_main.c |    2 --
 drivers/kvm/x86.c      |    2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index d095002..8357fbb 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -17,7 +17,6 @@
 
 #include "kvm.h"
 #include "x86.h"
-#include "x86_emulate.h"
 #include "irq.h"
 
 #include <linux/kvm.h>
@@ -44,7 +43,6 @@
 #include <linux/mman.h>
 
 #include <asm/processor.h>
-#include <asm/msr.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <asm/desc.h>
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index e905d46..7ea470e 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -16,6 +16,7 @@
 
 #include "kvm.h"
 #include "x86.h"
+#include "x86_emulate.h"
 #include "segment_descriptor.h"
 #include "irq.h"
 
@@ -25,6 +26,7 @@
 #include <linux/module.h>
 
 #include <asm/uaccess.h>
+#include <asm/msr.h>
 
 #define MAX_IO_MSRS 256
 #define CR0_RESERVED_BITS						\
-- 
1.5.1.2


[-- Attachment #3: 0002-move-kvm_x86_ops-to-x86.c.patch --]
[-- Type: application/octet-stream, Size: 1546 bytes --]

From 5f2d0f4ba1570db707797018dc7cc73f81e15b77 Mon Sep 17 00:00:00 2001
From: Zhang Xiantao <xiantao.zhang@intel.com>
Date: Thu, 8 Nov 2007 21:11:03 +0800
Subject: [PATCH] move kvm_x86_ops to x86.c
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
---
 drivers/kvm/kvm_main.c |    1 -
 drivers/kvm/x86.c      |    2 ++
 drivers/kvm/x86.h      |    2 ++
 3 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 8357fbb..de5bf1f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -55,7 +55,6 @@ static LIST_HEAD(vm_list);
 
 static cpumask_t cpus_hardware_enabled;
 
-struct kvm_x86_ops *kvm_x86_ops;
 struct kmem_cache *kvm_vcpu_cache;
 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 7ea470e..e26e46a 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -44,6 +44,8 @@
 
 #define STAT_OFFSET(x) offsetof(struct kvm_vcpu, stat.x)
 
+struct kvm_x86_ops *kvm_x86_ops;
+
 struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ "pf_fixed", STAT_OFFSET(pf_fixed) },
 	{ "pf_guest", STAT_OFFSET(pf_guest) },
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 663b822..ec32c26 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -85,6 +85,8 @@ struct kvm_vcpu {
 	struct x86_emulate_ctxt emulate_ctxt;
 };
 
+extern struct kvm_x86_ops *kvm_x86_ops;
+
 int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code);
 
 static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
-- 
1.5.1.2


[-- Attachment #4: 0003-Using-kvm_arch-prefix-to-redefine-kvm_x86_ops-ops-i.patch --]
[-- Type: application/octet-stream, Size: 6086 bytes --]

From b4ac5a637f879695bb1e149e7572248327c46ba7 Mon Sep 17 00:00:00 2001
From: Zhang Xiantao <xiantao.zhang@intel.com>
Date: Thu, 8 Nov 2007 21:17:25 +0800
Subject: [PATCH] Using kvm_arch prefix to redefine kvm_x86_ops->ops in x86.c. and
make kvm_x86_ops as x86_specific part.
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
---
 drivers/kvm/kvm.h      |   15 +++++++++++++++
 drivers/kvm/kvm_main.c |   26 +++++++++++++-------------
 drivers/kvm/x86.c      |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 13 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 091f9b7..e8f6ff1 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -649,6 +649,21 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
 
 __init void kvm_arch_init(void);
 
+
+void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
+void kvm_arch_vcpu_decache(struct kvm_vcpu *vcpu);
+void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
+void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
+struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
+
+int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
+void kvm_arch_hardware_enable(void *garbage);
+void kvm_arch_hardware_disable(void *garbage);
+int kvm_arch_hardware_setup(void);
+void kvm_arch_hardware_unsetup(void);
+void kvm_arch_check_processor_compat(void *rtn);
+
+
 static inline void kvm_guest_enter(void)
 {
 	account_system_vtime(current);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index de5bf1f..629ab54 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -240,7 +240,7 @@ static void kvm_free_vcpus(struct kvm *kvm)
 			kvm_unload_vcpu_mmu(kvm->vcpus[i]);
 	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
 		if (kvm->vcpus[i]) {
-			kvm_x86_ops->vcpu_free(kvm->vcpus[i]);
+			kvm_arch_vcpu_free(kvm->vcpus[i]);
 			kvm->vcpus[i] = NULL;
 		}
 	}
@@ -891,7 +891,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
 	if (!valid_vcpu(n))
 		return -EINVAL;
 
-	vcpu = kvm_x86_ops->vcpu_create(kvm, n);
+	vcpu = kvm_arch_vcpu_create(kvm, n);
 	if (IS_ERR(vcpu))
 		return PTR_ERR(vcpu);
 
@@ -901,7 +901,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
 	BUG_ON((unsigned long)&vcpu->host_fx_image & 0xF);
 
 	vcpu_load(vcpu);
-	r = kvm_x86_ops->vcpu_reset(vcpu);
+	r = kvm_arch_vcpu_reset(vcpu);
 	if (r == 0)
 		r = kvm_mmu_setup(vcpu);
 	vcpu_put(vcpu);
@@ -934,7 +934,7 @@ mmu_unload:
 	vcpu_put(vcpu);
 
 free_vcpu:
-	kvm_x86_ops->vcpu_free(vcpu);
+	kvm_arch_vcpu_free(vcpu);
 	return r;
 }
 
@@ -1298,7 +1298,7 @@ static void decache_vcpus_on_cpu(int cpu)
 			 */
 			if (mutex_trylock(&vcpu->mutex)) {
 				if (vcpu->cpu == cpu) {
-					kvm_x86_ops->vcpu_decache(vcpu);
+					kvm_arch_vcpu_decache(vcpu);
 					vcpu->cpu = -1;
 				}
 				mutex_unlock(&vcpu->mutex);
@@ -1314,7 +1314,7 @@ static void hardware_enable(void *junk)
 	if (cpu_isset(cpu, cpus_hardware_enabled))
 		return;
 	cpu_set(cpu, cpus_hardware_enabled);
-	kvm_x86_ops->hardware_enable(NULL);
+	kvm_arch_hardware_enable(NULL);
 }
 
 static void hardware_disable(void *junk)
@@ -1325,7 +1325,7 @@ static void hardware_disable(void *junk)
 		return;
 	cpu_clear(cpu, cpus_hardware_enabled);
 	decache_vcpus_on_cpu(cpu);
-	kvm_x86_ops->hardware_disable(NULL);
+	kvm_arch_hardware_disable(NULL);
 }
 
 static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
@@ -1493,7 +1493,7 @@ static void kvm_sched_in(struct preempt_notifier *pn, int cpu)
 {
 	struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
 
-	kvm_x86_ops->vcpu_load(vcpu, cpu);
+	kvm_arch_vcpu_load(vcpu, cpu);
 }
 
 static void kvm_sched_out(struct preempt_notifier *pn,
@@ -1501,7 +1501,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
 {
 	struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
 
-	kvm_x86_ops->vcpu_put(vcpu);
+	kvm_arch_vcpu_put(vcpu);
 }
 
 int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
@@ -1526,13 +1526,13 @@ int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
 
 	kvm_x86_ops = ops;
 
-	r = kvm_x86_ops->hardware_setup();
+	r = kvm_arch_hardware_setup();
 	if (r < 0)
 		goto out;
 
 	for_each_online_cpu(cpu) {
 		smp_call_function_single(cpu,
-				kvm_x86_ops->check_processor_compatibility,
+				kvm_arch_check_processor_compat,
 				&r, 0, 1);
 		if (r < 0)
 			goto out_free_0;
@@ -1587,7 +1587,7 @@ out_free_2:
 out_free_1:
 	on_each_cpu(hardware_disable, NULL, 0, 1);
 out_free_0:
-	kvm_x86_ops->hardware_unsetup();
+	kvm_arch_hardware_unsetup();
 out:
 	kvm_x86_ops = NULL;
 	return r;
@@ -1603,7 +1603,7 @@ void kvm_exit_x86(void)
 	unregister_reboot_notifier(&kvm_reboot_notifier);
 	unregister_cpu_notifier(&kvm_cpu_notifier);
 	on_each_cpu(hardware_disable, NULL, 0, 1);
-	kvm_x86_ops->hardware_unsetup();
+	kvm_arch_hardware_unsetup();
 	kvm_x86_ops = NULL;
 }
 EXPORT_SYMBOL_GPL(kvm_exit_x86);
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index e26e46a..20bb469 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2327,3 +2327,50 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
 	fx_restore(&vcpu->host_fx_image);
 }
 EXPORT_SYMBOL_GPL(kvm_put_guest_fpu);
+
+void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
+{
+	kvm_x86_ops->vcpu_free(vcpu);
+}
+
+void kvm_arch_vcpu_decache(struct kvm_vcpu *vcpu)
+{
+	kvm_x86_ops->vcpu_decache(vcpu);
+}
+
+struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
+						unsigned int id)
+{
+	return kvm_x86_ops->vcpu_create(kvm, id);
+}
+
+int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu)
+{
+	return kvm_x86_ops->vcpu_reset(vcpu);
+}
+
+void kvm_arch_hardware_enable(void *garbage)
+{
+	kvm_x86_ops->hardware_enable(garbage);
+}
+
+void kvm_arch_hardware_disable(void *garbage)
+{
+	kvm_x86_ops->hardware_disable(garbage);
+}
+
+int kvm_arch_hardware_setup(void)
+{
+	return kvm_x86_ops->hardware_setup();
+}
+
+void kvm_arch_hardware_unsetup(void)
+{
+	kvm_x86_ops->hardware_unsetup();
+}
+
+void kvm_arch_check_processor_compat(void *rtn)
+{
+	kvm_x86_ops->check_processor_compatibility(rtn);
+}
+
-- 
1.5.1.2


[-- Attachment #5: 0004-Combine-kvm_init-and-kvm_init_x86-into-one-kvm_init.patch --]
[-- Type: application/octet-stream, Size: 4037 bytes --]

From 0a12f34f02ca4d2060c230b5ea65cb1f269ab3fc Mon Sep 17 00:00:00 2001
From: Zhang Xiantao <xiantao.zhang@intel.com>
Date: Thu, 8 Nov 2007 21:18:48 +0800
Subject: [PATCH] Combine kvm_init and kvm_init_x86 into one kvm_init function, and
meanwhile, remove module_init and module_exit function since kvm_init
will called by svm and vmx.
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
---
 drivers/kvm/kvm.h      |    4 +-
 drivers/kvm/kvm_main.c |   60 +++++++++++++++++------------------------------
 drivers/kvm/svm.c      |    4 +-
 drivers/kvm/vmx.c      |    4 +-
 4 files changed, 28 insertions(+), 44 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index e8f6ff1..4da3615 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -494,9 +494,9 @@ void vcpu_load(struct kvm_vcpu *vcpu);
 void vcpu_put(struct kvm_vcpu *vcpu);
 
 
-int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
 		  struct module *module);
-void kvm_exit_x86(void);
+void kvm_exit(void);
 
 int kvm_mmu_module_init(void);
 void kvm_mmu_module_exit(void);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 629ab54..5c40d3d 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1504,12 +1504,27 @@ static void kvm_sched_out(struct preempt_notifier *pn,
 	kvm_arch_vcpu_put(vcpu);
 }
 
-int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
 		  struct module *module)
 {
 	int r;
 	int cpu;
 
+	r = kvm_mmu_module_init();
+	if (r)
+		goto out4;
+
+	kvm_init_debug();
+
+	kvm_arch_init();
+
+	bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
+
+	if (bad_page == NULL) {
+		r = -ENOMEM;
+		goto out;
+	}
+
 	if (kvm_x86_ops) {
 		printk(KERN_ERR "kvm: already loaded the other module\n");
 		return -EEXIST;
@@ -1590,11 +1605,14 @@ out_free_0:
 	kvm_arch_hardware_unsetup();
 out:
 	kvm_x86_ops = NULL;
+	kvm_exit_debug();
+	kvm_mmu_module_exit();
+out4:
 	return r;
 }
-EXPORT_SYMBOL_GPL(kvm_init_x86);
+EXPORT_SYMBOL_GPL(kvm_init);
 
-void kvm_exit_x86(void)
+void kvm_exit(void)
 {
 	misc_deregister(&kvm_dev);
 	kmem_cache_destroy(kvm_vcpu_cache);
@@ -1605,43 +1623,9 @@ void kvm_exit_x86(void)
 	on_each_cpu(hardware_disable, NULL, 0, 1);
 	kvm_arch_hardware_unsetup();
 	kvm_x86_ops = NULL;
-}
-EXPORT_SYMBOL_GPL(kvm_exit_x86);
-
-static __init int kvm_init(void)
-{
-	int r;
-
-	r = kvm_mmu_module_init();
-	if (r)
-		goto out4;
-
-	kvm_init_debug();
-
-	kvm_arch_init();
-
-	bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
-
-	if (bad_page == NULL) {
-		r = -ENOMEM;
-		goto out;
-	}
-
-	return 0;
-
-out:
-	kvm_exit_debug();
-	kvm_mmu_module_exit();
-out4:
-	return r;
-}
-
-static __exit void kvm_exit(void)
-{
 	kvm_exit_debug();
 	__free_page(bad_page);
 	kvm_mmu_module_exit();
 }
+EXPORT_SYMBOL_GPL(kvm_exit);
 
-module_init(kvm_init)
-module_exit(kvm_exit)
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index f54b2ea..11a0010 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1722,13 +1722,13 @@ static struct kvm_x86_ops svm_x86_ops = {
 
 static int __init svm_init(void)
 {
-	return kvm_init_x86(&svm_x86_ops, sizeof(struct vcpu_svm),
+	return kvm_init(&svm_x86_ops, sizeof(struct vcpu_svm),
 			      THIS_MODULE);
 }
 
 static void __exit svm_exit(void)
 {
-	kvm_exit_x86();
+	kvm_exit();
 }
 
 module_init(svm_init)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 6fc981d..2ba31b4 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2659,7 +2659,7 @@ static int __init vmx_init(void)
 	memset(iova, 0xff, PAGE_SIZE);
 	kunmap(vmx_io_bitmap_b);
 
-	r = kvm_init_x86(&vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
+	r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
 	if (r)
 		goto out1;
 
@@ -2680,7 +2680,7 @@ static void __exit vmx_exit(void)
 	__free_page(vmx_io_bitmap_b);
 	__free_page(vmx_io_bitmap_a);
 
-	kvm_exit_x86();
+	kvm_exit();
 }
 
 module_init(vmx_init)
-- 
1.5.1.2


[-- Attachment #6: 0005-Make-kvm_init-as-arch-indepenent-through-defining-a.patch --]
[-- Type: application/octet-stream, Size: 3938 bytes --]

From 60ac429810118effc9189504661a8c968b9117a6 Mon Sep 17 00:00:00 2001
From: Zhang Xiantao <xiantao.zhang@intel.com>
Date: Thu, 8 Nov 2007 21:19:46 +0800
Subject: [PATCH] Make kvm_init as arch-indepenent, through defining a void pointer
type parameter . All archs will register their corresponding functions
into kvm module. For example, x86 will use this parameter to register
vmx/svm's ops.
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
---
 drivers/kvm/kvm.h      |    5 +++--
 drivers/kvm/kvm_main.c |   26 ++++++--------------------
 drivers/kvm/x86.c      |   27 ++++++++++++++++++++++++++-
 3 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 4da3615..ce24fa1 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -494,7 +494,7 @@ void vcpu_load(struct kvm_vcpu *vcpu);
 void vcpu_put(struct kvm_vcpu *vcpu);
 
 
-int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(void *opaque, unsigned int vcpu_size,
 		  struct module *module);
 void kvm_exit(void);
 
@@ -647,7 +647,8 @@ int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu,
 				    struct kvm_debug_guest *dbg);
 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
 
-__init void kvm_arch_init(void);
+int kvm_arch_init(void *opaque);
+void kvm_arch_exit(void);
 
 
 void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 5c40d3d..5a3ce76 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1504,7 +1504,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
 	kvm_arch_vcpu_put(vcpu);
 }
 
-int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(void *opaque, unsigned int vcpu_size,
 		  struct module *module)
 {
 	int r;
@@ -1516,7 +1516,9 @@ int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
 
 	kvm_init_debug();
 
-	kvm_arch_init();
+	r = kvm_arch_init(opaque);
+	if (r)
+		goto out4;
 
 	bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
 
@@ -1525,22 +1527,6 @@ int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
 		goto out;
 	}
 
-	if (kvm_x86_ops) {
-		printk(KERN_ERR "kvm: already loaded the other module\n");
-		return -EEXIST;
-	}
-
-	if (!ops->cpu_has_kvm_support()) {
-		printk(KERN_ERR "kvm: no hardware support\n");
-		return -EOPNOTSUPP;
-	}
-	if (ops->disabled_by_bios()) {
-		printk(KERN_ERR "kvm: disabled by bios\n");
-		return -EOPNOTSUPP;
-	}
-
-	kvm_x86_ops = ops;
-
 	r = kvm_arch_hardware_setup();
 	if (r < 0)
 		goto out;
@@ -1604,7 +1590,7 @@ out_free_1:
 out_free_0:
 	kvm_arch_hardware_unsetup();
 out:
-	kvm_x86_ops = NULL;
+	kvm_arch_exit();
 	kvm_exit_debug();
 	kvm_mmu_module_exit();
 out4:
@@ -1622,7 +1608,7 @@ void kvm_exit(void)
 	unregister_cpu_notifier(&kvm_cpu_notifier);
 	on_each_cpu(hardware_disable, NULL, 0, 1);
 	kvm_arch_hardware_unsetup();
-	kvm_x86_ops = NULL;
+	kvm_arch_exit();
 	kvm_exit_debug();
 	__free_page(bad_page);
 	kvm_mmu_module_exit();
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 20bb469..e2e8e63 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -1611,9 +1611,34 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
 
-__init void kvm_arch_init(void)
+int kvm_arch_init(void *opaque)
 {
+	struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
+
 	kvm_init_msr_list();
+
+	if (kvm_x86_ops) {
+		printk(KERN_ERR "kvm: already loaded the other module\n");
+		return -EEXIST;
+	}
+
+	if (!ops->cpu_has_kvm_support()) {
+		printk(KERN_ERR "kvm: no hardware support\n");
+		return -EOPNOTSUPP;
+	}
+	if (ops->disabled_by_bios()) {
+		printk(KERN_ERR "kvm: disabled by bios\n");
+		return -EOPNOTSUPP;
+	}
+
+	kvm_x86_ops = ops;
+
+	return 0;
+}
+
+void kvm_arch_exit(void)
+{
+	kvm_x86_ops = NULL;
 }
 
 int kvm_emulate_halt(struct kvm_vcpu *vcpu)
-- 
1.5.1.2


[-- Attachment #7: Type: text/plain, Size: 314 bytes --]

-------------------------------------------------------------------------
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/

[-- Attachment #8: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

end of thread, other threads:[~2007-11-08 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-08  7:21 [PATCH]0/5 Patch to split x86 specific code from kvm_main.c Zhang, Xiantao
     [not found] ` <42DFA526FC41B1429CE7279EF83C6BDC905003-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-11-08 12:06   ` Carsten Otte
     [not found]     ` <4732FBC1.3030301-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-11-08 12:59       ` Zhang, Xiantao
     [not found]         ` <42DFA526FC41B1429CE7279EF83C6BDC94EE2B-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-11-08 13:36           ` [Resend ] [PATCH]0/5 Patch to split x86 specific code fromkvm_main.c, rebase to latest commits Zhang, Xiantao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.