linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III)
@ 2007-12-30  7:09 Avi Kivity
  2007-12-30  7:09 ` [PATCH 01/52] KVM: Remove ptr comparisons to 0 Avi Kivity
                   ` (51 more replies)
  0 siblings, 52 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

The third installment of the 2.6.25 kvm patch queue, for your reviewing
pleasure.  This time, a diffstat of the files affected by these 53 patches is
appended.

 drivers/kvm/kvm.h         |  384 ++++++---------------------------------------
 drivers/kvm/kvm_main.c    |  192 +++++++---------------
 drivers/kvm/mmu.c         |  113 +++++++++++---
 drivers/kvm/paging_tmpl.h |  156 +++++++------------
 drivers/kvm/svm.c         |    4 +-
 drivers/kvm/vmx.c         |    5 +-
 drivers/kvm/x86.c         |  261 +++++++++++++++++++++++++------
 drivers/kvm/x86.h         |  331 ++++++++++++++++++++++++++++++++++++++
 drivers/kvm/x86_emulate.c |   38 +++++-
 drivers/kvm/x86_emulate.h |   18 +--
 include/asm-x86/Kbuild    |    1 +
 include/asm-x86/kvm.h     |  155 ++++++++++++++++++
 include/linux/kvm.h       |  137 +----------------
 13 files changed, 1003 insertions(+), 792 deletions(-)

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

* [PATCH 01/52] KVM: Remove ptr comparisons to 0
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 02/52] KVM: Remove __init attributes for kvm_init_debug and kvm_init_msr_list Avi Kivity
                   ` (50 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Joe Perches

From: Joe Perches <joe@perches.com>

Fix sparse warnings "Using plain integer as NULL pointer"

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    2 +-
 drivers/kvm/kvm_main.c |    3 ++-
 drivers/kvm/svm.c      |    2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index e34e246..c4ad66b 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -398,7 +398,7 @@ static inline struct kvm_ioapic *ioapic_irqchip(struct kvm *kvm)
 
 static inline int irqchip_in_kernel(struct kvm *kvm)
 {
-	return pic_irqchip(kvm) != 0;
+	return pic_irqchip(kvm) != NULL;
 }
 
 struct descriptor_table {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index bce4216..7a871e0 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1449,7 +1449,8 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
 
 	/* A kmem cache lets us meet the alignment requirements of fx_save. */
 	kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size,
-					   __alignof__(struct kvm_vcpu), 0, 0);
+					   __alignof__(struct kvm_vcpu),
+					   0, NULL);
 	if (!kvm_vcpu_cache) {
 		r = -ENOMEM;
 		goto out_free_4;
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 0f0958d..762302a 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1271,7 +1271,7 @@ static int handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		       exit_code);
 
 	if (exit_code >= ARRAY_SIZE(svm_exit_handlers)
-	    || svm_exit_handlers[exit_code] == 0) {
+	    || !svm_exit_handlers[exit_code]) {
 		kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
 		kvm_run->hw.hardware_exit_reason = exit_code;
 		return 0;
-- 
1.5.3.7


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

* [PATCH 02/52] KVM: Remove __init attributes for kvm_init_debug and kvm_init_msr_list
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
  2007-12-30  7:09 ` [PATCH 01/52] KVM: Remove ptr comparisons to 0 Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 03/52] KVM: Portability: Add two hooks to handle kvm_create and destroy vm Avi Kivity
                   ` (49 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Since their callers are not declared with __init.

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.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 7a871e0..acd26cf 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1332,7 +1332,7 @@ static u64 stat_get(void *_offset)
 
 DEFINE_SIMPLE_ATTRIBUTE(stat_fops, stat_get, NULL, "%llu\n");
 
-static __init void kvm_init_debug(void)
+static void kvm_init_debug(void)
 {
 	struct kvm_stats_debugfs_item *p;
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index f1746af..abb7bee 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -1049,7 +1049,7 @@ out:
 	return r;
 }
 
-static __init void kvm_init_msr_list(void)
+static void kvm_init_msr_list(void)
 {
 	u32 dummy[2];
 	unsigned i, j;
-- 
1.5.3.7


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

* [PATCH 03/52] KVM: Portability: Add two hooks to handle kvm_create and destroy vm
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
  2007-12-30  7:09 ` [PATCH 01/52] KVM: Remove ptr comparisons to 0 Avi Kivity
  2007-12-30  7:09 ` [PATCH 02/52] KVM: Remove __init attributes for kvm_init_debug and kvm_init_msr_list Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 04/52] KVM: Replace 'light_exits' stat with 'host_state_reload' Avi Kivity
                   ` (48 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao@vtsmp-build32.los-vmm.org>

Add two arch hooks to handle kvm_create_vm and kvm destroy_vm. Now, just
put io_bus init and destory in common.

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    4 ++++
 drivers/kvm/kvm_main.c |   42 ++++++------------------------------------
 drivers/kvm/x86.c      |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 36 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index c4ad66b..59e001c 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -674,6 +674,10 @@ int kvm_arch_hardware_setup(void);
 void kvm_arch_hardware_unsetup(void);
 void kvm_arch_check_processor_compat(void *rtn);
 
+void kvm_free_physmem(struct kvm *kvm);
+
+struct  kvm *kvm_arch_create_vm(void);
+void kvm_arch_destroy_vm(struct kvm *kvm);
 
 static inline void kvm_guest_enter(void)
 {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index acd26cf..3aa34de 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -156,18 +156,18 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_uninit);
 
 static struct kvm *kvm_create_vm(void)
 {
-	struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
+	struct kvm *kvm = kvm_arch_create_vm();
 
-	if (!kvm)
-		return ERR_PTR(-ENOMEM);
+	if (IS_ERR(kvm))
+		goto out;
 
 	kvm_io_bus_init(&kvm->pio_bus);
 	mutex_init(&kvm->lock);
-	INIT_LIST_HEAD(&kvm->active_mmu_pages);
 	kvm_io_bus_init(&kvm->mmio_bus);
 	spin_lock(&kvm_lock);
 	list_add(&kvm->vm_list, &vm_list);
 	spin_unlock(&kvm_lock);
+out:
 	return kvm;
 }
 
@@ -188,7 +188,7 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
 	free->rmap = NULL;
 }
 
-static void kvm_free_physmem(struct kvm *kvm)
+void kvm_free_physmem(struct kvm *kvm)
 {
 	int i;
 
@@ -196,32 +196,6 @@ static void kvm_free_physmem(struct kvm *kvm)
 		kvm_free_physmem_slot(&kvm->memslots[i], NULL);
 }
 
-static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
-{
-	vcpu_load(vcpu);
-	kvm_mmu_unload(vcpu);
-	vcpu_put(vcpu);
-}
-
-static void kvm_free_vcpus(struct kvm *kvm)
-{
-	unsigned int i;
-
-	/*
-	 * Unpin any mmu pages first.
-	 */
-	for (i = 0; i < KVM_MAX_VCPUS; ++i)
-		if (kvm->vcpus[i])
-			kvm_unload_vcpu_mmu(kvm->vcpus[i]);
-	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
-		if (kvm->vcpus[i]) {
-			kvm_arch_vcpu_free(kvm->vcpus[i]);
-			kvm->vcpus[i] = NULL;
-		}
-	}
-
-}
-
 static void kvm_destroy_vm(struct kvm *kvm)
 {
 	spin_lock(&kvm_lock);
@@ -229,11 +203,7 @@ static void kvm_destroy_vm(struct kvm *kvm)
 	spin_unlock(&kvm_lock);
 	kvm_io_bus_destroy(&kvm->pio_bus);
 	kvm_io_bus_destroy(&kvm->mmio_bus);
-	kfree(kvm->vpic);
-	kfree(kvm->vioapic);
-	kvm_free_vcpus(kvm);
-	kvm_free_physmem(kvm);
-	kfree(kvm);
+	kvm_arch_destroy_vm(kvm);
 }
 
 static int kvm_vm_release(struct inode *inode, struct file *filp)
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index abb7bee..b7c72ac 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2543,3 +2543,50 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
 	kvm_mmu_destroy(vcpu);
 	free_page((unsigned long)vcpu->pio_data);
 }
+
+struct  kvm *kvm_arch_create_vm(void)
+{
+	struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
+
+	if (!kvm)
+		return ERR_PTR(-ENOMEM);
+
+	INIT_LIST_HEAD(&kvm->active_mmu_pages);
+
+	return kvm;
+}
+
+static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
+{
+	vcpu_load(vcpu);
+	kvm_mmu_unload(vcpu);
+	vcpu_put(vcpu);
+}
+
+static void kvm_free_vcpus(struct kvm *kvm)
+{
+	unsigned int i;
+
+	/*
+	 * Unpin any mmu pages first.
+	 */
+	for (i = 0; i < KVM_MAX_VCPUS; ++i)
+		if (kvm->vcpus[i])
+			kvm_unload_vcpu_mmu(kvm->vcpus[i]);
+	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
+		if (kvm->vcpus[i]) {
+			kvm_arch_vcpu_free(kvm->vcpus[i]);
+			kvm->vcpus[i] = NULL;
+		}
+	}
+
+}
+
+void kvm_arch_destroy_vm(struct kvm *kvm)
+{
+	kfree(kvm->vpic);
+	kfree(kvm->vioapic);
+	kvm_free_vcpus(kvm);
+	kvm_free_physmem(kvm);
+	kfree(kvm);
+}
-- 
1.5.3.7


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

* [PATCH 04/52] KVM: Replace 'light_exits' stat with 'host_state_reload'
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (2 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 03/52] KVM: Portability: Add two hooks to handle kvm_create and destroy vm Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 05/52] KVM: Add fpu_reload counter Avi Kivity
                   ` (47 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

This is a little more accurate (since it counts actual reloads, not potential
reloads), and reverses the sense of the statistic to measure a bad event like
most of the other stats (e.g. we want to minimize all counters).

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |    2 +-
 drivers/kvm/svm.c |    1 +
 drivers/kvm/vmx.c |    1 +
 drivers/kvm/x86.c |    6 ++----
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 59e001c..04efe88 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -246,7 +246,7 @@ struct kvm_stat {
 	u32 halt_wakeup;
 	u32 request_irq_exits;
 	u32 irq_exits;
-	u32 light_exits;
+	u32 host_state_reload;
 	u32 efer_reload;
 };
 
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 762302a..94c51a0 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -654,6 +654,7 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
 	struct vcpu_svm *svm = to_svm(vcpu);
 	int i;
 
+	++vcpu->stat.host_state_reload;
 	for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++)
 		wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]);
 
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 30220ea..4e60cf9 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -463,6 +463,7 @@ static void vmx_load_host_state(struct vcpu_vmx *vmx)
 	if (!vmx->host_state.loaded)
 		return;
 
+	++vmx->vcpu.stat.host_state_reload;
 	vmx->host_state.loaded = 0;
 	if (vmx->host_state.fs_reload_needed)
 		load_fs(vmx->host_state.fs_sel);
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index b7c72ac..923dfd4 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -60,7 +60,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ "halt_wakeup", STAT_OFFSET(halt_wakeup) },
 	{ "request_irq", STAT_OFFSET(request_irq_exits) },
 	{ "irq_exits", STAT_OFFSET(irq_exits) },
-	{ "light_exits", STAT_OFFSET(light_exits) },
+	{ "host_state_reload", STAT_OFFSET(host_state_reload) },
 	{ "efer_reload", STAT_OFFSET(efer_reload) },
 	{ NULL }
 };
@@ -1988,10 +1988,8 @@ again:
 			++vcpu->stat.request_irq_exits;
 			goto out;
 		}
-		if (!need_resched()) {
-			++vcpu->stat.light_exits;
+		if (!need_resched())
 			goto again;
-		}
 	}
 
 out:
-- 
1.5.3.7


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

* [PATCH 05/52] KVM: Add fpu_reload counter
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (3 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 04/52] KVM: Replace 'light_exits' stat with 'host_state_reload' Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 06/52] KVM: Add instruction emulation statistics Avi Kivity
                   ` (46 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Measure the number of times we switch the fpu state.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |    1 +
 drivers/kvm/x86.c |    2 ++
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 04efe88..a85c590 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -248,6 +248,7 @@ struct kvm_stat {
 	u32 irq_exits;
 	u32 host_state_reload;
 	u32 efer_reload;
+	u32 fpu_reload;
 };
 
 struct kvm_io_device {
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 923dfd4..c1211e1 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -62,6 +62,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ "irq_exits", STAT_OFFSET(irq_exits) },
 	{ "host_state_reload", STAT_OFFSET(host_state_reload) },
 	{ "efer_reload", STAT_OFFSET(efer_reload) },
+	{ "fpu_reload", STAT_OFFSET(fpu_reload) },
 	{ NULL }
 };
 
@@ -2417,6 +2418,7 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
 	vcpu->guest_fpu_loaded = 0;
 	fx_save(&vcpu->guest_fx_image);
 	fx_restore(&vcpu->host_fx_image);
+	++vcpu->stat.fpu_reload;
 }
 EXPORT_SYMBOL_GPL(kvm_put_guest_fpu);
 
-- 
1.5.3.7


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

* [PATCH 06/52] KVM: Add instruction emulation statistics
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (4 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 05/52] KVM: Add fpu_reload counter Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 07/52] KVM: Extend stats support for VM stats Avi Kivity
                   ` (45 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

---
 drivers/kvm/kvm.h |    2 ++
 drivers/kvm/x86.c |    4 ++++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index a85c590..5a8a9af 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -249,6 +249,8 @@ struct kvm_stat {
 	u32 host_state_reload;
 	u32 efer_reload;
 	u32 fpu_reload;
+	u32 insn_emulation;
+	u32 insn_emulation_fail;
 };
 
 struct kvm_io_device {
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index c1211e1..a46b95b 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -63,6 +63,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ "host_state_reload", STAT_OFFSET(host_state_reload) },
 	{ "efer_reload", STAT_OFFSET(efer_reload) },
 	{ "fpu_reload", STAT_OFFSET(fpu_reload) },
+	{ "insn_emulation", STAT_OFFSET(insn_emulation) },
+	{ "insn_emulation_fail", STAT_OFFSET(insn_emulation_fail) },
 	{ NULL }
 };
 
@@ -1381,7 +1383,9 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
 					get_segment_base(vcpu, VCPU_SREG_FS);
 
 		r = x86_decode_insn(&vcpu->emulate_ctxt, &emulate_ops);
+		++vcpu->stat.insn_emulation;
 		if (r)  {
+			++vcpu->stat.insn_emulation_fail;
 			if (kvm_mmu_unprotect_page_virt(vcpu, cr2))
 				return EMULATE_DONE;
 			return EMULATE_FAIL;
-- 
1.5.3.7


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

* [PATCH 07/52] KVM: Extend stats support for VM stats
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (5 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 06/52] KVM: Add instruction emulation statistics Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 08/52] KVM: MMU: Add some mmu statistics Avi Kivity
                   ` (44 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

This is in addition to the current virtual cpu statistics.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |   14 ++++++++++++--
 drivers/kvm/kvm_main.c |   26 +++++++++++++++++++++++---
 drivers/kvm/x86.c      |   39 ++++++++++++++++++++-------------------
 3 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 5a8a9af..d3171f9 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -231,7 +231,7 @@ struct kvm_pio_request {
 	int rep;
 };
 
-struct kvm_stat {
+struct kvm_vcpu_stat {
 	u32 pf_fixed;
 	u32 pf_guest;
 	u32 tlb_flush;
@@ -342,7 +342,7 @@ void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
 	wait_queue_head_t wq;				\
 	int sigset_active;				\
 	sigset_t sigset;				\
-	struct kvm_stat stat;				\
+	struct kvm_vcpu_stat stat;			\
 	KVM_VCPU_MMIO
 
 struct kvm_mem_alias {
@@ -361,6 +361,9 @@ struct kvm_memory_slot {
 	int user_alloc;
 };
 
+struct kvm_vm_stat {
+};
+
 struct kvm {
 	struct mutex lock; /* protects everything except vcpus */
 	int naliases;
@@ -387,6 +390,7 @@ struct kvm {
 	int round_robin_prev_vcpu;
 	unsigned int tss_addr;
 	struct page *apic_access_page;
+	struct kvm_vm_stat stat;
 };
 
 static inline struct kvm_pic *pic_irqchip(struct kvm *kvm)
@@ -809,9 +813,15 @@ static inline u32 get_rdx_init_val(void)
 #define TSS_REDIRECTION_SIZE (256 / 8)
 #define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
 
+enum kvm_stat_kind {
+	KVM_STAT_VM,
+	KVM_STAT_VCPU,
+};
+
 struct kvm_stats_debugfs_item {
 	const char *name;
 	int offset;
+	enum kvm_stat_kind kind;
 	struct dentry *dentry;
 };
 extern struct kvm_stats_debugfs_item debugfs_entries[];
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 3aa34de..1c4e950 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1281,7 +1281,22 @@ static struct notifier_block kvm_cpu_notifier = {
 	.priority = 20, /* must be > scheduler priority */
 };
 
-static u64 stat_get(void *_offset)
+static u64 vm_stat_get(void *_offset)
+{
+	unsigned offset = (long)_offset;
+	u64 total = 0;
+	struct kvm *kvm;
+
+	spin_lock(&kvm_lock);
+	list_for_each_entry(kvm, &vm_list, vm_list)
+		total += *(u32 *)((void *)kvm + offset);
+	spin_unlock(&kvm_lock);
+	return total;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops, vm_stat_get, NULL, "%llu\n");
+
+static u64 vcpu_stat_get(void *_offset)
 {
 	unsigned offset = (long)_offset;
 	u64 total = 0;
@@ -1300,7 +1315,12 @@ static u64 stat_get(void *_offset)
 	return total;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(stat_fops, stat_get, NULL, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");
+
+static struct file_operations *stat_fops[] = {
+	[KVM_STAT_VCPU] = &vcpu_stat_fops,
+	[KVM_STAT_VM]   = &vm_stat_fops,
+};
 
 static void kvm_init_debug(void)
 {
@@ -1310,7 +1330,7 @@ static void kvm_init_debug(void)
 	for (p = debugfs_entries; p->name; ++p)
 		p->dentry = debugfs_create_file(p->name, 0444, debugfs_dir,
 						(void *)(long)p->offset,
-						&stat_fops);
+						stat_fops[p->kind]);
 }
 
 static void kvm_exit_debug(void)
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index a46b95b..016abc3 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -42,29 +42,30 @@
 #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
 #define EFER_RESERVED_BITS 0xfffffffffffff2fe
 
-#define STAT_OFFSET(x) offsetof(struct kvm_vcpu, stat.x)
+#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
+#define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
 
 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) },
-	{ "tlb_flush", STAT_OFFSET(tlb_flush) },
-	{ "invlpg", STAT_OFFSET(invlpg) },
-	{ "exits", STAT_OFFSET(exits) },
-	{ "io_exits", STAT_OFFSET(io_exits) },
-	{ "mmio_exits", STAT_OFFSET(mmio_exits) },
-	{ "signal_exits", STAT_OFFSET(signal_exits) },
-	{ "irq_window", STAT_OFFSET(irq_window_exits) },
-	{ "halt_exits", STAT_OFFSET(halt_exits) },
-	{ "halt_wakeup", STAT_OFFSET(halt_wakeup) },
-	{ "request_irq", STAT_OFFSET(request_irq_exits) },
-	{ "irq_exits", STAT_OFFSET(irq_exits) },
-	{ "host_state_reload", STAT_OFFSET(host_state_reload) },
-	{ "efer_reload", STAT_OFFSET(efer_reload) },
-	{ "fpu_reload", STAT_OFFSET(fpu_reload) },
-	{ "insn_emulation", STAT_OFFSET(insn_emulation) },
-	{ "insn_emulation_fail", STAT_OFFSET(insn_emulation_fail) },
+	{ "pf_fixed", VCPU_STAT(pf_fixed) },
+	{ "pf_guest", VCPU_STAT(pf_guest) },
+	{ "tlb_flush", VCPU_STAT(tlb_flush) },
+	{ "invlpg", VCPU_STAT(invlpg) },
+	{ "exits", VCPU_STAT(exits) },
+	{ "io_exits", VCPU_STAT(io_exits) },
+	{ "mmio_exits", VCPU_STAT(mmio_exits) },
+	{ "signal_exits", VCPU_STAT(signal_exits) },
+	{ "irq_window", VCPU_STAT(irq_window_exits) },
+	{ "halt_exits", VCPU_STAT(halt_exits) },
+	{ "halt_wakeup", VCPU_STAT(halt_wakeup) },
+	{ "request_irq", VCPU_STAT(request_irq_exits) },
+	{ "irq_exits", VCPU_STAT(irq_exits) },
+	{ "host_state_reload", VCPU_STAT(host_state_reload) },
+	{ "efer_reload", VCPU_STAT(efer_reload) },
+	{ "fpu_reload", VCPU_STAT(fpu_reload) },
+	{ "insn_emulation", VCPU_STAT(insn_emulation) },
+	{ "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
 	{ NULL }
 };
 
-- 
1.5.3.7


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

* [PATCH 08/52] KVM: MMU: Add some mmu statistics
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (6 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 07/52] KVM: Extend stats support for VM stats Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 09/52] KVM: Make unloading of FPU state when putting vcpu arch-independent Avi Kivity
                   ` (43 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |    6 ++++++
 drivers/kvm/mmu.c |    9 ++++++++-
 drivers/kvm/x86.c |    6 ++++++
 3 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index d3171f9..bdcc44e 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -362,6 +362,12 @@ struct kvm_memory_slot {
 };
 
 struct kvm_vm_stat {
+	u32 mmu_shadow_zapped;
+	u32 mmu_pte_write;
+	u32 mmu_pte_updated;
+	u32 mmu_pde_zapped;
+	u32 mmu_flooded;
+	u32 mmu_recycled;
 };
 
 struct kvm {
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 9be54a5..87d8e70 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -755,6 +755,7 @@ static void kvm_mmu_zap_page(struct kvm *kvm,
 {
 	u64 *parent_pte;
 
+	++kvm->stat.mmu_shadow_zapped;
 	while (page->multimapped || page->parent_pte) {
 		if (!page->multimapped)
 			parent_pte = page->parent_pte;
@@ -1226,9 +1227,12 @@ static void mmu_pte_write_new_pte(struct kvm_vcpu *vcpu,
 				  const void *new, int bytes,
 				  int offset_in_pte)
 {
-	if (page->role.level != PT_PAGE_TABLE_LEVEL)
+	if (page->role.level != PT_PAGE_TABLE_LEVEL) {
+		++vcpu->kvm->stat.mmu_pde_zapped;
 		return;
+	}
 
+	++vcpu->kvm->stat.mmu_pte_updated;
 	if (page->role.glevels == PT32_ROOT_LEVEL)
 		paging32_update_pte(vcpu, page, spte, new, bytes,
 				    offset_in_pte);
@@ -1263,6 +1267,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 	int npte;
 
 	pgprintk("%s: gpa %llx bytes %d\n", __FUNCTION__, gpa, bytes);
+	++vcpu->kvm->stat.mmu_pte_write;
 	kvm_mmu_audit(vcpu, "pre pte write");
 	if (gfn == vcpu->last_pt_write_gfn
 	    && !last_updated_pte_accessed(vcpu)) {
@@ -1296,6 +1301,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 			pgprintk("misaligned: gpa %llx bytes %d role %x\n",
 				 gpa, bytes, page->role.word);
 			kvm_mmu_zap_page(vcpu->kvm, page);
+			++vcpu->kvm->stat.mmu_flooded;
 			continue;
 		}
 		page_offset = offset;
@@ -1344,6 +1350,7 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
 		page = container_of(vcpu->kvm->active_mmu_pages.prev,
 				    struct kvm_mmu_page, link);
 		kvm_mmu_zap_page(vcpu->kvm, page);
+		++vcpu->kvm->stat.mmu_recycled;
 	}
 }
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 016abc3..fdc7632 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -66,6 +66,12 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ "fpu_reload", VCPU_STAT(fpu_reload) },
 	{ "insn_emulation", VCPU_STAT(insn_emulation) },
 	{ "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
+	{ "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
+	{ "mmu_pte_write", VM_STAT(mmu_pte_write) },
+	{ "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
+	{ "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
+	{ "mmu_flooded", VM_STAT(mmu_flooded) },
+	{ "mmu_recycled", VM_STAT(mmu_recycled) },
 	{ NULL }
 };
 
-- 
1.5.3.7


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

* [PATCH 09/52] KVM: Make unloading of FPU state when putting vcpu arch-independent
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (7 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 08/52] KVM: MMU: Add some mmu statistics Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 10/52] KVM: Portability: Move kvm_vcpu_ioctl_get_dirty_log to arch-specific file Avi Kivity
                   ` (42 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Amit Shah

From: Amit Shah <amit.shah@qumranet.com>

Instead of having each architecture do it individually, we
do this in the arch-independent code (just x86 as of now).

[avi: add svm to the mix, which was added to mainline during the
 2.6.24-rc process]

Signed-off-by: Amit Shah <amit.shah@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/svm.c |    1 -
 drivers/kvm/vmx.c |    1 -
 drivers/kvm/x86.c |    1 +
 3 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 94c51a0..928fb35 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -659,7 +659,6 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
 		wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]);
 
 	rdtscll(vcpu->host_tsc);
-	kvm_put_guest_fpu(vcpu);
 }
 
 static void svm_vcpu_decache(struct kvm_vcpu *vcpu)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 4e60cf9..c23f399 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -541,7 +541,6 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
 {
 	vmx_load_host_state(to_vmx(vcpu));
-	kvm_put_guest_fpu(vcpu);
 }
 
 static void vmx_fpu_activate(struct kvm_vcpu *vcpu)
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index fdc7632..9618fcb 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -678,6 +678,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 {
 	kvm_x86_ops->vcpu_put(vcpu);
+	kvm_put_guest_fpu(vcpu);
 }
 
 static void cpuid_fix_nx_cap(struct kvm_vcpu *vcpu)
-- 
1.5.3.7


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

* [PATCH 10/52] KVM: Portability: Move kvm_vcpu_ioctl_get_dirty_log to arch-specific  file
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (8 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 09/52] KVM: Make unloading of FPU state when putting vcpu arch-independent Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 11/52] KVM: Portability: MMU initialization and teardown split Avi Kivity
                   ` (41 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Meanwhile keep the interface in common, and leave as more logic in common
as possible.

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    5 +++++
 drivers/kvm/kvm_main.c |   19 ++++---------------
 drivers/kvm/x86.c      |   31 +++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index bdcc44e..c1aa84f 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -644,6 +644,11 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
 
 int kvm_dev_ioctl_check_extension(long ext);
 
+int kvm_get_dirty_log(struct kvm *kvm,
+			struct kvm_dirty_log *log, int *is_dirty);
+int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
+				struct kvm_dirty_log *log);
+
 int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
 				   struct
 				   kvm_userspace_memory_region *mem,
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 1c4e950..e64dfa2 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -389,19 +389,14 @@ int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
 	return kvm_set_memory_region(kvm, mem, user_alloc);
 }
 
-/*
- * Get (and clear) the dirty memory log for a memory slot.
- */
-static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
-				      struct kvm_dirty_log *log)
+int kvm_get_dirty_log(struct kvm *kvm,
+			struct kvm_dirty_log *log, int *is_dirty)
 {
 	struct kvm_memory_slot *memslot;
 	int r, i;
 	int n;
 	unsigned long any = 0;
 
-	mutex_lock(&kvm->lock);
-
 	r = -EINVAL;
 	if (log->slot >= KVM_MEMORY_SLOTS)
 		goto out;
@@ -420,17 +415,11 @@ static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
 	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
 		goto out;
 
-	/* If nothing is dirty, don't bother messing with page tables. */
-	if (any) {
-		kvm_mmu_slot_remove_write_access(kvm, log->slot);
-		kvm_flush_remote_tlbs(kvm);
-		memset(memslot->dirty_bitmap, 0, n);
-	}
+	if (any)
+		*is_dirty = 1;
 
 	r = 0;
-
 out:
-	mutex_unlock(&kvm->lock);
 	return r;
 }
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 9618fcb..935e276 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -937,6 +937,37 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
 	return r;
 }
 
+/*
+ * Get (and clear) the dirty memory log for a memory slot.
+ */
+int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
+				      struct kvm_dirty_log *log)
+{
+	int r;
+	int n;
+	struct kvm_memory_slot *memslot;
+	int is_dirty = 0;
+
+	mutex_lock(&kvm->lock);
+
+	r = kvm_get_dirty_log(kvm, log, &is_dirty);
+	if (r)
+		goto out;
+
+	/* If nothing is dirty, don't bother messing with page tables. */
+	if (is_dirty) {
+		kvm_mmu_slot_remove_write_access(kvm, log->slot);
+		kvm_flush_remote_tlbs(kvm);
+		memslot = &kvm->memslots[log->slot];
+		n = ALIGN(memslot->npages, BITS_PER_LONG) / 8;
+		memset(memslot->dirty_bitmap, 0, n);
+	}
+	r = 0;
+out:
+	mutex_unlock(&kvm->lock);
+	return r;
+}
+
 long kvm_arch_vm_ioctl(struct file *filp,
 		       unsigned int ioctl, unsigned long arg)
 {
-- 
1.5.3.7


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

* [PATCH 11/52] KVM: Portability: MMU initialization and teardown split
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (9 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 10/52] KVM: Portability: Move kvm_vcpu_ioctl_get_dirty_log to arch-specific file Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 12/52] KVM: Portability: Move some macro definitions from kvm.h to x86.h Avi Kivity
                   ` (40 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Move out kvm_mmu init and exit functionality from kvm_main.c

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm_main.c |    8 --------
 drivers/kvm/x86.c      |   24 +++++++++++++++++++-----
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index e64dfa2..f9fd865 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1383,10 +1383,6 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
 	int r;
 	int cpu;
 
-	r = kvm_mmu_module_init();
-	if (r)
-		goto out4;
-
 	kvm_init_debug();
 
 	r = kvm_arch_init(opaque);
@@ -1446,8 +1442,6 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
 	kvm_preempt_ops.sched_in = kvm_sched_in;
 	kvm_preempt_ops.sched_out = kvm_sched_out;
 
-	kvm_mmu_set_nonpresent_ptes(0ull, 0ull);
-
 	return 0;
 
 out_free:
@@ -1466,7 +1460,6 @@ out_free_0:
 out:
 	kvm_arch_exit();
 	kvm_exit_debug();
-	kvm_mmu_module_exit();
 out4:
 	return r;
 }
@@ -1485,6 +1478,5 @@ void kvm_exit(void)
 	kvm_arch_exit();
 	kvm_exit_debug();
 	__free_page(bad_page);
-	kvm_mmu_module_exit();
 }
 EXPORT_SYMBOL_GPL(kvm_exit);
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 935e276..2257a0a 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -1711,33 +1711,47 @@ EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
 
 int kvm_arch_init(void *opaque)
 {
+	int r;
 	struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
 
+	r = kvm_mmu_module_init();
+	if (r)
+		goto out_fail;
+
 	kvm_init_msr_list();
 
 	if (kvm_x86_ops) {
 		printk(KERN_ERR "kvm: already loaded the other module\n");
-		return -EEXIST;
+		r = -EEXIST;
+		goto out;
 	}
 
 	if (!ops->cpu_has_kvm_support()) {
 		printk(KERN_ERR "kvm: no hardware support\n");
-		return -EOPNOTSUPP;
+		r = -EOPNOTSUPP;
+		goto out;
 	}
 	if (ops->disabled_by_bios()) {
 		printk(KERN_ERR "kvm: disabled by bios\n");
-		return -EOPNOTSUPP;
+		r = -EOPNOTSUPP;
+		goto out;
 	}
 
 	kvm_x86_ops = ops;
-
+	kvm_mmu_set_nonpresent_ptes(0ull, 0ull);
 	return 0;
+
+out:
+	kvm_mmu_module_exit();
+out_fail:
+	return r;
 }
 
 void kvm_arch_exit(void)
 {
 	kvm_x86_ops = NULL;
- }
+	kvm_mmu_module_exit();
+}
 
 int kvm_emulate_halt(struct kvm_vcpu *vcpu)
 {
-- 
1.5.3.7


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

* [PATCH 12/52] KVM: Portability: Move some macro definitions from kvm.h to x86.h
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (10 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 11/52] KVM: Portability: MMU initialization and teardown split Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:09 ` [PATCH 13/52] KVM: Portability: Move struct kvm_x86_ops definition " Avi Kivity
                   ` (39 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |   33 ---------------------------------
 drivers/kvm/x86.h |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index c1aa84f..aceecf4 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -20,24 +20,6 @@
 #include <linux/kvm.h>
 #include <linux/kvm_para.h>
 
-#define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1)
-#define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD))
-#define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS|0xFFFFFF0000000000ULL)
-
-#define KVM_GUEST_CR0_MASK \
-	(X86_CR0_PG | X86_CR0_PE | X86_CR0_WP | X86_CR0_NE \
-	 | X86_CR0_NW | X86_CR0_CD)
-#define KVM_VM_CR0_ALWAYS_ON \
-	(X86_CR0_PG | X86_CR0_PE | X86_CR0_WP | X86_CR0_NE | X86_CR0_TS \
-	 | X86_CR0_MP)
-#define KVM_GUEST_CR4_MASK \
-	(X86_CR4_VME | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE | X86_CR4_VMXE)
-#define KVM_PMODE_VM_CR4_ALWAYS_ON (X86_CR4_PAE | X86_CR4_VMXE)
-#define KVM_RMODE_VM_CR4_ALWAYS_ON (X86_CR4_VME | X86_CR4_PAE | X86_CR4_VMXE)
-
-#define INVALID_PAGE (~(hpa_t)0)
-#define UNMAPPED_GVA (~(gpa_t)0)
-
 #define KVM_MAX_VCPUS 4
 #define KVM_ALIAS_SLOTS 4
 #define KVM_MEMORY_SLOTS 8
@@ -50,21 +32,6 @@
 #define KVM_REFILL_PAGES 25
 #define KVM_MAX_CPUID_ENTRIES 40
 
-#define DE_VECTOR 0
-#define UD_VECTOR 6
-#define NM_VECTOR 7
-#define DF_VECTOR 8
-#define TS_VECTOR 10
-#define NP_VECTOR 11
-#define SS_VECTOR 12
-#define GP_VECTOR 13
-#define PF_VECTOR 14
-
-#define SELECTOR_TI_MASK (1 << 2)
-#define SELECTOR_RPL_MASK 0x03
-
-#define IOPL_SHIFT 12
-
 #define KVM_PIO_PAGE_OFFSET 1
 
 /*
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 4df0641..ec1d669 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -19,6 +19,39 @@
 #include <linux/kvm.h>
 #include <linux/kvm_para.h>
 
+#define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1)
+#define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD))
+#define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS|0xFFFFFF0000000000ULL)
+
+#define KVM_GUEST_CR0_MASK \
+	(X86_CR0_PG | X86_CR0_PE | X86_CR0_WP | X86_CR0_NE \
+	 | X86_CR0_NW | X86_CR0_CD)
+#define KVM_VM_CR0_ALWAYS_ON \
+	(X86_CR0_PG | X86_CR0_PE | X86_CR0_WP | X86_CR0_NE | X86_CR0_TS \
+	 | X86_CR0_MP)
+#define KVM_GUEST_CR4_MASK \
+	(X86_CR4_VME | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE | X86_CR4_VMXE)
+#define KVM_PMODE_VM_CR4_ALWAYS_ON (X86_CR4_PAE | X86_CR4_VMXE)
+#define KVM_RMODE_VM_CR4_ALWAYS_ON (X86_CR4_VME | X86_CR4_PAE | X86_CR4_VMXE)
+
+#define INVALID_PAGE (~(hpa_t)0)
+#define UNMAPPED_GVA (~(gpa_t)0)
+
+#define DE_VECTOR 0
+#define UD_VECTOR 6
+#define NM_VECTOR 7
+#define DF_VECTOR 8
+#define TS_VECTOR 10
+#define NP_VECTOR 11
+#define SS_VECTOR 12
+#define GP_VECTOR 13
+#define PF_VECTOR 14
+
+#define SELECTOR_TI_MASK (1 << 2)
+#define SELECTOR_RPL_MASK 0x03
+
+#define IOPL_SHIFT 12
+
 extern spinlock_t kvm_lock;
 extern struct list_head vm_list;
 
-- 
1.5.3.7


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

* [PATCH 13/52] KVM: Portability: Move struct kvm_x86_ops definition to x86.h
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (11 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 12/52] KVM: Portability: Move some macro definitions from kvm.h to x86.h Avi Kivity
@ 2007-12-30  7:09 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 14/52] KVM: Portability: Move vcpu regs enumeration " Avi Kivity
                   ` (38 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:09 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |   69 -----------------------------------------------------
 drivers/kvm/x86.h |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 69 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index aceecf4..e4e1ff7 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -386,75 +386,6 @@ struct descriptor_table {
 	unsigned long base;
 } __attribute__((packed));
 
-struct kvm_x86_ops {
-	int (*cpu_has_kvm_support)(void);          /* __init */
-	int (*disabled_by_bios)(void);             /* __init */
-	void (*hardware_enable)(void *dummy);      /* __init */
-	void (*hardware_disable)(void *dummy);
-	void (*check_processor_compatibility)(void *rtn);
-	int (*hardware_setup)(void);               /* __init */
-	void (*hardware_unsetup)(void);            /* __exit */
-
-	/* Create, but do not attach this VCPU */
-	struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);
-	void (*vcpu_free)(struct kvm_vcpu *vcpu);
-	int (*vcpu_reset)(struct kvm_vcpu *vcpu);
-
-	void (*prepare_guest_switch)(struct kvm_vcpu *vcpu);
-	void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
-	void (*vcpu_put)(struct kvm_vcpu *vcpu);
-	void (*vcpu_decache)(struct kvm_vcpu *vcpu);
-
-	int (*set_guest_debug)(struct kvm_vcpu *vcpu,
-			       struct kvm_debug_guest *dbg);
-	void (*guest_debug_pre)(struct kvm_vcpu *vcpu);
-	int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
-	int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
-	u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
-	void (*get_segment)(struct kvm_vcpu *vcpu,
-			    struct kvm_segment *var, int seg);
-	void (*set_segment)(struct kvm_vcpu *vcpu,
-			    struct kvm_segment *var, int seg);
-	void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
-	void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu);
-	void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
-	void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
-	void (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4);
-	void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer);
-	void (*get_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
-	void (*set_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
-	void (*get_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
-	void (*set_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
-	unsigned long (*get_dr)(struct kvm_vcpu *vcpu, int dr);
-	void (*set_dr)(struct kvm_vcpu *vcpu, int dr, unsigned long value,
-		       int *exception);
-	void (*cache_regs)(struct kvm_vcpu *vcpu);
-	void (*decache_regs)(struct kvm_vcpu *vcpu);
-	unsigned long (*get_rflags)(struct kvm_vcpu *vcpu);
-	void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
-
-	void (*tlb_flush)(struct kvm_vcpu *vcpu);
-	void (*inject_page_fault)(struct kvm_vcpu *vcpu,
-				  unsigned long addr, u32 err_code);
-
-	void (*inject_gp)(struct kvm_vcpu *vcpu, unsigned err_code);
-
-	void (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run);
-	int (*handle_exit)(struct kvm_run *run, struct kvm_vcpu *vcpu);
-	void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
-	void (*patch_hypercall)(struct kvm_vcpu *vcpu,
-				unsigned char *hypercall_addr);
-	int (*get_irq)(struct kvm_vcpu *vcpu);
-	void (*set_irq)(struct kvm_vcpu *vcpu, int vec);
-	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
-	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
-				       struct kvm_run *run);
-
-	int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
-};
-
-extern struct kvm_x86_ops *kvm_x86_ops;
-
 /* The guest did something we don't support. */
 #define pr_unimpl(vcpu, fmt, ...)					\
  do {									\
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index ec1d669..77b4092 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -121,6 +121,73 @@ struct kvm_vcpu {
 	struct x86_emulate_ctxt emulate_ctxt;
 };
 
+struct kvm_x86_ops {
+	int (*cpu_has_kvm_support)(void);          /* __init */
+	int (*disabled_by_bios)(void);             /* __init */
+	void (*hardware_enable)(void *dummy);      /* __init */
+	void (*hardware_disable)(void *dummy);
+	void (*check_processor_compatibility)(void *rtn);
+	int (*hardware_setup)(void);               /* __init */
+	void (*hardware_unsetup)(void);            /* __exit */
+
+	/* Create, but do not attach this VCPU */
+	struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);
+	void (*vcpu_free)(struct kvm_vcpu *vcpu);
+	int (*vcpu_reset)(struct kvm_vcpu *vcpu);
+
+	void (*prepare_guest_switch)(struct kvm_vcpu *vcpu);
+	void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
+	void (*vcpu_put)(struct kvm_vcpu *vcpu);
+	void (*vcpu_decache)(struct kvm_vcpu *vcpu);
+
+	int (*set_guest_debug)(struct kvm_vcpu *vcpu,
+			       struct kvm_debug_guest *dbg);
+	void (*guest_debug_pre)(struct kvm_vcpu *vcpu);
+	int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
+	int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
+	u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
+	void (*get_segment)(struct kvm_vcpu *vcpu,
+			    struct kvm_segment *var, int seg);
+	void (*set_segment)(struct kvm_vcpu *vcpu,
+			    struct kvm_segment *var, int seg);
+	void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
+	void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu);
+	void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
+	void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
+	void (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4);
+	void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer);
+	void (*get_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
+	void (*set_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
+	void (*get_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
+	void (*set_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
+	unsigned long (*get_dr)(struct kvm_vcpu *vcpu, int dr);
+	void (*set_dr)(struct kvm_vcpu *vcpu, int dr, unsigned long value,
+		       int *exception);
+	void (*cache_regs)(struct kvm_vcpu *vcpu);
+	void (*decache_regs)(struct kvm_vcpu *vcpu);
+	unsigned long (*get_rflags)(struct kvm_vcpu *vcpu);
+	void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
+
+	void (*tlb_flush)(struct kvm_vcpu *vcpu);
+	void (*inject_page_fault)(struct kvm_vcpu *vcpu,
+				  unsigned long addr, u32 err_code);
+
+	void (*inject_gp)(struct kvm_vcpu *vcpu, unsigned err_code);
+
+	void (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run);
+	int (*handle_exit)(struct kvm_run *run, struct kvm_vcpu *vcpu);
+	void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
+	void (*patch_hypercall)(struct kvm_vcpu *vcpu,
+				unsigned char *hypercall_addr);
+	int (*get_irq)(struct kvm_vcpu *vcpu);
+	void (*set_irq)(struct kvm_vcpu *vcpu, int vec);
+	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
+	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
+				       struct kvm_run *run);
+
+	int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
+};
+
 extern struct kvm_x86_ops *kvm_x86_ops;
 
 int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code);
-- 
1.5.3.7


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

* [PATCH 14/52] KVM: Portability: Move vcpu regs enumeration definition to x86.h
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (12 preceding siblings ...)
  2007-12-30  7:09 ` [PATCH 13/52] KVM: Portability: Move struct kvm_x86_ops definition " Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 15/52] KVM: Move some static inline functions out from kvm.h into x86.h Avi Kivity
                   ` (37 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |   35 -----------------------------------
 drivers/kvm/x86.h |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index e4e1ff7..1c4de50 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -150,41 +150,6 @@ struct kvm_guest_debug {
 	int singlestep;
 };
 
-enum {
-	VCPU_REGS_RAX = 0,
-	VCPU_REGS_RCX = 1,
-	VCPU_REGS_RDX = 2,
-	VCPU_REGS_RBX = 3,
-	VCPU_REGS_RSP = 4,
-	VCPU_REGS_RBP = 5,
-	VCPU_REGS_RSI = 6,
-	VCPU_REGS_RDI = 7,
-#ifdef CONFIG_X86_64
-	VCPU_REGS_R8 = 8,
-	VCPU_REGS_R9 = 9,
-	VCPU_REGS_R10 = 10,
-	VCPU_REGS_R11 = 11,
-	VCPU_REGS_R12 = 12,
-	VCPU_REGS_R13 = 13,
-	VCPU_REGS_R14 = 14,
-	VCPU_REGS_R15 = 15,
-#endif
-	NR_VCPU_REGS
-};
-
-enum {
-	VCPU_SREG_CS,
-	VCPU_SREG_DS,
-	VCPU_SREG_ES,
-	VCPU_SREG_FS,
-	VCPU_SREG_GS,
-	VCPU_SREG_SS,
-	VCPU_SREG_TR,
-	VCPU_SREG_LDTR,
-};
-
-#include "x86_emulate.h"
-
 struct kvm_pio_request {
 	unsigned long count;
 	int cur_count;
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 77b4092..77a4a4a 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -55,6 +55,41 @@
 extern spinlock_t kvm_lock;
 extern struct list_head vm_list;
 
+enum {
+	VCPU_REGS_RAX = 0,
+	VCPU_REGS_RCX = 1,
+	VCPU_REGS_RDX = 2,
+	VCPU_REGS_RBX = 3,
+	VCPU_REGS_RSP = 4,
+	VCPU_REGS_RBP = 5,
+	VCPU_REGS_RSI = 6,
+	VCPU_REGS_RDI = 7,
+#ifdef CONFIG_X86_64
+	VCPU_REGS_R8 = 8,
+	VCPU_REGS_R9 = 9,
+	VCPU_REGS_R10 = 10,
+	VCPU_REGS_R11 = 11,
+	VCPU_REGS_R12 = 12,
+	VCPU_REGS_R13 = 13,
+	VCPU_REGS_R14 = 14,
+	VCPU_REGS_R15 = 15,
+#endif
+	NR_VCPU_REGS
+};
+
+enum {
+	VCPU_SREG_CS,
+	VCPU_SREG_DS,
+	VCPU_SREG_ES,
+	VCPU_SREG_FS,
+	VCPU_SREG_GS,
+	VCPU_SREG_SS,
+	VCPU_SREG_TR,
+	VCPU_SREG_LDTR,
+};
+
+#include "x86_emulate.h"
+
 struct kvm_vcpu {
 	KVM_VCPU_COMM;
 	u64 host_tsc;
-- 
1.5.3.7


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

* [PATCH 15/52] KVM: Move some static inline functions out from kvm.h into x86.h
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (13 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 14/52] KVM: Portability: Move vcpu regs enumeration " Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 16/52] KVM: Portability: Move some function declarations to x86.h Avi Kivity
                   ` (36 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |  109 ----------------------------------------------------
 drivers/kvm/x86.h |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 109 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 1c4de50..41f6ee2 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -577,115 +577,6 @@ static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
 	return slot - kvm->memslots;
 }
 
-static inline struct kvm_mmu_page *page_header(hpa_t shadow_page)
-{
-	struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT);
-
-	return (struct kvm_mmu_page *)page_private(page);
-}
-
-static inline u16 read_fs(void)
-{
-	u16 seg;
-	asm("mov %%fs, %0" : "=g"(seg));
-	return seg;
-}
-
-static inline u16 read_gs(void)
-{
-	u16 seg;
-	asm("mov %%gs, %0" : "=g"(seg));
-	return seg;
-}
-
-static inline u16 read_ldt(void)
-{
-	u16 ldt;
-	asm("sldt %0" : "=g"(ldt));
-	return ldt;
-}
-
-static inline void load_fs(u16 sel)
-{
-	asm("mov %0, %%fs" : : "rm"(sel));
-}
-
-static inline void load_gs(u16 sel)
-{
-	asm("mov %0, %%gs" : : "rm"(sel));
-}
-
-#ifndef load_ldt
-static inline void load_ldt(u16 sel)
-{
-	asm("lldt %0" : : "rm"(sel));
-}
-#endif
-
-static inline void get_idt(struct descriptor_table *table)
-{
-	asm("sidt %0" : "=m"(*table));
-}
-
-static inline void get_gdt(struct descriptor_table *table)
-{
-	asm("sgdt %0" : "=m"(*table));
-}
-
-static inline unsigned long read_tr_base(void)
-{
-	u16 tr;
-	asm("str %0" : "=g"(tr));
-	return segment_base(tr);
-}
-
-#ifdef CONFIG_X86_64
-static inline unsigned long read_msr(unsigned long msr)
-{
-	u64 value;
-
-	rdmsrl(msr, value);
-	return value;
-}
-#endif
-
-static inline void fx_save(struct i387_fxsave_struct *image)
-{
-	asm("fxsave (%0)":: "r" (image));
-}
-
-static inline void fx_restore(struct i387_fxsave_struct *image)
-{
-	asm("fxrstor (%0)":: "r" (image));
-}
-
-static inline void fpu_init(void)
-{
-	asm("finit");
-}
-
-static inline u32 get_rdx_init_val(void)
-{
-	return 0x600; /* P6 family */
-}
-
-#define ASM_VMX_VMCLEAR_RAX       ".byte 0x66, 0x0f, 0xc7, 0x30"
-#define ASM_VMX_VMLAUNCH          ".byte 0x0f, 0x01, 0xc2"
-#define ASM_VMX_VMRESUME          ".byte 0x0f, 0x01, 0xc3"
-#define ASM_VMX_VMPTRLD_RAX       ".byte 0x0f, 0xc7, 0x30"
-#define ASM_VMX_VMREAD_RDX_RAX    ".byte 0x0f, 0x78, 0xd0"
-#define ASM_VMX_VMWRITE_RAX_RDX   ".byte 0x0f, 0x79, 0xd0"
-#define ASM_VMX_VMWRITE_RSP_RDX   ".byte 0x0f, 0x79, 0xd4"
-#define ASM_VMX_VMXOFF            ".byte 0x0f, 0x01, 0xc4"
-#define ASM_VMX_VMXON_RAX         ".byte 0xf3, 0x0f, 0xc7, 0x30"
-
-#define MSR_IA32_TIME_STAMP_COUNTER		0x010
-
-#define TSS_IOPB_BASE_OFFSET 0x66
-#define TSS_BASE_SIZE 0x68
-#define TSS_IOPB_SIZE (65536 / 8)
-#define TSS_REDIRECTION_SIZE (256 / 8)
-#define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
 
 enum kvm_stat_kind {
 	KVM_STAT_VM,
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 77a4a4a..f1c43ca 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -267,4 +267,114 @@ static inline int is_paging(struct kvm_vcpu *vcpu)
 
 int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
 int complete_pio(struct kvm_vcpu *vcpu);
+
+static inline struct kvm_mmu_page *page_header(hpa_t shadow_page)
+{
+	struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT);
+
+	return (struct kvm_mmu_page *)page_private(page);
+}
+
+static inline u16 read_fs(void)
+{
+	u16 seg;
+	asm("mov %%fs, %0" : "=g"(seg));
+	return seg;
+}
+
+static inline u16 read_gs(void)
+{
+	u16 seg;
+	asm("mov %%gs, %0" : "=g"(seg));
+	return seg;
+}
+
+static inline u16 read_ldt(void)
+{
+	u16 ldt;
+	asm("sldt %0" : "=g"(ldt));
+	return ldt;
+}
+
+static inline void load_fs(u16 sel)
+{
+	asm("mov %0, %%fs" : : "rm"(sel));
+}
+
+static inline void load_gs(u16 sel)
+{
+	asm("mov %0, %%gs" : : "rm"(sel));
+}
+
+#ifndef load_ldt
+static inline void load_ldt(u16 sel)
+{
+	asm("lldt %0" : : "rm"(sel));
+}
+#endif
+
+static inline void get_idt(struct descriptor_table *table)
+{
+	asm("sidt %0" : "=m"(*table));
+}
+
+static inline void get_gdt(struct descriptor_table *table)
+{
+	asm("sgdt %0" : "=m"(*table));
+}
+
+static inline unsigned long read_tr_base(void)
+{
+	u16 tr;
+	asm("str %0" : "=g"(tr));
+	return segment_base(tr);
+}
+
+#ifdef CONFIG_X86_64
+static inline unsigned long read_msr(unsigned long msr)
+{
+	u64 value;
+
+	rdmsrl(msr, value);
+	return value;
+}
+#endif
+
+static inline void fx_save(struct i387_fxsave_struct *image)
+{
+	asm("fxsave (%0)":: "r" (image));
+}
+
+static inline void fx_restore(struct i387_fxsave_struct *image)
+{
+	asm("fxrstor (%0)":: "r" (image));
+}
+
+static inline void fpu_init(void)
+{
+	asm("finit");
+}
+
+static inline u32 get_rdx_init_val(void)
+{
+	return 0x600; /* P6 family */
+}
+
+#define ASM_VMX_VMCLEAR_RAX       ".byte 0x66, 0x0f, 0xc7, 0x30"
+#define ASM_VMX_VMLAUNCH          ".byte 0x0f, 0x01, 0xc2"
+#define ASM_VMX_VMRESUME          ".byte 0x0f, 0x01, 0xc3"
+#define ASM_VMX_VMPTRLD_RAX       ".byte 0x0f, 0xc7, 0x30"
+#define ASM_VMX_VMREAD_RDX_RAX    ".byte 0x0f, 0x78, 0xd0"
+#define ASM_VMX_VMWRITE_RAX_RDX   ".byte 0x0f, 0x79, 0xd0"
+#define ASM_VMX_VMWRITE_RSP_RDX   ".byte 0x0f, 0x79, 0xd4"
+#define ASM_VMX_VMXOFF            ".byte 0x0f, 0x01, 0xc4"
+#define ASM_VMX_VMXON_RAX         ".byte 0xf3, 0x0f, 0xc7, 0x30"
+
+#define MSR_IA32_TIME_STAMP_COUNTER		0x010
+
+#define TSS_IOPB_BASE_OFFSET 0x66
+#define TSS_BASE_SIZE 0x68
+#define TSS_IOPB_SIZE (65536 / 8)
+#define TSS_REDIRECTION_SIZE (256 / 8)
+#define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
 #endif
-- 
1.5.3.7


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

* [PATCH 16/52] KVM: Portability: Move some function declarations to x86.h
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (14 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 15/52] KVM: Move some static inline functions out from kvm.h into x86.h Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 17/52] KVM: VMX: Force seg.base == (seg.sel << 4) in real mode Avi Kivity
                   ` (35 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |   84 -----------------------------------------------------
 drivers/kvm/x86.h |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 84 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 41f6ee2..1901456 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -375,19 +375,6 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
 		  struct module *module);
 void kvm_exit(void);
 
-int kvm_mmu_module_init(void);
-void kvm_mmu_module_exit(void);
-
-void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
-int kvm_mmu_create(struct kvm_vcpu *vcpu);
-int kvm_mmu_setup(struct kvm_vcpu *vcpu);
-void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte);
-
-int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
-void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
-void kvm_mmu_zap_all(struct kvm *kvm);
-void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
-
 hpa_t gpa_to_hpa(struct kvm *kvm, gpa_t gpa);
 #define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
 #define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
@@ -421,83 +408,12 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
 void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
 
-enum emulation_result {
-	EMULATE_DONE,       /* no further processing */
-	EMULATE_DO_MMIO,      /* kvm_run filled with mmio request */
-	EMULATE_FAIL,         /* can't emulate this instruction */
-};
-
-int emulate_instruction(struct kvm_vcpu *vcpu, struct kvm_run *run,
-			unsigned long cr2, u16 error_code, int no_decode);
-void kvm_report_emulation_failure(struct kvm_vcpu *cvpu, const char *context);
-void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
-void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
-void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
-		   unsigned long *rflags);
-
-unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr);
-void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value,
-		     unsigned long *rflags);
-int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data);
-int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
-
-struct x86_emulate_ctxt;
-
-int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
-		     int size, unsigned port);
-int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
-			   int size, unsigned long count, int down,
-			    gva_t address, int rep, unsigned port);
-void kvm_emulate_cpuid(struct kvm_vcpu *vcpu);
-int kvm_emulate_halt(struct kvm_vcpu *vcpu);
-int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address);
-int emulate_clts(struct kvm_vcpu *vcpu);
-int emulator_get_dr(struct x86_emulate_ctxt *ctxt, int dr,
-		    unsigned long *dest);
-int emulator_set_dr(struct x86_emulate_ctxt *ctxt, int dr,
-		    unsigned long value);
-
-void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
-void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr0);
-void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0);
-void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0);
-unsigned long get_cr8(struct kvm_vcpu *vcpu);
-void lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
-void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);
-
-int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
-int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
-
-void fx_init(struct kvm_vcpu *vcpu);
-
 void kvm_vcpu_block(struct kvm_vcpu *vcpu);
 void kvm_resched(struct kvm_vcpu *vcpu);
 void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
 void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
 void kvm_flush_remote_tlbs(struct kvm *kvm);
 
-int emulator_read_std(unsigned long addr,
-		      void *val,
-		      unsigned int bytes,
-		      struct kvm_vcpu *vcpu);
-int emulator_write_emulated(unsigned long addr,
-			    const void *val,
-			    unsigned int bytes,
-			    struct kvm_vcpu *vcpu);
-
-unsigned long segment_base(u16 selector);
-
-void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
-		       const u8 *new, int bytes);
-int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
-void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
-int kvm_mmu_load(struct kvm_vcpu *vcpu);
-void kvm_mmu_unload(struct kvm_vcpu *vcpu);
-
-int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
-
-int kvm_fix_hypercall(struct kvm_vcpu *vcpu);
-
 long kvm_arch_dev_ioctl(struct file *filp,
 			unsigned int ioctl, unsigned long arg);
 long kvm_arch_vcpu_ioctl(struct file *filp,
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index f1c43ca..90b791b 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -225,6 +225,90 @@ struct kvm_x86_ops {
 
 extern struct kvm_x86_ops *kvm_x86_ops;
 
+int kvm_mmu_module_init(void);
+void kvm_mmu_module_exit(void);
+
+void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
+int kvm_mmu_create(struct kvm_vcpu *vcpu);
+int kvm_mmu_setup(struct kvm_vcpu *vcpu);
+void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte);
+
+int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
+void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
+void kvm_mmu_zap_all(struct kvm *kvm);
+void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
+
+enum emulation_result {
+	EMULATE_DONE,       /* no further processing */
+	EMULATE_DO_MMIO,      /* kvm_run filled with mmio request */
+	EMULATE_FAIL,         /* can't emulate this instruction */
+};
+
+int emulate_instruction(struct kvm_vcpu *vcpu, struct kvm_run *run,
+			unsigned long cr2, u16 error_code, int no_decode);
+void kvm_report_emulation_failure(struct kvm_vcpu *cvpu, const char *context);
+void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
+void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
+void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
+		   unsigned long *rflags);
+
+unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr);
+void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value,
+		     unsigned long *rflags);
+int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data);
+int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
+
+struct x86_emulate_ctxt;
+
+int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
+		     int size, unsigned port);
+int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
+			   int size, unsigned long count, int down,
+			    gva_t address, int rep, unsigned port);
+void kvm_emulate_cpuid(struct kvm_vcpu *vcpu);
+int kvm_emulate_halt(struct kvm_vcpu *vcpu);
+int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address);
+int emulate_clts(struct kvm_vcpu *vcpu);
+int emulator_get_dr(struct x86_emulate_ctxt *ctxt, int dr,
+		    unsigned long *dest);
+int emulator_set_dr(struct x86_emulate_ctxt *ctxt, int dr,
+		    unsigned long value);
+
+void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
+void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr0);
+void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0);
+void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0);
+unsigned long get_cr8(struct kvm_vcpu *vcpu);
+void lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
+void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);
+
+int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
+int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
+
+void fx_init(struct kvm_vcpu *vcpu);
+
+int emulator_read_std(unsigned long addr,
+		      void *val,
+		      unsigned int bytes,
+		      struct kvm_vcpu *vcpu);
+int emulator_write_emulated(unsigned long addr,
+			    const void *val,
+			    unsigned int bytes,
+			    struct kvm_vcpu *vcpu);
+
+unsigned long segment_base(u16 selector);
+
+void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
+		       const u8 *new, int bytes);
+int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
+void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
+int kvm_mmu_load(struct kvm_vcpu *vcpu);
+void kvm_mmu_unload(struct kvm_vcpu *vcpu);
+
+int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
+
+int kvm_fix_hypercall(struct kvm_vcpu *vcpu);
+
 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.3.7


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

* [PATCH 17/52] KVM: VMX: Force seg.base == (seg.sel << 4) in real  mode
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (15 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 16/52] KVM: Portability: Move some function declarations to x86.h Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 18/52] KVM: MMU: Change guest pte access to kvm_{read,write}_guest() Avi Kivity
                   ` (34 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jan Kiszka

From: Jan Kiszka <jan.kiszka@siemens.com>

Ensure that segment.base == segment.selector << 4 when entering the real
mode on Intel so that the CPU will not bark at us.  This fixes some old
protected mode demo from http://www.x86.org/articles/pmbasics/tspec_a1_doc.htm.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/vmx.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index c23f399..fbe792d 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1165,7 +1165,8 @@ static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
 	save->base = vmcs_readl(sf->base);
 	save->limit = vmcs_read32(sf->limit);
 	save->ar = vmcs_read32(sf->ar_bytes);
-	vmcs_write16(sf->selector, vmcs_readl(sf->base) >> 4);
+	vmcs_write16(sf->selector, save->base >> 4);
+	vmcs_write32(sf->base, save->base & 0xfffff);
 	vmcs_write32(sf->limit, 0xffff);
 	vmcs_write32(sf->ar_bytes, 0xf3);
 }
-- 
1.5.3.7


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

* [PATCH 18/52] KVM: MMU: Change guest pte access to kvm_{read,write}_guest()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (16 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 17/52] KVM: VMX: Force seg.base == (seg.sel << 4) in real mode Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 19/52] KVM: Simplify kvm_clear_guest_page() Avi Kivity
                   ` (33 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Izik Eidus

From: Izik Eidus <izike@qumranet.com>

Things are simpler and more regular this way.

Signed-off-by: Izik Eidus <izike@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/paging_tmpl.h |   24 +++++-------------------
 1 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 0f0266a..be66401 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -72,7 +72,6 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 			    struct kvm_vcpu *vcpu, gva_t addr,
 			    int write_fault, int user_fault, int fetch_fault)
 {
-	struct page *page = NULL;
 	pt_element_t *table;
 	pt_element_t pte;
 	gfn_t table_gfn;
@@ -99,16 +98,13 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 		index = PT_INDEX(addr, walker->level);
 
 		table_gfn = (pte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
+		pte_gpa = table_gfn << PAGE_SHIFT;
+		pte_gpa += index * sizeof(pt_element_t);
 		walker->table_gfn[walker->level - 1] = table_gfn;
 		pgprintk("%s: table_gfn[%d] %lx\n", __FUNCTION__,
 			 walker->level - 1, table_gfn);
 
-		page = gfn_to_page(vcpu->kvm, (pte & PT64_BASE_ADDR_MASK)
-				   >> PAGE_SHIFT);
-
-		table = kmap_atomic(page, KM_USER0);
-		pte = table[index];
-		kunmap_atomic(table, KM_USER0);
+		kvm_read_guest(vcpu->kvm, pte_gpa, &pte, sizeof(pte));
 
 		if (!is_present_pte(pte))
 			goto not_present;
@@ -128,9 +124,7 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 		if (!(pte & PT_ACCESSED_MASK)) {
 			mark_page_dirty(vcpu->kvm, table_gfn);
 			pte |= PT_ACCESSED_MASK;
-			table = kmap_atomic(page, KM_USER0);
-			table[index] = pte;
-			kunmap_atomic(table, KM_USER0);
+			kvm_write_guest(vcpu->kvm, pte_gpa, &pte, sizeof(pte));
 		}
 
 		if (walker->level == PT_PAGE_TABLE_LEVEL) {
@@ -149,21 +143,15 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 
 		walker->inherited_ar &= pte;
 		--walker->level;
-		kvm_release_page(page);
 	}
 
 	if (write_fault && !is_dirty_pte(pte)) {
 		mark_page_dirty(vcpu->kvm, table_gfn);
 		pte |= PT_DIRTY_MASK;
-		table = kmap_atomic(page, KM_USER0);
-		table[index] = pte;
-		kunmap_atomic(table, KM_USER0);
-		pte_gpa = table_gfn << PAGE_SHIFT;
-		pte_gpa += index * sizeof(pt_element_t);
+		kvm_write_guest(vcpu->kvm, pte_gpa, &pte, sizeof(pte));
 		kvm_mmu_pte_write(vcpu, pte_gpa, (u8 *)&pte, sizeof(pte));
 	}
 
-	kvm_release_page(page);
 	walker->pte = pte;
 	pgprintk("%s: pte %llx\n", __FUNCTION__, (u64)pte);
 	return 1;
@@ -182,8 +170,6 @@ err:
 		walker->error_code |= PFERR_USER_MASK;
 	if (fetch_fault)
 		walker->error_code |= PFERR_FETCH_MASK;
-	if (page)
-		kvm_release_page(page);
 	return 0;
 }
 
-- 
1.5.3.7


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

* [PATCH 19/52] KVM: Simplify kvm_clear_guest_page()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (17 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 18/52] KVM: MMU: Change guest pte access to kvm_{read,write}_guest() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h> Avi Kivity
                   ` (32 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Izik Eidus

From: Izik Eidus <izike@qumranet.com>

Use kvm_write_guest_page() with empty_zero_page, instead of doing
kmap and memset.

Signed-off-by: Izik Eidus <izike@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm_main.c |   17 +----------------
 1 files changed, 1 insertions(+), 16 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index f9fd865..469e6b4 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -633,22 +633,7 @@ int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
 
 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
 {
-	void *page_virt;
-	struct page *page;
-
-	page = gfn_to_page(kvm, gfn);
-	if (is_error_page(page)) {
-		kvm_release_page(page);
-		return -EFAULT;
-	}
-	page_virt = kmap_atomic(page, KM_USER0);
-
-	memset(page_virt + offset, 0, len);
-
-	kunmap_atomic(page_virt, KM_USER0);
-	kvm_release_page(page);
-	mark_page_dirty(kvm, gfn);
-	return 0;
+	return kvm_write_guest_page(kvm, gfn, empty_zero_page, offset, len);
 }
 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
 
-- 
1.5.3.7


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

* [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h>
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (18 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 19/52] KVM: Simplify kvm_clear_guest_page() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2008-01-03 18:14   ` Adrian Bunk
  2007-12-30  7:10 ` [PATCH 21/52] KVM: MMU: Remove unused variable Avi Kivity
                   ` (31 subsequent siblings)
  51 siblings, 1 reply; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Needed for empty_zero_page.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm_main.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 469e6b4..d6c5191 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -46,6 +46,7 @@
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <asm/desc.h>
+#include <asm/pgtable.h>
 
 MODULE_AUTHOR("Qumranet");
 MODULE_LICENSE("GPL");
-- 
1.5.3.7


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

* [PATCH 21/52] KVM: MMU: Remove unused variable
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (19 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h> Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 22/52] KVM: Remove unused "rmap_overflow" variable Avi Kivity
                   ` (30 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/paging_tmpl.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index be66401..77a2b22 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -72,7 +72,6 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 			    struct kvm_vcpu *vcpu, gva_t addr,
 			    int write_fault, int user_fault, int fetch_fault)
 {
-	pt_element_t *table;
 	pt_element_t pte;
 	gfn_t table_gfn;
 	unsigned index;
-- 
1.5.3.7


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

* [PATCH 22/52] KVM: Remove unused "rmap_overflow" variable
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (20 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 21/52] KVM: MMU: Remove unused variable Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 23/52] KVM: Correct consistent typo: "destory" -> "destroy" Avi Kivity
                   ` (29 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Hollis Blanchard

From: Hollis Blanchard <hollisb@us.ibm.com>

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 1901456..ba78a45 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -318,7 +318,6 @@ struct kvm {
 	unsigned int n_alloc_mmu_pages;
 	struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
 	struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
-	unsigned long rmap_overflow;
 	struct list_head vm_list;
 	struct file *filp;
 	struct kvm_io_bus mmio_bus;
-- 
1.5.3.7


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

* [PATCH 23/52] KVM: Correct consistent typo: "destory" -> "destroy"
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (21 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 22/52] KVM: Remove unused "rmap_overflow" variable Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 24/52] KVM: Move misplaced comment Avi Kivity
                   ` (28 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Hollis Blanchard

From: Hollis Blanchard <hollisb@us.ibm.com>

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    2 +-
 drivers/kvm/kvm_main.c |    2 +-
 drivers/kvm/x86.c      |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index ba78a45..ccba958 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -461,7 +461,7 @@ void kvm_arch_vcpu_free(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);
-void kvm_arch_vcpu_destory(struct kvm_vcpu *vcpu);
+void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
 
 int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
 void kvm_arch_hardware_enable(void *garbage);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index d6c5191..9c94491 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -824,7 +824,7 @@ unlink:
 	kvm->vcpus[n] = NULL;
 	mutex_unlock(&kvm->lock);
 vcpu_destroy:
-	kvm_arch_vcpu_destory(vcpu);
+	kvm_arch_vcpu_destroy(vcpu);
 	return r;
 }
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 2257a0a..5a1b72f 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2513,7 +2513,7 @@ fail:
 	return ERR_PTR(r);
 }
 
-void kvm_arch_vcpu_destory(struct kvm_vcpu *vcpu)
+void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
 {
 	vcpu_load(vcpu);
 	kvm_mmu_unload(vcpu);
-- 
1.5.3.7


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

* [PATCH 24/52] KVM: Move misplaced comment
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (22 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 23/52] KVM: Correct consistent typo: "destory" -> "destroy" Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 25/52] KVM: Portability: Move kvm_memory_alias to asm/kvm.h Avi Kivity
                   ` (27 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Hollis Blanchard

From: Hollis Blanchard <hollisb@us.ibm.com>

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index ccba958..52e8018 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -135,15 +135,15 @@ struct kvm_mmu {
 
 #define KVM_NR_MEM_OBJS 40
 
+/*
+ * We don't want allocation failures within the mmu code, so we preallocate
+ * enough memory for a single page fault in a cache.
+ */
 struct kvm_mmu_memory_cache {
 	int nobjs;
 	void *objects[KVM_NR_MEM_OBJS];
 };
 
-/*
- * We don't want allocation failures within the mmu code, so we preallocate
- * enough memory for a single page fault in a cache.
- */
 struct kvm_guest_debug {
 	int enabled;
 	unsigned long bp[4];
-- 
1.5.3.7


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

* [PATCH 25/52] KVM: Portability: Move kvm_memory_alias to asm/kvm.h
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (23 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 24/52] KVM: Move misplaced comment Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 26/52] KVM: Portability: Move x86 pic strutctures Avi Kivity
                   ` (26 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jerone Young

From: Jerone Young <jyoung5@us.ibm.com>

This patch moves sturct kvm_memory_alias from include/linux/kvm.h
to include/asm-x86/kvm.h. Also have include/linux/kvm.h include
include/asm/kvm.h.

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/kvm.h |   20 ++++++++++++++++++++
 include/linux/kvm.h   |    8 +-------
 2 files changed, 21 insertions(+), 7 deletions(-)
 create mode 100644 include/asm-x86/kvm.h

diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
new file mode 100644
index 0000000..37cf8e9
--- /dev/null
+++ b/include/asm-x86/kvm.h
@@ -0,0 +1,20 @@
+#ifndef __LINUX_KVM_X86_H
+#define __LINUX_KVM_X86_H
+
+/*
+ * KVM x86 specific structures and definitions
+ *
+ */
+
+#include <asm/types.h>
+#include <linux/ioctl.h>
+
+struct kvm_memory_alias {
+	__u32 slot;  /* this has a different namespace than memory slots */
+	__u32 flags;
+	__u64 guest_phys_addr;
+	__u64 memory_size;
+	__u64 target_phys_addr;
+};
+
+#endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 71d33d6..d09dd5d 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -9,6 +9,7 @@
 
 #include <asm/types.h>
 #include <linux/ioctl.h>
+#include <asm/kvm.h>
 
 #define KVM_API_VERSION 12
 
@@ -35,13 +36,6 @@ struct kvm_userspace_memory_region {
 /* for kvm_memory_region::flags */
 #define KVM_MEM_LOG_DIRTY_PAGES  1UL
 
-struct kvm_memory_alias {
-	__u32 slot;  /* this has a different namespace than memory slots */
-	__u32 flags;
-	__u64 guest_phys_addr;
-	__u64 memory_size;
-	__u64 target_phys_addr;
-};
 
 /* for KVM_IRQ_LINE */
 struct kvm_irq_level {
-- 
1.5.3.7


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

* [PATCH 26/52] KVM: Portability: Move x86 pic strutctures
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (24 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 25/52] KVM: Portability: Move kvm_memory_alias to asm/kvm.h Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 27/52] KVM: Portability: Move kvm_regs to <asm/kvm.h> Avi Kivity
                   ` (25 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jerone Young

From: Jerone Young <jyoung5@us.ibm.com>

This patch moves structures:
	kvm_pic_state
	kvm_ioapic_state

to inclue/asm-x86/kvm.h.

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/kvm.h |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/kvm.h   |   48 ------------------------------------------------
 2 files changed, 49 insertions(+), 48 deletions(-)

diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
index 37cf8e9..80752bc 100644
--- a/include/asm-x86/kvm.h
+++ b/include/asm-x86/kvm.h
@@ -17,4 +17,53 @@ struct kvm_memory_alias {
 	__u64 target_phys_addr;
 };
 
+/* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
+struct kvm_pic_state {
+	__u8 last_irr;	/* edge detection */
+	__u8 irr;		/* interrupt request register */
+	__u8 imr;		/* interrupt mask register */
+	__u8 isr;		/* interrupt service register */
+	__u8 priority_add;	/* highest irq priority */
+	__u8 irq_base;
+	__u8 read_reg_select;
+	__u8 poll;
+	__u8 special_mask;
+	__u8 init_state;
+	__u8 auto_eoi;
+	__u8 rotate_on_auto_eoi;
+	__u8 special_fully_nested_mode;
+	__u8 init4;		/* true if 4 byte init */
+	__u8 elcr;		/* PIIX edge/trigger selection */
+	__u8 elcr_mask;
+};
+
+#define KVM_IOAPIC_NUM_PINS  24
+struct kvm_ioapic_state {
+	__u64 base_address;
+	__u32 ioregsel;
+	__u32 id;
+	__u32 irr;
+	__u32 pad;
+	union {
+		__u64 bits;
+		struct {
+			__u8 vector;
+			__u8 delivery_mode:3;
+			__u8 dest_mode:1;
+			__u8 delivery_status:1;
+			__u8 polarity:1;
+			__u8 remote_irr:1;
+			__u8 trig_mode:1;
+			__u8 mask:1;
+			__u8 reserve:7;
+			__u8 reserved[4];
+			__u8 dest_id;
+		} fields;
+	} redirtbl[KVM_IOAPIC_NUM_PINS];
+};
+
+#define KVM_IRQCHIP_PIC_MASTER   0
+#define KVM_IRQCHIP_PIC_SLAVE    1
+#define KVM_IRQCHIP_IOAPIC       2
+
 #endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index d09dd5d..1779c3d 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -48,54 +48,6 @@ struct kvm_irq_level {
 	__u32 level;
 };
 
-/* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
-struct kvm_pic_state {
-	__u8 last_irr;	/* edge detection */
-	__u8 irr;		/* interrupt request register */
-	__u8 imr;		/* interrupt mask register */
-	__u8 isr;		/* interrupt service register */
-	__u8 priority_add;	/* highest irq priority */
-	__u8 irq_base;
-	__u8 read_reg_select;
-	__u8 poll;
-	__u8 special_mask;
-	__u8 init_state;
-	__u8 auto_eoi;
-	__u8 rotate_on_auto_eoi;
-	__u8 special_fully_nested_mode;
-	__u8 init4;		/* true if 4 byte init */
-	__u8 elcr;		/* PIIX edge/trigger selection */
-	__u8 elcr_mask;
-};
-
-#define KVM_IOAPIC_NUM_PINS  24
-struct kvm_ioapic_state {
-	__u64 base_address;
-	__u32 ioregsel;
-	__u32 id;
-	__u32 irr;
-	__u32 pad;
-	union {
-		__u64 bits;
-		struct {
-			__u8 vector;
-			__u8 delivery_mode:3;
-			__u8 dest_mode:1;
-			__u8 delivery_status:1;
-			__u8 polarity:1;
-			__u8 remote_irr:1;
-			__u8 trig_mode:1;
-			__u8 mask:1;
-			__u8 reserve:7;
-			__u8 reserved[4];
-			__u8 dest_id;
-		} fields;
-	} redirtbl[KVM_IOAPIC_NUM_PINS];
-};
-
-#define KVM_IRQCHIP_PIC_MASTER   0
-#define KVM_IRQCHIP_PIC_SLAVE    1
-#define KVM_IRQCHIP_IOAPIC       2
 
 struct kvm_irqchip {
 	__u32 chip_id;
-- 
1.5.3.7


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

* [PATCH 27/52] KVM: Portability: Move kvm_regs to <asm/kvm.h>
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (25 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 26/52] KVM: Portability: Move x86 pic strutctures Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 28/52] KVM: Portability: Move structure lapic_state " Avi Kivity
                   ` (24 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jerone Young

From: Jerone Young <jyoung5@us.ibm.com>

This patch moves structure kvm_regs to include/asm-x86/kvm.h.
Each architecture will need to create there own version of this
structure.

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/kvm.h |   10 ++++++++++
 include/linux/kvm.h   |    9 ---------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
index 80752bc..c83a2ff 100644
--- a/include/asm-x86/kvm.h
+++ b/include/asm-x86/kvm.h
@@ -66,4 +66,14 @@ struct kvm_ioapic_state {
 #define KVM_IRQCHIP_PIC_SLAVE    1
 #define KVM_IRQCHIP_IOAPIC       2
 
+/* for KVM_GET_REGS and KVM_SET_REGS */
+struct kvm_regs {
+	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
+	__u64 rax, rbx, rcx, rdx;
+	__u64 rsi, rdi, rsp, rbp;
+	__u64 r8,  r9,  r10, r11;
+	__u64 r12, r13, r14, r15;
+	__u64 rip, rflags;
+};
+
 #endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 1779c3d..0d83efc 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -134,15 +134,6 @@ struct kvm_run {
 	};
 };
 
-/* for KVM_GET_REGS and KVM_SET_REGS */
-struct kvm_regs {
-	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
-	__u64 rax, rbx, rcx, rdx;
-	__u64 rsi, rdi, rsp, rbp;
-	__u64 r8,  r9,  r10, r11;
-	__u64 r12, r13, r14, r15;
-	__u64 rip, rflags;
-};
 
 /* for KVM_GET_FPU and KVM_SET_FPU */
 struct kvm_fpu {
-- 
1.5.3.7


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

* [PATCH 28/52] KVM: Portability: Move structure lapic_state to <asm/kvm.h>
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (26 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 27/52] KVM: Portability: Move kvm_regs to <asm/kvm.h> Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 29/52] KVM: Portability: Move kvm_segment & kvm_dtable structure " Avi Kivity
                   ` (23 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jerone Young

From: Jerone Young <jyoung5@us.ibm.com>

This patch moves structure lapic_state from include/linux/kvm.h
to include/asm-x86/kvm.h

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/kvm.h |    6 ++++++
 include/linux/kvm.h   |    5 -----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
index c83a2ff..a2c65b5 100644
--- a/include/asm-x86/kvm.h
+++ b/include/asm-x86/kvm.h
@@ -76,4 +76,10 @@ struct kvm_regs {
 	__u64 rip, rflags;
 };
 
+/* for KVM_GET_LAPIC and KVM_SET_LAPIC */
+#define KVM_APIC_REG_SIZE 0x400
+struct kvm_lapic_state {
+	char regs[KVM_APIC_REG_SIZE];
+};
+
 #endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 0d83efc..280ec0d 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -150,11 +150,6 @@ struct kvm_fpu {
 	__u32 pad2;
 };
 
-/* for KVM_GET_LAPIC and KVM_SET_LAPIC */
-#define KVM_APIC_REG_SIZE 0x400
-struct kvm_lapic_state {
-	char regs[KVM_APIC_REG_SIZE];
-};
 
 struct kvm_segment {
 	__u64 base;
-- 
1.5.3.7


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

* [PATCH 29/52] KVM: Portability: Move kvm_segment & kvm_dtable structure to  <asm/kvm.h>
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (27 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 28/52] KVM: Portability: Move structure lapic_state " Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 30/52] KVM: Portability: Move kvm_sregs and msr structures " Avi Kivity
                   ` (22 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jerone Young

From: Jerone Young <jyoung5@us.ibm.com>

This patch moves structures:
	kvm_segment
	kvm_dtable
from include/linux/kvm.h to include/asm-x86/kvm.h

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/kvm.h |   17 +++++++++++++++++
 include/linux/kvm.h   |   15 ---------------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
index a2c65b5..644a325 100644
--- a/include/asm-x86/kvm.h
+++ b/include/asm-x86/kvm.h
@@ -82,4 +82,21 @@ struct kvm_lapic_state {
 	char regs[KVM_APIC_REG_SIZE];
 };
 
+struct kvm_segment {
+	__u64 base;
+	__u32 limit;
+	__u16 selector;
+	__u8  type;
+	__u8  present, dpl, db, s, l, g, avl;
+	__u8  unusable;
+	__u8  padding;
+};
+
+struct kvm_dtable {
+	__u64 base;
+	__u16 limit;
+	__u16 padding[3];
+};
+
+
 #endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 280ec0d..442cb58 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -151,21 +151,6 @@ struct kvm_fpu {
 };
 
 
-struct kvm_segment {
-	__u64 base;
-	__u32 limit;
-	__u16 selector;
-	__u8  type;
-	__u8  present, dpl, db, s, l, g, avl;
-	__u8  unusable;
-	__u8  padding;
-};
-
-struct kvm_dtable {
-	__u64 base;
-	__u16 limit;
-	__u16 padding[3];
-};
 
 /* for KVM_GET_SREGS and KVM_SET_SREGS */
 struct kvm_sregs {
-- 
1.5.3.7


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

* [PATCH 30/52] KVM: Portability: Move kvm_sregs and msr structures to <asm/kvm.h>
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (28 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 29/52] KVM: Portability: Move kvm_segment & kvm_dtable structure " Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 31/52] KVM: Portability: Move cpuid " Avi Kivity
                   ` (21 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jerone Young

From: Jerone Young <jyoung5@us.ibm.com>

Move structures:
	kvm_sregs
	kvm_msr_entry
	kvm_msrs
	kvm_msr_list

from include/linux/kvm.h to include/asm-x86/kvm.h

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/kvm.h |   36 ++++++++++++++++++++++++++++++++++++
 include/linux/kvm.h   |   36 ------------------------------------
 2 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
index 644a325..32c7dda 100644
--- a/include/asm-x86/kvm.h
+++ b/include/asm-x86/kvm.h
@@ -9,6 +9,9 @@
 #include <asm/types.h>
 #include <linux/ioctl.h>
 
+/* Architectural interrupt line count. */
+#define KVM_NR_INTERRUPTS 256
+
 struct kvm_memory_alias {
 	__u32 slot;  /* this has a different namespace than memory slots */
 	__u32 flags;
@@ -99,4 +102,37 @@ struct kvm_dtable {
 };
 
 
+/* for KVM_GET_SREGS and KVM_SET_SREGS */
+struct kvm_sregs {
+	/* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
+	struct kvm_segment cs, ds, es, fs, gs, ss;
+	struct kvm_segment tr, ldt;
+	struct kvm_dtable gdt, idt;
+	__u64 cr0, cr2, cr3, cr4, cr8;
+	__u64 efer;
+	__u64 apic_base;
+	__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
+};
+
+struct kvm_msr_entry {
+	__u32 index;
+	__u32 reserved;
+	__u64 data;
+};
+
+/* for KVM_GET_MSRS and KVM_SET_MSRS */
+struct kvm_msrs {
+	__u32 nmsrs; /* number of msrs in entries */
+	__u32 pad;
+
+	struct kvm_msr_entry entries[0];
+};
+
+/* for KVM_GET_MSR_INDEX_LIST */
+struct kvm_msr_list {
+	__u32 nmsrs; /* number of msrs in entries */
+	__u32 indices[0];
+};
+
+
 #endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 442cb58..e6867aa 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -13,9 +13,6 @@
 
 #define KVM_API_VERSION 12
 
-/* Architectural interrupt line count. */
-#define KVM_NR_INTERRUPTS 256
-
 /* for KVM_CREATE_MEMORY_REGION */
 struct kvm_memory_region {
 	__u32 slot;
@@ -151,39 +148,6 @@ struct kvm_fpu {
 };
 
 
-
-/* for KVM_GET_SREGS and KVM_SET_SREGS */
-struct kvm_sregs {
-	/* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
-	struct kvm_segment cs, ds, es, fs, gs, ss;
-	struct kvm_segment tr, ldt;
-	struct kvm_dtable gdt, idt;
-	__u64 cr0, cr2, cr3, cr4, cr8;
-	__u64 efer;
-	__u64 apic_base;
-	__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
-};
-
-struct kvm_msr_entry {
-	__u32 index;
-	__u32 reserved;
-	__u64 data;
-};
-
-/* for KVM_GET_MSRS and KVM_SET_MSRS */
-struct kvm_msrs {
-	__u32 nmsrs; /* number of msrs in entries */
-	__u32 pad;
-
-	struct kvm_msr_entry entries[0];
-};
-
-/* for KVM_GET_MSR_INDEX_LIST */
-struct kvm_msr_list {
-	__u32 nmsrs; /* number of msrs in entries */
-	__u32 indices[0];
-};
-
 /* for KVM_TRANSLATE */
 struct kvm_translation {
 	/* in */
-- 
1.5.3.7


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

* [PATCH 31/52] KVM: Portability: Move cpuid structures to <asm/kvm.h>
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (29 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 30/52] KVM: Portability: Move kvm_sregs and msr structures " Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 32/52] KVM: Export include/asm-x86/kvm.h Avi Kivity
                   ` (20 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Jerone Young

From: Jerone Young <jyoung5@us.ibm.com>

This patch moves structures:
	kvm_cpuid_entry
	kvm_cpuid

from include/linux/kvm.h to include/asm-x86/kvm.h

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/kvm.h |   17 +++++++++++++++++
 include/linux/kvm.h   |   16 ----------------
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
index 32c7dda..4837d75 100644
--- a/include/asm-x86/kvm.h
+++ b/include/asm-x86/kvm.h
@@ -135,4 +135,21 @@ struct kvm_msr_list {
 };
 
 
+struct kvm_cpuid_entry {
+	__u32 function;
+	__u32 eax;
+	__u32 ebx;
+	__u32 ecx;
+	__u32 edx;
+	__u32 padding;
+};
+
+/* for KVM_SET_CPUID */
+struct kvm_cpuid {
+	__u32 nent;
+	__u32 padding;
+	struct kvm_cpuid_entry entries[0];
+};
+
+
 #endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index e6867aa..fd4f900 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -192,22 +192,6 @@ struct kvm_dirty_log {
 	};
 };
 
-struct kvm_cpuid_entry {
-	__u32 function;
-	__u32 eax;
-	__u32 ebx;
-	__u32 ecx;
-	__u32 edx;
-	__u32 padding;
-};
-
-/* for KVM_SET_CPUID */
-struct kvm_cpuid {
-	__u32 nent;
-	__u32 padding;
-	struct kvm_cpuid_entry entries[0];
-};
-
 /* for KVM_SET_SIGNAL_MASK */
 struct kvm_signal_mask {
 	__u32 len;
-- 
1.5.3.7


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

* [PATCH 32/52] KVM: Export include/asm-x86/kvm.h
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (30 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 31/52] KVM: Portability: Move cpuid " Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 33/52] KVM: MMU: Fix potential memory leak with smp real-mode Avi Kivity
                   ` (19 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 include/asm-x86/Kbuild |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/asm-x86/Kbuild b/include/asm-x86/Kbuild
index 12db5a1..da5eb69 100644
--- a/include/asm-x86/Kbuild
+++ b/include/asm-x86/Kbuild
@@ -3,6 +3,7 @@ include include/asm-generic/Kbuild.asm
 header-y += boot.h
 header-y += bootparam.h
 header-y += debugreg.h
+header-y += kvm.h
 header-y += ldt.h
 header-y += msr-index.h
 header-y += prctl.h
-- 
1.5.3.7


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

* [PATCH 33/52] KVM: MMU: Fix potential memory leak with smp real-mode
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (31 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 32/52] KVM: Export include/asm-x86/kvm.h Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 34/52] KVM: MMU: Selectively set PageDirty when releasing guest memory Avi Kivity
                   ` (18 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Izik Eidus

From: Izik Eidus <izike@qumranet.com>

When we map a page, we check whether some other vcpu mapped it for us and if
so, bail out.  But we should decrease the refcount on the page as we do so.

Signed-off-by: Izik Eidus <izike@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/mmu.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 87d8e70..8add4d5 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -907,8 +907,10 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
 
 			pte = table[index];
 			was_rmapped = is_rmap_pte(pte);
-			if (is_shadow_present_pte(pte) && is_writeble_pte(pte))
+			if (is_shadow_present_pte(pte) && is_writeble_pte(pte)) {
+				kvm_release_page(pfn_to_page(p >> PAGE_SHIFT));
 				return 0;
+			}
 			mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT);
 			page_header_update_slot(vcpu->kvm, table, v);
 			table[index] = p | PT_PRESENT_MASK | PT_WRITABLE_MASK |
-- 
1.5.3.7


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

* [PATCH 34/52] KVM: MMU: Selectively set PageDirty when releasing guest memory
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (32 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 33/52] KVM: MMU: Fix potential memory leak with smp real-mode Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 35/52] KVM: x86 emulator: retire ->write_std() Avi Kivity
                   ` (17 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Izik Eidus

From: Izik Eidus <izike@localhost.localdomain>

Improve dirty bit setting for pages that kvm release, until now every page
that we released we marked dirty, from now only pages that have potential
to get dirty we mark dirty.

Signed-off-by: Izik Eidus <izike@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h         |    3 ++-
 drivers/kvm/kvm_main.c    |   12 +++++++++---
 drivers/kvm/mmu.c         |   23 +++++++++++++++--------
 drivers/kvm/paging_tmpl.h |   12 ++++++------
 drivers/kvm/x86.c         |    2 +-
 5 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 52e8018..c2acd74 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -393,7 +393,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
 			    int user_alloc);
 gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn);
 struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
-void kvm_release_page(struct page *page);
+void kvm_release_page_clean(struct page *page);
+void kvm_release_page_dirty(struct page *page);
 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
 			int len);
 int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 9c94491..f06fa3a 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -543,13 +543,19 @@ struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
 
 EXPORT_SYMBOL_GPL(gfn_to_page);
 
-void kvm_release_page(struct page *page)
+void kvm_release_page_clean(struct page *page)
+{
+	put_page(page);
+}
+EXPORT_SYMBOL_GPL(kvm_release_page_clean);
+
+void kvm_release_page_dirty(struct page *page)
 {
 	if (!PageReserved(page))
 		SetPageDirty(page);
 	put_page(page);
 }
-EXPORT_SYMBOL_GPL(kvm_release_page);
+EXPORT_SYMBOL_GPL(kvm_release_page_dirty);
 
 static int next_segment(unsigned long len, int offset)
 {
@@ -1055,7 +1061,7 @@ static struct page *kvm_vm_nopage(struct vm_area_struct *vma,
 	/* current->mm->mmap_sem is already held so call lockless version */
 	page = __gfn_to_page(kvm, pgoff);
 	if (is_error_page(page)) {
-		kvm_release_page(page);
+		kvm_release_page_clean(page);
 		return NOPAGE_SIGBUS;
 	}
 	if (type != NULL)
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 8add4d5..4624f37 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -420,14 +420,18 @@ static void rmap_remove(struct kvm *kvm, u64 *spte)
 	struct kvm_rmap_desc *desc;
 	struct kvm_rmap_desc *prev_desc;
 	struct kvm_mmu_page *page;
+	struct page *release_page;
 	unsigned long *rmapp;
 	int i;
 
 	if (!is_rmap_pte(*spte))
 		return;
 	page = page_header(__pa(spte));
-	kvm_release_page(pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >>
-			 PAGE_SHIFT));
+	release_page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
+	if (is_writeble_pte(*spte))
+		kvm_release_page_dirty(release_page);
+	else
+		kvm_release_page_clean(release_page);
 	rmapp = gfn_to_rmap(kvm, page->gfns[spte - page->spt]);
 	if (!*rmapp) {
 		printk(KERN_ERR "rmap_remove: %p %llx 0->BUG\n", spte, *spte);
@@ -893,7 +897,9 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
 {
 	int level = PT32E_ROOT_LEVEL;
 	hpa_t table_addr = vcpu->mmu.root_hpa;
+	struct page *page;
 
+	page = pfn_to_page(p >> PAGE_SHIFT);
 	for (; ; level--) {
 		u32 index = PT64_INDEX(v, level);
 		u64 *table;
@@ -908,7 +914,7 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
 			pte = table[index];
 			was_rmapped = is_rmap_pte(pte);
 			if (is_shadow_present_pte(pte) && is_writeble_pte(pte)) {
-				kvm_release_page(pfn_to_page(p >> PAGE_SHIFT));
+				kvm_release_page_clean(page);
 				return 0;
 			}
 			mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT);
@@ -918,7 +924,8 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
 			if (!was_rmapped)
 				rmap_add(vcpu, &table[index], v >> PAGE_SHIFT);
 			else
-				kvm_release_page(pfn_to_page(p >> PAGE_SHIFT));
+				kvm_release_page_clean(page);
+
 			return 0;
 		}
 
@@ -933,7 +940,7 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
 						     1, 3, &table[index]);
 			if (!new_table) {
 				pgprintk("nonpaging_map: ENOMEM\n");
-				kvm_release_page(pfn_to_page(p >> PAGE_SHIFT));
+				kvm_release_page_clean(page);
 				return -ENOMEM;
 			}
 
@@ -1049,8 +1056,8 @@ static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
 	paddr = gpa_to_hpa(vcpu->kvm, addr & PT64_BASE_ADDR_MASK);
 
 	if (is_error_hpa(paddr)) {
-		kvm_release_page(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
-				 >> PAGE_SHIFT));
+		kvm_release_page_clean(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
+				       >> PAGE_SHIFT));
 		return 1;
 	}
 
@@ -1580,7 +1587,7 @@ static void audit_mappings_page(struct kvm_vcpu *vcpu, u64 page_pte,
 				       " valid guest gva %lx\n", audit_msg, va);
 			page = pfn_to_page((gpa & PT64_BASE_ADDR_MASK)
 					   >> PAGE_SHIFT);
-			kvm_release_page(page);
+			kvm_release_page_clean(page);
 
 		}
 	}
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 77a2b22..bf15d12 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -212,8 +212,8 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 	if (is_error_hpa(paddr)) {
 		set_shadow_pte(shadow_pte,
 			       shadow_trap_nonpresent_pte | PT_SHADOW_IO_MARK);
-		kvm_release_page(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
-					     >> PAGE_SHIFT));
+		kvm_release_page_clean(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
+				       >> PAGE_SHIFT));
 		return;
 	}
 
@@ -259,12 +259,12 @@ unshadowed:
 
 			page = pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
 					   >> PAGE_SHIFT);
-			kvm_release_page(page);
+			kvm_release_page_clean(page);
 		}
 	}
 	else
-		kvm_release_page(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
-				 >> PAGE_SHIFT));
+		kvm_release_page_clean(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
+				       >> PAGE_SHIFT));
 	if (!ptwrite || !*ptwrite)
 		vcpu->last_pte_updated = shadow_pte;
 }
@@ -503,7 +503,7 @@ static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu,
 		else
 			sp->spt[i] = shadow_notrap_nonpresent_pte;
 	kunmap_atomic(gpt, KM_USER0);
-	kvm_release_page(page);
+	kvm_release_page_clean(page);
 }
 
 #undef pt_element_t
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 5a1b72f..6212984 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -1472,7 +1472,7 @@ static void free_pio_guest_pages(struct kvm_vcpu *vcpu)
 
 	for (i = 0; i < ARRAY_SIZE(vcpu->pio.guest_pages); ++i)
 		if (vcpu->pio.guest_pages[i]) {
-			kvm_release_page(vcpu->pio.guest_pages[i]);
+			kvm_release_page_dirty(vcpu->pio.guest_pages[i]);
 			vcpu->pio.guest_pages[i] = NULL;
 		}
 }
-- 
1.5.3.7


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

* [PATCH 35/52] KVM: x86 emulator: retire ->write_std()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (33 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 34/52] KVM: MMU: Selectively set PageDirty when releasing guest memory Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 36/52] KVM: x86 emulator: prefetch up to 15 bytes of the instruction executed Avi Kivity
                   ` (16 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Theoretically used to acccess memory known to be ordinary RAM, it was
never implemented.  It is questionable whether it is possible to implement
it correctly.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/x86.c         |   10 ----------
 drivers/kvm/x86_emulate.h |   11 -----------
 2 files changed, 0 insertions(+), 21 deletions(-)

diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 6212984..5a54e32 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -1162,15 +1162,6 @@ int emulator_read_std(unsigned long addr,
 }
 EXPORT_SYMBOL_GPL(emulator_read_std);
 
-static int emulator_write_std(unsigned long addr,
-			      const void *val,
-			      unsigned int bytes,
-			      struct kvm_vcpu *vcpu)
-{
-	pr_unimpl(vcpu, "emulator_write_std: addr %lx n %d\n", addr, bytes);
-	return X86EMUL_UNHANDLEABLE;
-}
-
 static int emulator_read_emulated(unsigned long addr,
 				  void *val,
 				  unsigned int bytes,
@@ -1367,7 +1358,6 @@ EXPORT_SYMBOL_GPL(kvm_report_emulation_failure);
 
 struct x86_emulate_ops emulate_ops = {
 	.read_std            = emulator_read_std,
-	.write_std           = emulator_write_std,
 	.read_emulated       = emulator_read_emulated,
 	.write_emulated      = emulator_write_emulated,
 	.cmpxchg_emulated    = emulator_cmpxchg_emulated,
diff --git a/drivers/kvm/x86_emulate.h b/drivers/kvm/x86_emulate.h
index e34868b..a62bf14 100644
--- a/drivers/kvm/x86_emulate.h
+++ b/drivers/kvm/x86_emulate.h
@@ -63,17 +63,6 @@ struct x86_emulate_ops {
 			unsigned int bytes, struct kvm_vcpu *vcpu);
 
 	/*
-	 * write_std: Write bytes of standard (non-emulated/special) memory.
-	 *            Used for stack operations, and others.
-	 *  @addr:  [IN ] Linear address to which to write.
-	 *  @val:   [IN ] Value to write to memory (low-order bytes used as
-	 *                required).
-	 *  @bytes: [IN ] Number of bytes to write to memory.
-	 */
-	int (*write_std)(unsigned long addr, const void *val,
-			 unsigned int bytes, struct kvm_vcpu *vcpu);
-
-	/*
 	 * read_emulated: Read bytes from emulated/special memory area.
 	 *  @addr:  [IN ] Linear address from which to read.
 	 *  @val:   [OUT] Value read from memory, zero-extended to 'u_long'.
-- 
1.5.3.7


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

* [PATCH 36/52] KVM: x86 emulator: prefetch up to 15 bytes of the instruction executed
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (34 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 35/52] KVM: x86 emulator: retire ->write_std() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 37/52] KVM: Recalculate mmu pages needed for every memory region change Avi Kivity
                   ` (15 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Instead of fetching one byte at a time, prefetch 15 bytes (or until the next
page boundary) to avoid guest page table walks.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/x86_emulate.c |   38 ++++++++++++++++++++++++++++++++++++--
 drivers/kvm/x86_emulate.h |    7 +++++++
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 8e2162f..6e7f774 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -414,8 +414,7 @@ static u16 twobyte_table[256] = {
 /* Fetch next part of the instruction being emulated. */
 #define insn_fetch(_type, _size, _eip)                                  \
 ({	unsigned long _x;						\
-	rc = ops->read_std((unsigned long)(_eip) + ctxt->cs_base, &_x,	\
-			   (_size), ctxt->vcpu);			\
+	rc = do_insn_fetch(ctxt, ops, (_eip), &_x, (_size));		\
 	if (rc != 0)							\
 		goto done;						\
 	(_eip) += (_size);						\
@@ -446,6 +445,41 @@ static u16 twobyte_table[256] = {
 		register_address_increment(c->eip, rel);		\
 	} while (0)
 
+static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
+			      struct x86_emulate_ops *ops,
+			      unsigned long linear, u8 *dest)
+{
+	struct fetch_cache *fc = &ctxt->decode.fetch;
+	int rc;
+	int size;
+
+	if (linear < fc->start || linear >= fc->end) {
+		size = min(15UL, PAGE_SIZE - offset_in_page(linear));
+		rc = ops->read_std(linear, fc->data, size, ctxt->vcpu);
+		if (rc)
+			return rc;
+		fc->start = linear;
+		fc->end = linear + size;
+	}
+	*dest = fc->data[linear - fc->start];
+	return 0;
+}
+
+static int do_insn_fetch(struct x86_emulate_ctxt *ctxt,
+			 struct x86_emulate_ops *ops,
+			 unsigned long eip, void *dest, unsigned size)
+{
+	int rc = 0;
+
+	eip += ctxt->cs_base;
+	while (size--) {
+		rc = do_fetch_insn_byte(ctxt, ops, eip++, dest++);
+		if (rc)
+			return rc;
+	}
+	return 0;
+}
+
 /*
  * Given the 'reg' portion of a ModRM byte, and a register block, return a
  * pointer into the block that addresses the relevant register.
diff --git a/drivers/kvm/x86_emulate.h b/drivers/kvm/x86_emulate.h
index a62bf14..4603b2b 100644
--- a/drivers/kvm/x86_emulate.h
+++ b/drivers/kvm/x86_emulate.h
@@ -108,6 +108,12 @@ struct operand {
 	unsigned long val, orig_val, *ptr;
 };
 
+struct fetch_cache {
+	u8 data[15];
+	unsigned long start;
+	unsigned long end;
+};
+
 struct decode_cache {
 	u8 twobyte;
 	u8 b;
@@ -130,6 +136,7 @@ struct decode_cache {
 	u8 use_modrm_ea;
 	unsigned long modrm_ea;
 	unsigned long modrm_val;
+	struct fetch_cache fetch;
 };
 
 struct x86_emulate_ctxt {
-- 
1.5.3.7


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

* [PATCH 37/52] KVM: Recalculate mmu pages needed for every memory region change
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (35 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 36/52] KVM: x86 emulator: prefetch up to 15 bytes of the instruction executed Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 38/52] KVM: Portability: Split kvm_set_memory_region() to have an arch callout Avi Kivity
                   ` (14 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Instead of incrementally changing the mmu cache size for every memory slot
operation, recalculate it from scratch.  This is simpler and safer.

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm_main.c |   21 ++++-----------------
 drivers/kvm/mmu.c      |   19 +++++++++++++++++++
 drivers/kvm/x86.h      |    1 +
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index f06fa3a..6a702e1 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -333,26 +333,13 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	if (mem->slot >= kvm->nmemslots)
 		kvm->nmemslots = mem->slot + 1;
 
+	*memslot = new;
+
 	if (!kvm->n_requested_mmu_pages) {
-		unsigned int n_pages;
-
-		if (npages) {
-			n_pages = npages * KVM_PERMILLE_MMU_PAGES / 1000;
-			kvm_mmu_change_mmu_pages(kvm, kvm->n_alloc_mmu_pages +
-						 n_pages);
-		} else {
-			unsigned int nr_mmu_pages;
-
-			n_pages = old.npages * KVM_PERMILLE_MMU_PAGES / 1000;
-			nr_mmu_pages = kvm->n_alloc_mmu_pages - n_pages;
-			nr_mmu_pages = max(nr_mmu_pages,
-				        (unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
-			kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
-		}
+		unsigned int nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm);
+		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
 	}
 
-	*memslot = new;
-
 	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
 	kvm_flush_remote_tlbs(kvm);
 
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 4624f37..101cd53 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -1535,6 +1535,25 @@ nomem:
 	return -ENOMEM;
 }
 
+/*
+ * Caculate mmu pages needed for kvm.
+ */
+unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm)
+{
+	int i;
+	unsigned int nr_mmu_pages;
+	unsigned int  nr_pages = 0;
+
+	for (i = 0; i < kvm->nmemslots; i++)
+		nr_pages += kvm->memslots[i].npages;
+
+	nr_mmu_pages = nr_pages * KVM_PERMILLE_MMU_PAGES / 1000;
+	nr_mmu_pages = max(nr_mmu_pages,
+			(unsigned int) KVM_MIN_ALLOC_MMU_PAGES);
+
+	return nr_mmu_pages;
+}
+
 #ifdef AUDIT
 
 static const char *audit_msg;
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 90b791b..71f2477 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -236,6 +236,7 @@ void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte);
 int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
 void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
 void kvm_mmu_zap_all(struct kvm *kvm);
+unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm);
 void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
 
 enum emulation_result {
-- 
1.5.3.7


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

* [PATCH 38/52] KVM: Portability:  Split kvm_set_memory_region() to have an arch callout
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (36 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 37/52] KVM: Recalculate mmu pages needed for every memory region change Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 39/52] KVM: Split vcpu creation to avoid vcpu_load() before preemption setup Avi Kivity
                   ` (13 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Zhang Xiantao

From: Zhang Xiantao <xiantao.zhang@intel.com>

Moving !user_alloc case to kvm_arch to avoid unnecessary
code logic in non-x86 platform.

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    4 +++
 drivers/kvm/kvm_main.c |   38 ++++-------------------------------
 drivers/kvm/x86.c      |   51 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 33 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index c2acd74..49094a2 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -391,6 +391,10 @@ int kvm_set_memory_region(struct kvm *kvm,
 int __kvm_set_memory_region(struct kvm *kvm,
 			    struct kvm_userspace_memory_region *mem,
 			    int user_alloc);
+int kvm_arch_set_memory_region(struct kvm *kvm,
+				struct kvm_userspace_memory_region *mem,
+				struct kvm_memory_slot old,
+				int user_alloc);
 gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn);
 struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
 void kvm_release_page_clean(struct page *page);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 6a702e1..5f3ef54 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -291,33 +291,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 		memset(new.rmap, 0, npages * sizeof(*new.rmap));
 
 		new.user_alloc = user_alloc;
-		if (user_alloc)
-			new.userspace_addr = mem->userspace_addr;
-		else {
-			down_write(&current->mm->mmap_sem);
-			new.userspace_addr = do_mmap(NULL, 0,
-						     npages * PAGE_SIZE,
-						     PROT_READ | PROT_WRITE,
-						     MAP_SHARED | MAP_ANONYMOUS,
-						     0);
-			up_write(&current->mm->mmap_sem);
-
-			if (IS_ERR((void *)new.userspace_addr))
-				goto out_free;
-		}
-	} else {
-		if (!old.user_alloc && old.rmap) {
-			int ret;
-
-			down_write(&current->mm->mmap_sem);
-			ret = do_munmap(current->mm, old.userspace_addr,
-					old.npages * PAGE_SIZE);
-			up_write(&current->mm->mmap_sem);
-			if (ret < 0)
-				printk(KERN_WARNING
-				       "kvm_vm_ioctl_set_memory_region: "
-				       "failed to munmap memory\n");
-		}
+		new.userspace_addr = mem->userspace_addr;
 	}
 
 	/* Allocate page dirty bitmap if needed */
@@ -335,14 +309,12 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
 	*memslot = new;
 
-	if (!kvm->n_requested_mmu_pages) {
-		unsigned int nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm);
-		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
+	r = kvm_arch_set_memory_region(kvm, mem, old, user_alloc);
+	if (r) {
+		*memslot = old;
+		goto out_free;
 	}
 
-	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
-	kvm_flush_remote_tlbs(kvm);
-
 	kvm_free_physmem_slot(&old, &new);
 	return 0;
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 5a54e32..6abb2ed 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -24,6 +24,7 @@
 #include <linux/fs.h>
 #include <linux/vmalloc.h>
 #include <linux/module.h>
+#include <linux/mman.h>
 
 #include <asm/uaccess.h>
 #include <asm/msr.h>
@@ -2637,3 +2638,53 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
 	kvm_free_physmem(kvm);
 	kfree(kvm);
 }
+
+int kvm_arch_set_memory_region(struct kvm *kvm,
+				struct kvm_userspace_memory_region *mem,
+				struct kvm_memory_slot old,
+				int user_alloc)
+{
+	int npages = mem->memory_size >> PAGE_SHIFT;
+	struct kvm_memory_slot *memslot = &kvm->memslots[mem->slot];
+
+	/*To keep backward compatibility with older userspace,
+	 *x86 needs to hanlde !user_alloc case.
+	 */
+	if (!user_alloc) {
+		if (npages && !old.rmap) {
+			down_write(&current->mm->mmap_sem);
+			memslot->userspace_addr = do_mmap(NULL, 0,
+						     npages * PAGE_SIZE,
+						     PROT_READ | PROT_WRITE,
+						     MAP_SHARED | MAP_ANONYMOUS,
+						     0);
+			up_write(&current->mm->mmap_sem);
+
+			if (IS_ERR((void *)memslot->userspace_addr))
+				return PTR_ERR((void *)memslot->userspace_addr);
+		} else {
+			if (!old.user_alloc && old.rmap) {
+				int ret;
+
+				down_write(&current->mm->mmap_sem);
+				ret = do_munmap(current->mm, old.userspace_addr,
+						old.npages * PAGE_SIZE);
+				up_write(&current->mm->mmap_sem);
+				if (ret < 0)
+					printk(KERN_WARNING
+				       "kvm_vm_ioctl_set_memory_region: "
+				       "failed to munmap memory\n");
+			}
+		}
+	}
+
+	if (!kvm->n_requested_mmu_pages) {
+		unsigned int nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm);
+		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
+	}
+
+	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
+	kvm_flush_remote_tlbs(kvm);
+
+	return 0;
+}
-- 
1.5.3.7


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

* [PATCH 39/52] KVM: Split vcpu creation to avoid vcpu_load() before preemption setup
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (37 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 38/52] KVM: Portability: Split kvm_set_memory_region() to have an arch callout Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 40/52] KVM: MMU: Implement guest page fault bypass for nonpae Avi Kivity
                   ` (12 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Split kvm_arch_vcpu_create() into kvm_arch_vcpu_create() and
kvm_arch_vcpu_setup(), enabling preemption notification between the two.
This mean that we can now do vcpu_load() within kvm_arch_vcpu_setup().

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    1 +
 drivers/kvm/kvm_main.c |    4 ++++
 drivers/kvm/x86.c      |   16 +++++++---------
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 49094a2..b65f5de 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -466,6 +466,7 @@ void kvm_arch_vcpu_free(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_setup(struct kvm_vcpu *vcpu);
 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
 
 int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 5f3ef54..d99396b 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -769,6 +769,10 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
 
 	preempt_notifier_init(&vcpu->preempt_notifier, &kvm_preempt_ops);
 
+	r = kvm_arch_vcpu_setup(vcpu);
+	if (r)
+		goto vcpu_destroy;
+
 	mutex_lock(&kvm->lock);
 	if (kvm->vcpus[n]) {
 		r = -EEXIST;
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 6abb2ed..b482b6a 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2478,13 +2478,12 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
 						unsigned int id)
 {
-	int r;
-	struct kvm_vcpu *vcpu = kvm_x86_ops->vcpu_create(kvm, id);
+	return kvm_x86_ops->vcpu_create(kvm, id);
+}
 
-	if (IS_ERR(vcpu)) {
-		r = -ENOMEM;
-		goto fail;
-	}
+int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
+{
+	int r;
 
 	/* We do fxsave: this must be aligned. */
 	BUG_ON((unsigned long)&vcpu->host_fx_image & 0xF);
@@ -2497,11 +2496,10 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
 	if (r < 0)
 		goto free_vcpu;
 
-	return vcpu;
+	return 0;
 free_vcpu:
 	kvm_x86_ops->vcpu_free(vcpu);
-fail:
-	return ERR_PTR(r);
+	return r;
 }
 
 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
-- 
1.5.3.7


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

* [PATCH 40/52] KVM: MMU: Implement guest page fault bypass for nonpae
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (38 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 39/52] KVM: Split vcpu creation to avoid vcpu_load() before preemption setup Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 41/52] KVM: Add statistic for remote tlb flushes Avi Kivity
                   ` (11 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

I spent an hour worrying why I see so many guest page faults on FC6 i386.
Turns out bypass wasn't implemented for nonpae.  Implement it so it doesn't
happen again.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/paging_tmpl.h |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index bf15d12..92b9313 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -486,19 +486,22 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
 static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu,
 				 struct kvm_mmu_page *sp)
 {
-	int i;
+	int i, offset = 0;
 	pt_element_t *gpt;
 	struct page *page;
 
-	if (sp->role.metaphysical || PTTYPE == 32) {
+	if (sp->role.metaphysical
+	    || (PTTYPE == 32 && sp->role.level > PT_PAGE_TABLE_LEVEL)) {
 		nonpaging_prefetch_page(vcpu, sp);
 		return;
 	}
 
+	if (PTTYPE == 32)
+		offset = sp->role.quadrant << PT64_LEVEL_BITS;
 	page = gfn_to_page(vcpu->kvm, sp->gfn);
 	gpt = kmap_atomic(page, KM_USER0);
 	for (i = 0; i < PT64_ENT_PER_PAGE; ++i)
-		if (is_present_pte(gpt[i]))
+		if (is_present_pte(gpt[offset + i]))
 			sp->spt[i] = shadow_trap_nonpresent_pte;
 		else
 			sp->spt[i] = shadow_notrap_nonpresent_pte;
-- 
1.5.3.7


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

* [PATCH 41/52] KVM: Add statistic for remote tlb flushes
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (39 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 40/52] KVM: MMU: Implement guest page fault bypass for nonpae Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 42/52] KVM: MMU: Avoid unnecessary remote tlb flushes when guest updates a pte Avi Kivity
                   ` (10 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    1 +
 drivers/kvm/kvm_main.c |    3 +++
 drivers/kvm/x86.c      |    1 +
 3 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index b65f5de..048849d 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -300,6 +300,7 @@ struct kvm_vm_stat {
 	u32 mmu_pde_zapped;
 	u32 mmu_flooded;
 	u32 mmu_recycled;
+	u32 remote_tlb_flush;
 };
 
 struct kvm {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index d99396b..411b2bd 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -115,6 +115,9 @@ void kvm_flush_remote_tlbs(struct kvm *kvm)
 		if (cpu != -1 && cpu != raw_smp_processor_id())
 			cpu_set(cpu, cpus);
 	}
+	if (cpus_empty(cpus))
+		return;
+	++kvm->stat.remote_tlb_flush;
 	smp_call_function_mask(cpus, ack_flush, NULL, 1);
 }
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index b482b6a..ac09f38 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -73,6 +73,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
 	{ "mmu_flooded", VM_STAT(mmu_flooded) },
 	{ "mmu_recycled", VM_STAT(mmu_recycled) },
+	{ "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
 	{ NULL }
 };
 
-- 
1.5.3.7


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

* [PATCH 42/52] KVM: MMU: Avoid unnecessary remote tlb flushes when guest updates a pte
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (40 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 41/52] KVM: Add statistic for remote tlb flushes Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 43/52] KVM: Don't bother the mmu if cr3 load doesn't change cr3 Avi Kivity
                   ` (9 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

If all we're doing is increasing permissions on a pte (typical for demand
paging), then there's not need to flush remote tlbs.  Worst case they'll
get a spurious page fault.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/mmu.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 101cd53..281dd5f 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -134,6 +134,8 @@ static int dbg = 1;
 #define PT32_DIR_BASE_ADDR_MASK \
 	(PAGE_MASK & ~((1ULL << (PAGE_SHIFT + PT32_LEVEL_BITS)) - 1))
 
+#define PT64_PERM_MASK (PT_PRESENT_MASK | PT_WRITABLE_MASK | PT_USER_MASK \
+			| PT64_NX_MASK)
 
 #define PFERR_PRESENT_MASK (1U << 0)
 #define PFERR_WRITE_MASK (1U << 1)
@@ -1227,7 +1229,6 @@ static void mmu_pte_write_zap_pte(struct kvm_vcpu *vcpu,
 		}
 	}
 	set_shadow_pte(spte, shadow_trap_nonpresent_pte);
-	kvm_flush_remote_tlbs(vcpu->kvm);
 }
 
 static void mmu_pte_write_new_pte(struct kvm_vcpu *vcpu,
@@ -1250,6 +1251,27 @@ static void mmu_pte_write_new_pte(struct kvm_vcpu *vcpu,
 				    offset_in_pte);
 }
 
+static bool need_remote_flush(u64 old, u64 new)
+{
+	if (!is_shadow_present_pte(old))
+		return false;
+	if (!is_shadow_present_pte(new))
+		return true;
+	if ((old ^ new) & PT64_BASE_ADDR_MASK)
+		return true;
+	old ^= PT64_NX_MASK;
+	new ^= PT64_NX_MASK;
+	return (old & ~new & PT64_PERM_MASK) != 0;
+}
+
+static void mmu_pte_write_flush_tlb(struct kvm_vcpu *vcpu, u64 old, u64 new)
+{
+	if (need_remote_flush(old, new))
+		kvm_flush_remote_tlbs(vcpu->kvm);
+	else
+		kvm_mmu_flush_tlb(vcpu);
+}
+
 static bool last_updated_pte_accessed(struct kvm_vcpu *vcpu)
 {
 	u64 *spte = vcpu->last_pte_updated;
@@ -1265,6 +1287,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 	struct hlist_node *node, *n;
 	struct hlist_head *bucket;
 	unsigned index;
+	u64 entry;
 	u64 *spte;
 	unsigned offset = offset_in_page(gpa);
 	unsigned pte_size;
@@ -1335,9 +1358,11 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 		}
 		spte = &page->spt[page_offset / sizeof(*spte)];
 		while (npte--) {
+			entry = *spte;
 			mmu_pte_write_zap_pte(vcpu, page, spte);
 			mmu_pte_write_new_pte(vcpu, page, spte, new, bytes,
 					      page_offset & (pte_size - 1));
+			mmu_pte_write_flush_tlb(vcpu, entry, *spte);
 			++spte;
 		}
 	}
-- 
1.5.3.7


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

* [PATCH 43/52] KVM: Don't bother the mmu if cr3 load doesn't change cr3
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (41 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 42/52] KVM: MMU: Avoid unnecessary remote tlb flushes when guest updates a pte Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 44/52] KVM: MMU: Code cleanup Avi Kivity
                   ` (8 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

If the guest requests just a tlb flush, don't take the vm lock and
drop the mmu context pointlessly.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/mmu.c |    2 +-
 drivers/kvm/x86.c |   25 +++++++++++++++++++++++++
 drivers/kvm/x86.h |    1 +
 3 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 281dd5f..346aa65 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -1086,7 +1086,7 @@ static int nonpaging_init_context(struct kvm_vcpu *vcpu)
 	return 0;
 }
 
-static void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu)
+void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu)
 {
 	++vcpu->stat.tlb_flush;
 	kvm_x86_ops->tlb_flush(vcpu);
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index ac09f38..15e1203 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -166,6 +166,26 @@ out:
 	return ret;
 }
 
+static bool pdptrs_changed(struct kvm_vcpu *vcpu)
+{
+	u64 pdpte[ARRAY_SIZE(vcpu->pdptrs)];
+	bool changed = true;
+	int r;
+
+	if (is_long_mode(vcpu) || !is_pae(vcpu))
+		return false;
+
+	mutex_lock(&vcpu->kvm->lock);
+	r = kvm_read_guest(vcpu->kvm, vcpu->cr3 & ~31u, pdpte, sizeof(pdpte));
+	if (r < 0)
+		goto out;
+	changed = memcmp(pdpte, vcpu->pdptrs, sizeof(pdpte)) != 0;
+out:
+	mutex_unlock(&vcpu->kvm->lock);
+
+	return changed;
+}
+
 void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 {
 	if (cr0 & CR0_RESERVED_BITS) {
@@ -271,6 +291,11 @@ EXPORT_SYMBOL_GPL(set_cr4);
 
 void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
 {
+	if (cr3 == vcpu->cr3 && !pdptrs_changed(vcpu)) {
+		kvm_mmu_flush_tlb(vcpu);
+		return;
+	}
+
 	if (is_long_mode(vcpu)) {
 		if (cr3 & CR3_L_MODE_RESERVED_BITS) {
 			printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n");
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 71f2477..b1528c9 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -299,6 +299,7 @@ int emulator_write_emulated(unsigned long addr,
 
 unsigned long segment_base(u16 selector);
 
+void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 		       const u8 *new, int bytes);
 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
-- 
1.5.3.7


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

* [PATCH 44/52] KVM: MMU: Code cleanup
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (42 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 43/52] KVM: Don't bother the mmu if cr3 load doesn't change cr3 Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 45/52] KVM: MMU: Introduce and use gpte_to_gfn() Avi Kivity
                   ` (7 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel; +Cc: Izik Eidus

From: Izik Eidus <izike@qumranet.com>

Signed-off-by: Izik Eidus <izike@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/paging_tmpl.h |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 92b9313..6e01301 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -187,6 +187,7 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 	int dirty = gpte & PT_DIRTY_MASK;
 	u64 spte;
 	int was_rmapped = is_rmap_pte(*shadow_pte);
+	struct page *page;
 
 	pgprintk("%s: spte %llx gpte %llx access %llx write_fault %d"
 		 " user_fault %d gfn %lx\n",
@@ -205,6 +206,12 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 
 	paddr = gpa_to_hpa(vcpu->kvm, gaddr & PT64_BASE_ADDR_MASK);
 
+	/*
+	 * the reason paddr get mask even that it isnt pte is beacuse the
+	 * HPA_ERR_MASK bit might be used to signal error
+	 */
+	page = pfn_to_page((paddr & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
+
 	spte |= PT_PRESENT_MASK;
 	if (access_bits & PT_USER_MASK)
 		spte |= PT_USER_MASK;
@@ -212,8 +219,7 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 	if (is_error_hpa(paddr)) {
 		set_shadow_pte(shadow_pte,
 			       shadow_trap_nonpresent_pte | PT_SHADOW_IO_MARK);
-		kvm_release_page_clean(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
-				       >> PAGE_SHIFT));
+		kvm_release_page_clean(page);
 		return;
 	}
 
@@ -254,17 +260,11 @@ unshadowed:
 	if (!was_rmapped) {
 		rmap_add(vcpu, shadow_pte, (gaddr & PT64_BASE_ADDR_MASK)
 			 >> PAGE_SHIFT);
-		if (!is_rmap_pte(*shadow_pte)) {
-			struct page *page;
-
-			page = pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
-					   >> PAGE_SHIFT);
+		if (!is_rmap_pte(*shadow_pte))
 			kvm_release_page_clean(page);
-		}
 	}
 	else
-		kvm_release_page_clean(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
-				       >> PAGE_SHIFT));
+		kvm_release_page_clean(page);
 	if (!ptwrite || !*ptwrite)
 		vcpu->last_pte_updated = shadow_pte;
 }
-- 
1.5.3.7


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

* [PATCH 45/52] KVM: MMU: Introduce and use gpte_to_gfn()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (43 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 44/52] KVM: MMU: Code cleanup Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 46/52] KVM: MMU: Move pse36 handling to the guest walker Avi Kivity
                   ` (6 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Instead of repretitively open-coding this.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/paging_tmpl.h |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 6e01301..6f79ae8 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -52,6 +52,9 @@
 	#error Invalid PTTYPE value
 #endif
 
+#define gpte_to_gfn FNAME(gpte_to_gfn)
+#define gpte_to_gfn_pde FNAME(gpte_to_gfn_pde)
+
 /*
  * The guest_walker structure emulates the behavior of the hardware page
  * table walker.
@@ -65,6 +68,16 @@ struct guest_walker {
 	u32 error_code;
 };
 
+static gfn_t gpte_to_gfn(pt_element_t gpte)
+{
+	return (gpte & PT_BASE_ADDR_MASK) >> PAGE_SHIFT;
+}
+
+static gfn_t gpte_to_gfn_pde(pt_element_t gpte)
+{
+	return (gpte & PT_DIR_BASE_ADDR_MASK) >> PAGE_SHIFT;
+}
+
 /*
  * Fetch a guest pte for a guest virtual address
  */
@@ -96,7 +109,7 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 	for (;;) {
 		index = PT_INDEX(addr, walker->level);
 
-		table_gfn = (pte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
+		table_gfn = gpte_to_gfn(pte);
 		pte_gpa = table_gfn << PAGE_SHIFT;
 		pte_gpa += index * sizeof(pt_element_t);
 		walker->table_gfn[walker->level - 1] = table_gfn;
@@ -127,15 +140,14 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 		}
 
 		if (walker->level == PT_PAGE_TABLE_LEVEL) {
-			walker->gfn = (pte & PT_BASE_ADDR_MASK) >> PAGE_SHIFT;
+			walker->gfn = gpte_to_gfn(pte);
 			break;
 		}
 
 		if (walker->level == PT_DIRECTORY_LEVEL
 		    && (pte & PT_PAGE_SIZE_MASK)
 		    && (PTTYPE == 64 || is_pse(vcpu))) {
-			walker->gfn = (pte & PT_DIR_BASE_ADDR_MASK)
-				>> PAGE_SHIFT;
+			walker->gfn = gpte_to_gfn_pde(pte);
 			walker->gfn += PT_INDEX(addr, PT_PAGE_TABLE_LEVEL);
 			break;
 		}
@@ -296,8 +308,7 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page,
 		return;
 	pgprintk("%s: gpte %llx spte %p\n", __FUNCTION__, (u64)gpte, spte);
 	FNAME(set_pte)(vcpu, gpte, spte, PT_USER_MASK | PT_WRITABLE_MASK, 0,
-		       0, NULL, NULL,
-		       (gpte & PT_BASE_ADDR_MASK) >> PAGE_SHIFT);
+		       0, NULL, NULL, gpte_to_gfn(gpte));
 }
 
 static void FNAME(set_pde)(struct kvm_vcpu *vcpu, pt_element_t gpde,
@@ -370,8 +381,7 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
 			hugepage_access >>= PT_WRITABLE_SHIFT;
 			if (walker->pte & PT64_NX_MASK)
 				hugepage_access |= (1 << 2);
-			table_gfn = (walker->pte & PT_BASE_ADDR_MASK)
-				>> PAGE_SHIFT;
+			table_gfn = gpte_to_gfn(walker->pte);
 		} else {
 			metaphysical = 0;
 			table_gfn = walker->table_gfn[level - 2];
@@ -519,3 +529,5 @@ static void FNAME(prefetch_page)(struct kvm_vcpu *vcpu,
 #undef PT_DIR_BASE_ADDR_MASK
 #undef PT_LEVEL_BITS
 #undef PT_MAX_FULL_LEVELS
+#undef gpte_to_gfn
+#undef gpte_to_gfn_pde
-- 
1.5.3.7


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

* [PATCH 46/52] KVM: MMU: Move pse36 handling to the guest walker
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (44 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 45/52] KVM: MMU: Introduce and use gpte_to_gfn() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 47/52] KVM: MMU: Remove extra gaddr parameter from set_pte_common() Avi Kivity
                   ` (5 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/mmu.c         |    7 +++++++
 drivers/kvm/paging_tmpl.h |    5 ++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 346aa65..a9fed59 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -218,6 +218,13 @@ static int is_rmap_pte(u64 pte)
 		&& pte != shadow_notrap_nonpresent_pte;
 }
 
+static gfn_t pse36_gfn_delta(u32 gpte)
+{
+	int shift = 32 - PT32_DIR_PSE36_SHIFT - PAGE_SHIFT;
+
+	return (gpte & PT32_DIR_PSE36_MASK) << shift;
+}
+
 static void set_shadow_pte(u64 *sptep, u64 spte)
 {
 #ifdef CONFIG_X86_64
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 6f79ae8..dceb4b9 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -149,6 +149,8 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 		    && (PTTYPE == 64 || is_pse(vcpu))) {
 			walker->gfn = gpte_to_gfn_pde(pte);
 			walker->gfn += PT_INDEX(addr, PT_PAGE_TABLE_LEVEL);
+			if (PTTYPE == 32 && is_cpuid_PSE36())
+				walker->gfn += pse36_gfn_delta(pte);
 			break;
 		}
 
@@ -320,9 +322,6 @@ static void FNAME(set_pde)(struct kvm_vcpu *vcpu, pt_element_t gpde,
 
 	access_bits &= gpde;
 	gaddr = (gpa_t)gfn << PAGE_SHIFT;
-	if (PTTYPE == 32 && is_cpuid_PSE36())
-		gaddr |= (gpde & PT32_DIR_PSE36_MASK) <<
-			(32 - PT32_DIR_PSE36_SHIFT);
 	FNAME(set_pte_common)(vcpu, shadow_pte, gaddr,
 			      gpde, access_bits, user_fault, write_fault,
 			      ptwrite, walker, gfn);
-- 
1.5.3.7


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

* [PATCH 47/52] KVM: MMU: Remove extra gaddr parameter from set_pte_common()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (45 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 46/52] KVM: MMU: Move pse36 handling to the guest walker Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 48/52] KVM: MMU: Remove set_pde() Avi Kivity
                   ` (4 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Similar information is available in the gfn parameter, so use that.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/mmu.c         |    1 +
 drivers/kvm/paging_tmpl.h |   29 +++++++++--------------------
 2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index a9fed59..c3362ba 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -29,6 +29,7 @@
 
 #include <asm/page.h>
 #include <asm/cmpxchg.h>
+#include <asm/io.h>
 
 #undef MMU_DEBUG
 
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index dceb4b9..cc373ed 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -188,7 +188,6 @@ err:
 
 static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 				  u64 *shadow_pte,
-				  gpa_t gaddr,
 				  pt_element_t gpte,
 				  u64 access_bits,
 				  int user_fault,
@@ -197,7 +196,6 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 				  struct guest_walker *walker,
 				  gfn_t gfn)
 {
-	hpa_t paddr;
 	int dirty = gpte & PT_DIRTY_MASK;
 	u64 spte;
 	int was_rmapped = is_rmap_pte(*shadow_pte);
@@ -218,26 +216,20 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 	if (!dirty)
 		access_bits &= ~PT_WRITABLE_MASK;
 
-	paddr = gpa_to_hpa(vcpu->kvm, gaddr & PT64_BASE_ADDR_MASK);
-
-	/*
-	 * the reason paddr get mask even that it isnt pte is beacuse the
-	 * HPA_ERR_MASK bit might be used to signal error
-	 */
-	page = pfn_to_page((paddr & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
+	page = gfn_to_page(vcpu->kvm, gfn);
 
 	spte |= PT_PRESENT_MASK;
 	if (access_bits & PT_USER_MASK)
 		spte |= PT_USER_MASK;
 
-	if (is_error_hpa(paddr)) {
+	if (is_error_page(page)) {
 		set_shadow_pte(shadow_pte,
 			       shadow_trap_nonpresent_pte | PT_SHADOW_IO_MARK);
 		kvm_release_page_clean(page);
 		return;
 	}
 
-	spte |= paddr;
+	spte |= page_to_phys(page);
 
 	if ((access_bits & PT_WRITABLE_MASK)
 	    || (write_fault && !is_write_protection(vcpu) && !user_fault)) {
@@ -266,14 +258,14 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 unshadowed:
 
 	if (access_bits & PT_WRITABLE_MASK)
-		mark_page_dirty(vcpu->kvm, gaddr >> PAGE_SHIFT);
+		mark_page_dirty(vcpu->kvm, gfn);
 
 	pgprintk("%s: setting spte %llx\n", __FUNCTION__, spte);
 	set_shadow_pte(shadow_pte, spte);
-	page_header_update_slot(vcpu->kvm, shadow_pte, gaddr);
+	page_header_update_slot(vcpu->kvm, shadow_pte,
+				(gpa_t)gfn << PAGE_SHIFT);
 	if (!was_rmapped) {
-		rmap_add(vcpu, shadow_pte, (gaddr & PT64_BASE_ADDR_MASK)
-			 >> PAGE_SHIFT);
+		rmap_add(vcpu, shadow_pte, gfn);
 		if (!is_rmap_pte(*shadow_pte))
 			kvm_release_page_clean(page);
 	}
@@ -289,7 +281,7 @@ static void FNAME(set_pte)(struct kvm_vcpu *vcpu, pt_element_t gpte,
 			   struct guest_walker *walker, gfn_t gfn)
 {
 	access_bits &= gpte;
-	FNAME(set_pte_common)(vcpu, shadow_pte, gpte & PT_BASE_ADDR_MASK,
+	FNAME(set_pte_common)(vcpu, shadow_pte,
 			      gpte, access_bits, user_fault, write_fault,
 			      ptwrite, walker, gfn);
 }
@@ -318,11 +310,8 @@ static void FNAME(set_pde)(struct kvm_vcpu *vcpu, pt_element_t gpde,
 			   int user_fault, int write_fault, int *ptwrite,
 			   struct guest_walker *walker, gfn_t gfn)
 {
-	gpa_t gaddr;
-
 	access_bits &= gpde;
-	gaddr = (gpa_t)gfn << PAGE_SHIFT;
-	FNAME(set_pte_common)(vcpu, shadow_pte, gaddr,
+	FNAME(set_pte_common)(vcpu, shadow_pte,
 			      gpde, access_bits, user_fault, write_fault,
 			      ptwrite, walker, gfn);
 }
-- 
1.5.3.7


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

* [PATCH 48/52] KVM: MMU: Remove set_pde()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (46 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 47/52] KVM: MMU: Remove extra gaddr parameter from set_pte_common() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 49/52] KVM: MMU: Merge set_pte() and set_pte_common() Avi Kivity
                   ` (3 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

It is now identical to set_pte().

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/paging_tmpl.h |   25 ++++---------------------
 1 files changed, 4 insertions(+), 21 deletions(-)

diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index cc373ed..062f4f5 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -305,17 +305,6 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page,
 		       0, NULL, NULL, gpte_to_gfn(gpte));
 }
 
-static void FNAME(set_pde)(struct kvm_vcpu *vcpu, pt_element_t gpde,
-			   u64 *shadow_pte, u64 access_bits,
-			   int user_fault, int write_fault, int *ptwrite,
-			   struct guest_walker *walker, gfn_t gfn)
-{
-	access_bits &= gpde;
-	FNAME(set_pte_common)(vcpu, shadow_pte,
-			      gpde, access_bits, user_fault, write_fault,
-			      ptwrite, walker, gfn);
-}
-
 /*
  * Fetch a shadow pte for a specific level in the paging hierarchy.
  */
@@ -384,16 +373,10 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
 		prev_shadow_ent = shadow_ent;
 	}
 
-	if (walker->level == PT_DIRECTORY_LEVEL) {
-		FNAME(set_pde)(vcpu, walker->pte, shadow_ent,
-			       walker->inherited_ar, user_fault, write_fault,
-			       ptwrite, walker, walker->gfn);
-	} else {
-		ASSERT(walker->level == PT_PAGE_TABLE_LEVEL);
-		FNAME(set_pte)(vcpu, walker->pte, shadow_ent,
-			       walker->inherited_ar, user_fault, write_fault,
-			       ptwrite, walker, walker->gfn);
-	}
+	FNAME(set_pte)(vcpu, walker->pte, shadow_ent,
+		       walker->inherited_ar, user_fault, write_fault,
+		       ptwrite, walker, walker->gfn);
+
 	return shadow_ent;
 }
 
-- 
1.5.3.7


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

* [PATCH 49/52] KVM: MMU: Merge set_pte() and set_pte_common()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (47 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 48/52] KVM: MMU: Remove set_pde() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 50/52] KVM: MMU: Adjust page_header_update_slot() to accept a gfn instead of a gpa Avi Kivity
                   ` (2 subsequent siblings)
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Since set_pte() is now the only caller of set_pte_common(), merge the two
functions.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/paging_tmpl.h |   26 ++++++--------------------
 1 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 062f4f5..54a6ee8 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -186,15 +186,11 @@ err:
 	return 0;
 }
 
-static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
-				  u64 *shadow_pte,
-				  pt_element_t gpte,
-				  u64 access_bits,
-				  int user_fault,
-				  int write_fault,
-				  int *ptwrite,
-				  struct guest_walker *walker,
-				  gfn_t gfn)
+static void FNAME(set_pte)(struct kvm_vcpu *vcpu, pt_element_t gpte,
+			   u64 *shadow_pte, u64 access_bits,
+			   int user_fault, int write_fault,
+			   int *ptwrite, struct guest_walker *walker,
+			   gfn_t gfn)
 {
 	int dirty = gpte & PT_DIRTY_MASK;
 	u64 spte;
@@ -206,6 +202,7 @@ static void FNAME(set_pte_common)(struct kvm_vcpu *vcpu,
 		 __FUNCTION__, *shadow_pte, (u64)gpte, access_bits,
 		 write_fault, user_fault, gfn);
 
+	access_bits &= gpte;
 	/*
 	 * We don't set the accessed bit, since we sometimes want to see
 	 * whether the guest actually used the pte (in order to detect
@@ -275,17 +272,6 @@ unshadowed:
 		vcpu->last_pte_updated = shadow_pte;
 }
 
-static void FNAME(set_pte)(struct kvm_vcpu *vcpu, pt_element_t gpte,
-			   u64 *shadow_pte, u64 access_bits,
-			   int user_fault, int write_fault, int *ptwrite,
-			   struct guest_walker *walker, gfn_t gfn)
-{
-	access_bits &= gpte;
-	FNAME(set_pte_common)(vcpu, shadow_pte,
-			      gpte, access_bits, user_fault, write_fault,
-			      ptwrite, walker, gfn);
-}
-
 static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page,
 			      u64 *spte, const void *pte, int bytes,
 			      int offset_in_pte)
-- 
1.5.3.7


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

* [PATCH 50/52] KVM: MMU: Adjust page_header_update_slot() to accept a gfn instead of a gpa
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (48 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 49/52] KVM: MMU: Merge set_pte() and set_pte_common() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 51/52] KVM: MMU: Introduce gfn_to_gpa() Avi Kivity
  2007-12-30  7:10 ` [PATCH 52/52] KVM: MMU: Simplify nonpaging_map() Avi Kivity
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/mmu.c         |    7 ++++---
 drivers/kvm/paging_tmpl.h |    3 +--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index c3362ba..1dcffc4 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -860,9 +860,9 @@ static void mmu_unshadow(struct kvm *kvm, gfn_t gfn)
 	}
 }
 
-static void page_header_update_slot(struct kvm *kvm, void *pte, gpa_t gpa)
+static void page_header_update_slot(struct kvm *kvm, void *pte, gfn_t gfn)
 {
-	int slot = memslot_id(kvm, gfn_to_memslot(kvm, gpa >> PAGE_SHIFT));
+	int slot = memslot_id(kvm, gfn_to_memslot(kvm, gfn));
 	struct kvm_mmu_page *page_head = page_header(__pa(pte));
 
 	__set_bit(slot, &page_head->slot_bitmap);
@@ -928,7 +928,8 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
 				return 0;
 			}
 			mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT);
-			page_header_update_slot(vcpu->kvm, table, v);
+			page_header_update_slot(vcpu->kvm, table,
+						v >> PAGE_SHIFT);
 			table[index] = p | PT_PRESENT_MASK | PT_WRITABLE_MASK |
 								PT_USER_MASK;
 			if (!was_rmapped)
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 54a6ee8..a3da98b 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -259,8 +259,7 @@ unshadowed:
 
 	pgprintk("%s: setting spte %llx\n", __FUNCTION__, spte);
 	set_shadow_pte(shadow_pte, spte);
-	page_header_update_slot(vcpu->kvm, shadow_pte,
-				(gpa_t)gfn << PAGE_SHIFT);
+	page_header_update_slot(vcpu->kvm, shadow_pte, gfn);
 	if (!was_rmapped) {
 		rmap_add(vcpu, shadow_pte, gfn);
 		if (!is_rmap_pte(*shadow_pte))
-- 
1.5.3.7


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

* [PATCH 51/52] KVM: MMU: Introduce gfn_to_gpa()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (49 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 50/52] KVM: MMU: Adjust page_header_update_slot() to accept a gfn instead of a gpa Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  2007-12-30  7:10 ` [PATCH 52/52] KVM: MMU: Simplify nonpaging_map() Avi Kivity
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Converting a frame number to an address is tricky since the data type changes
size.  Introduce a function to do it.  This fixes an actual bug when
accessing guest ptes.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h         |    4 ++++
 drivers/kvm/paging_tmpl.h |    4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 048849d..eda82cd 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -499,6 +499,10 @@ static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
 	return slot - kvm->memslots;
 }
 
+static inline gpa_t gfn_to_gpa(gfn_t gfn)
+{
+	return (gpa_t)gfn << PAGE_SHIFT;
+}
 
 enum kvm_stat_kind {
 	KVM_STAT_VM,
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index a3da98b..b24bc7c 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -110,7 +110,7 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
 		index = PT_INDEX(addr, walker->level);
 
 		table_gfn = gpte_to_gfn(pte);
-		pte_gpa = table_gfn << PAGE_SHIFT;
+		pte_gpa = gfn_to_gpa(table_gfn);
 		pte_gpa += index * sizeof(pt_element_t);
 		walker->table_gfn[walker->level - 1] = table_gfn;
 		pgprintk("%s: table_gfn[%d] %lx\n", __FUNCTION__,
@@ -442,7 +442,7 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
 	r = FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0);
 
 	if (r) {
-		gpa = (gpa_t)walker.gfn << PAGE_SHIFT;
+		gpa = gfn_to_gpa(walker.gfn);
 		gpa |= vaddr & ~PAGE_MASK;
 	}
 
-- 
1.5.3.7


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

* [PATCH 52/52] KVM: MMU: Simplify nonpaging_map()
  2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
                   ` (50 preceding siblings ...)
  2007-12-30  7:10 ` [PATCH 51/52] KVM: MMU: Introduce gfn_to_gpa() Avi Kivity
@ 2007-12-30  7:10 ` Avi Kivity
  51 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2007-12-30  7:10 UTC (permalink / raw)
  To: linux-kernel, kvm-devel

Instead of passing an hpa, pass a regular struct page.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/mmu.c |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 1dcffc4..1965185 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -903,13 +903,11 @@ static void nonpaging_new_cr3(struct kvm_vcpu *vcpu)
 {
 }
 
-static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
+static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, struct page *page)
 {
 	int level = PT32E_ROOT_LEVEL;
 	hpa_t table_addr = vcpu->mmu.root_hpa;
-	struct page *page;
 
-	page = pfn_to_page(p >> PAGE_SHIFT);
 	for (; ; level--) {
 		u32 index = PT64_INDEX(v, level);
 		u64 *table;
@@ -930,8 +928,9 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
 			mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT);
 			page_header_update_slot(vcpu->kvm, table,
 						v >> PAGE_SHIFT);
-			table[index] = p | PT_PRESENT_MASK | PT_WRITABLE_MASK |
-								PT_USER_MASK;
+			table[index] = page_to_phys(page)
+				| PT_PRESENT_MASK | PT_WRITABLE_MASK
+				| PT_USER_MASK;
 			if (!was_rmapped)
 				rmap_add(vcpu, &table[index], v >> PAGE_SHIFT);
 			else
@@ -1050,10 +1049,9 @@ static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr)
 }
 
 static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
-			       u32 error_code)
+				u32 error_code)
 {
-	gpa_t addr = gva;
-	hpa_t paddr;
+	struct page *page;
 	int r;
 
 	r = mmu_topup_memory_caches(vcpu);
@@ -1063,16 +1061,14 @@ static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
 	ASSERT(vcpu);
 	ASSERT(VALID_PAGE(vcpu->mmu.root_hpa));
 
+	page = gfn_to_page(vcpu->kvm, gva >> PAGE_SHIFT);
 
-	paddr = gpa_to_hpa(vcpu->kvm, addr & PT64_BASE_ADDR_MASK);
-
-	if (is_error_hpa(paddr)) {
-		kvm_release_page_clean(pfn_to_page((paddr & PT64_BASE_ADDR_MASK)
-				       >> PAGE_SHIFT));
+	if (is_error_page(page)) {
+		kvm_release_page_clean(page);
 		return 1;
 	}
 
-	return nonpaging_map(vcpu, addr & PAGE_MASK, paddr);
+	return nonpaging_map(vcpu, gva & PAGE_MASK, page);
 }
 
 static void nonpaging_free(struct kvm_vcpu *vcpu)
-- 
1.5.3.7


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

* Re: [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h>
  2007-12-30  7:10 ` [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h> Avi Kivity
@ 2008-01-03 18:14   ` Adrian Bunk
  2008-01-06  9:09     ` [kvm-devel] " Avi Kivity
  0 siblings, 1 reply; 55+ messages in thread
From: Adrian Bunk @ 2008-01-03 18:14 UTC (permalink / raw)
  To: Avi Kivity; +Cc: linux-kernel, kvm-devel

On Sun, Dec 30, 2007 at 09:10:06AM +0200, Avi Kivity wrote:
> Needed for empty_zero_page.
> 
> Signed-off-by: Avi Kivity <avi@qumranet.com>
> ---
>  drivers/kvm/kvm_main.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
> index 469e6b4..d6c5191 100644
> --- a/drivers/kvm/kvm_main.c
> +++ b/drivers/kvm/kvm_main.c
> @@ -46,6 +46,7 @@
>  #include <asm/io.h>
>  #include <asm/uaccess.h>
>  #include <asm/desc.h>
> +#include <asm/pgtable.h>
>  
>  MODULE_AUTHOR("Qumranet");
>  MODULE_LICENSE("GPL");

Can you merge this patch into the previous one for the final submission?

For being able to bisect (which has proven to be a very valuable help) 
we aim at having the tree between any two commits both compiling and 
working.

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

* Re: [kvm-devel] [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h>
  2008-01-03 18:14   ` Adrian Bunk
@ 2008-01-06  9:09     ` Avi Kivity
  0 siblings, 0 replies; 55+ messages in thread
From: Avi Kivity @ 2008-01-06  9:09 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: kvm-devel, linux-kernel

Adrian Bunk wrote:
> On Sun, Dec 30, 2007 at 09:10:06AM +0200, Avi Kivity wrote:
>   
>> Needed for empty_zero_page.
>>
>> Signed-off-by: Avi Kivity <avi@qumranet.com>
>> ---
>>  drivers/kvm/kvm_main.c |    1 +
>>  1 files changed, 1 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
>> index 469e6b4..d6c5191 100644
>> --- a/drivers/kvm/kvm_main.c
>> +++ b/drivers/kvm/kvm_main.c
>> @@ -46,6 +46,7 @@
>>  #include <asm/io.h>
>>  #include <asm/uaccess.h>
>>  #include <asm/desc.h>
>> +#include <asm/pgtable.h>
>>  
>>  MODULE_AUTHOR("Qumranet");
>>  MODULE_LICENSE("GPL");
>>     
>
> Can you merge this patch into the previous one for the final submission?
>
> For being able to bisect (which has proven to be a very valuable help) 
> we aim at having the tree between any two commits both compiling and 
> working.
>   

Certainly, I'll do that.


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


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

end of thread, other threads:[~2008-01-06  9:10 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
2007-12-30  7:09 ` [PATCH 01/52] KVM: Remove ptr comparisons to 0 Avi Kivity
2007-12-30  7:09 ` [PATCH 02/52] KVM: Remove __init attributes for kvm_init_debug and kvm_init_msr_list Avi Kivity
2007-12-30  7:09 ` [PATCH 03/52] KVM: Portability: Add two hooks to handle kvm_create and destroy vm Avi Kivity
2007-12-30  7:09 ` [PATCH 04/52] KVM: Replace 'light_exits' stat with 'host_state_reload' Avi Kivity
2007-12-30  7:09 ` [PATCH 05/52] KVM: Add fpu_reload counter Avi Kivity
2007-12-30  7:09 ` [PATCH 06/52] KVM: Add instruction emulation statistics Avi Kivity
2007-12-30  7:09 ` [PATCH 07/52] KVM: Extend stats support for VM stats Avi Kivity
2007-12-30  7:09 ` [PATCH 08/52] KVM: MMU: Add some mmu statistics Avi Kivity
2007-12-30  7:09 ` [PATCH 09/52] KVM: Make unloading of FPU state when putting vcpu arch-independent Avi Kivity
2007-12-30  7:09 ` [PATCH 10/52] KVM: Portability: Move kvm_vcpu_ioctl_get_dirty_log to arch-specific file Avi Kivity
2007-12-30  7:09 ` [PATCH 11/52] KVM: Portability: MMU initialization and teardown split Avi Kivity
2007-12-30  7:09 ` [PATCH 12/52] KVM: Portability: Move some macro definitions from kvm.h to x86.h Avi Kivity
2007-12-30  7:09 ` [PATCH 13/52] KVM: Portability: Move struct kvm_x86_ops definition " Avi Kivity
2007-12-30  7:10 ` [PATCH 14/52] KVM: Portability: Move vcpu regs enumeration " Avi Kivity
2007-12-30  7:10 ` [PATCH 15/52] KVM: Move some static inline functions out from kvm.h into x86.h Avi Kivity
2007-12-30  7:10 ` [PATCH 16/52] KVM: Portability: Move some function declarations to x86.h Avi Kivity
2007-12-30  7:10 ` [PATCH 17/52] KVM: VMX: Force seg.base == (seg.sel << 4) in real mode Avi Kivity
2007-12-30  7:10 ` [PATCH 18/52] KVM: MMU: Change guest pte access to kvm_{read,write}_guest() Avi Kivity
2007-12-30  7:10 ` [PATCH 19/52] KVM: Simplify kvm_clear_guest_page() Avi Kivity
2007-12-30  7:10 ` [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h> Avi Kivity
2008-01-03 18:14   ` Adrian Bunk
2008-01-06  9:09     ` [kvm-devel] " Avi Kivity
2007-12-30  7:10 ` [PATCH 21/52] KVM: MMU: Remove unused variable Avi Kivity
2007-12-30  7:10 ` [PATCH 22/52] KVM: Remove unused "rmap_overflow" variable Avi Kivity
2007-12-30  7:10 ` [PATCH 23/52] KVM: Correct consistent typo: "destory" -> "destroy" Avi Kivity
2007-12-30  7:10 ` [PATCH 24/52] KVM: Move misplaced comment Avi Kivity
2007-12-30  7:10 ` [PATCH 25/52] KVM: Portability: Move kvm_memory_alias to asm/kvm.h Avi Kivity
2007-12-30  7:10 ` [PATCH 26/52] KVM: Portability: Move x86 pic strutctures Avi Kivity
2007-12-30  7:10 ` [PATCH 27/52] KVM: Portability: Move kvm_regs to <asm/kvm.h> Avi Kivity
2007-12-30  7:10 ` [PATCH 28/52] KVM: Portability: Move structure lapic_state " Avi Kivity
2007-12-30  7:10 ` [PATCH 29/52] KVM: Portability: Move kvm_segment & kvm_dtable structure " Avi Kivity
2007-12-30  7:10 ` [PATCH 30/52] KVM: Portability: Move kvm_sregs and msr structures " Avi Kivity
2007-12-30  7:10 ` [PATCH 31/52] KVM: Portability: Move cpuid " Avi Kivity
2007-12-30  7:10 ` [PATCH 32/52] KVM: Export include/asm-x86/kvm.h Avi Kivity
2007-12-30  7:10 ` [PATCH 33/52] KVM: MMU: Fix potential memory leak with smp real-mode Avi Kivity
2007-12-30  7:10 ` [PATCH 34/52] KVM: MMU: Selectively set PageDirty when releasing guest memory Avi Kivity
2007-12-30  7:10 ` [PATCH 35/52] KVM: x86 emulator: retire ->write_std() Avi Kivity
2007-12-30  7:10 ` [PATCH 36/52] KVM: x86 emulator: prefetch up to 15 bytes of the instruction executed Avi Kivity
2007-12-30  7:10 ` [PATCH 37/52] KVM: Recalculate mmu pages needed for every memory region change Avi Kivity
2007-12-30  7:10 ` [PATCH 38/52] KVM: Portability: Split kvm_set_memory_region() to have an arch callout Avi Kivity
2007-12-30  7:10 ` [PATCH 39/52] KVM: Split vcpu creation to avoid vcpu_load() before preemption setup Avi Kivity
2007-12-30  7:10 ` [PATCH 40/52] KVM: MMU: Implement guest page fault bypass for nonpae Avi Kivity
2007-12-30  7:10 ` [PATCH 41/52] KVM: Add statistic for remote tlb flushes Avi Kivity
2007-12-30  7:10 ` [PATCH 42/52] KVM: MMU: Avoid unnecessary remote tlb flushes when guest updates a pte Avi Kivity
2007-12-30  7:10 ` [PATCH 43/52] KVM: Don't bother the mmu if cr3 load doesn't change cr3 Avi Kivity
2007-12-30  7:10 ` [PATCH 44/52] KVM: MMU: Code cleanup Avi Kivity
2007-12-30  7:10 ` [PATCH 45/52] KVM: MMU: Introduce and use gpte_to_gfn() Avi Kivity
2007-12-30  7:10 ` [PATCH 46/52] KVM: MMU: Move pse36 handling to the guest walker Avi Kivity
2007-12-30  7:10 ` [PATCH 47/52] KVM: MMU: Remove extra gaddr parameter from set_pte_common() Avi Kivity
2007-12-30  7:10 ` [PATCH 48/52] KVM: MMU: Remove set_pde() Avi Kivity
2007-12-30  7:10 ` [PATCH 49/52] KVM: MMU: Merge set_pte() and set_pte_common() Avi Kivity
2007-12-30  7:10 ` [PATCH 50/52] KVM: MMU: Adjust page_header_update_slot() to accept a gfn instead of a gpa Avi Kivity
2007-12-30  7:10 ` [PATCH 51/52] KVM: MMU: Introduce gfn_to_gpa() Avi Kivity
2007-12-30  7:10 ` [PATCH 52/52] KVM: MMU: Simplify nonpaging_map() Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).