kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] KVM MMU: fix objects free
@ 2010-05-13  2:06 Xiao Guangrong
  2010-05-13  2:07 ` [PATCH 2/5] KVM MMU: remove rmap before clear spte Xiao Guangrong
  2010-05-14 22:50 ` [PATCH 1/5] KVM MMU: fix objects free Marcelo Tosatti
  0 siblings, 2 replies; 6+ messages in thread
From: Xiao Guangrong @ 2010-05-13  2:06 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, KVM list, LKML

Where to alloc, where to free

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 arch/x86/kvm/mmu.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 604eb3f..67da751 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -304,10 +304,11 @@ static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
 	return 0;
 }
 
-static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc)
+static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc,
+				  struct kmem_cache *cache)
 {
 	while (mc->nobjs)
-		kfree(mc->objects[--mc->nobjs]);
+		kmem_cache_free(cache, mc->objects[--mc->nobjs]);
 }
 
 static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache,
@@ -355,10 +356,11 @@ out:
 
 static void mmu_free_memory_caches(struct kvm_vcpu *vcpu)
 {
-	mmu_free_memory_cache(&vcpu->arch.mmu_pte_chain_cache);
-	mmu_free_memory_cache(&vcpu->arch.mmu_rmap_desc_cache);
+	mmu_free_memory_cache(&vcpu->arch.mmu_pte_chain_cache, pte_chain_cache);
+	mmu_free_memory_cache(&vcpu->arch.mmu_rmap_desc_cache, rmap_desc_cache);
 	mmu_free_memory_cache_page(&vcpu->arch.mmu_page_cache);
-	mmu_free_memory_cache(&vcpu->arch.mmu_page_header_cache);
+	mmu_free_memory_cache(&vcpu->arch.mmu_page_header_cache,
+				mmu_page_header_cache);
 }
 
 static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc,
@@ -379,7 +381,7 @@ static struct kvm_pte_chain *mmu_alloc_pte_chain(struct kvm_vcpu *vcpu)
 
 static void mmu_free_pte_chain(struct kvm_pte_chain *pc)
 {
-	kfree(pc);
+	kmem_cache_free(pte_chain_cache, pc);
 }
 
 static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu)
@@ -390,7 +392,7 @@ static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu)
 
 static void mmu_free_rmap_desc(struct kvm_rmap_desc *rd)
 {
-	kfree(rd);
+	kmem_cache_free(rmap_desc_cache, rd);
 }
 
 /*
@@ -897,7 +899,7 @@ static void kvm_mmu_free_page(struct kvm *kvm, struct kvm_mmu_page *sp)
 	list_del(&sp->link);
 	__free_page(virt_to_page(sp->spt));
 	__free_page(virt_to_page(sp->gfns));
-	kfree(sp);
+	kmem_cache_free(mmu_page_header_cache, sp);
 	++kvm->arch.n_free_mmu_pages;
 }
 
-- 
1.6.1.2

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

* [PATCH 2/5] KVM MMU: remove rmap before clear spte
  2010-05-13  2:06 [PATCH 1/5] KVM MMU: fix objects free Xiao Guangrong
@ 2010-05-13  2:07 ` Xiao Guangrong
  2010-05-13  2:08   ` [PATCH 3/5] KVM MMU: fix for got gfn when sync shadow pages Xiao Guangrong
  2010-05-14 22:50 ` [PATCH 1/5] KVM MMU: fix objects free Marcelo Tosatti
  1 sibling, 1 reply; 6+ messages in thread
From: Xiao Guangrong @ 2010-05-13  2:07 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, KVM list, LKML

Remove rmap before clear spte otherwise it will trigger BUG_ON() in
some functions such as rmap_write_protect()

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 arch/x86/kvm/mmu.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 67da751..a474d93 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1812,6 +1812,7 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
 		if (level > PT_PAGE_TABLE_LEVEL &&
 		    has_wrprotected_page(vcpu->kvm, gfn, level)) {
 			ret = 1;
+			rmap_remove(vcpu->kvm, sptep);
 			spte = shadow_trap_nonpresent_pte;
 			goto set_pte;
 		}
-- 
1.6.1.2



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

* [PATCH 3/5] KVM MMU: fix for got gfn when sync shadow pages
  2010-05-13  2:07 ` [PATCH 2/5] KVM MMU: remove rmap before clear spte Xiao Guangrong
@ 2010-05-13  2:08   ` Xiao Guangrong
  2010-05-13  2:08     ` [PATCH 4/5] KVM MMU: fix two typos Xiao Guangrong
  0 siblings, 1 reply; 6+ messages in thread
From: Xiao Guangrong @ 2010-05-13  2:08 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, KVM list, LKML

sp->gfns[] are not mapping gfn since it has cooked by unalias_gfn()

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 arch/x86/kvm/paging_tmpl.h |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 11d8a16..71c73fe 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -588,7 +588,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
 		unsigned pte_access;
 		pt_element_t gpte;
 		gpa_t pte_gpa;
-		gfn_t gfn = sp->gfns[i];
+		gfn_t gfn;
 
 		if (!is_shadow_present_pte(sp->spt[i]))
 			continue;
@@ -599,8 +599,9 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
 					  sizeof(pt_element_t)))
 			return -EINVAL;
 
-		if (gpte_to_gfn(gpte) != gfn || !is_present_gpte(gpte) ||
-		    !(gpte & PT_ACCESSED_MASK)) {
+		gfn = gpte_to_gfn(gpte);
+		if (unalias_gfn(vcpu->kvm, gfn) != sp->gfns[i] ||
+		      !is_present_gpte(gpte) || !(gpte & PT_ACCESSED_MASK)) {
 			u64 nonpresent;
 
 			rmap_remove(vcpu->kvm, &sp->spt[i]);
-- 
1.6.1.2



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

* [PATCH 4/5] KVM MMU: fix two typos
  2010-05-13  2:08   ` [PATCH 3/5] KVM MMU: fix for got gfn when sync shadow pages Xiao Guangrong
@ 2010-05-13  2:08     ` Xiao Guangrong
  2010-05-13  2:09       ` [PATCH 5/5] KVM x86: cleanup unused local variable Xiao Guangrong
  0 siblings, 1 reply; 6+ messages in thread
From: Xiao Guangrong @ 2010-05-13  2:08 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, KVM list, LKML

fix two typos in next branch

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 arch/x86/kvm/mmu.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index a474d93..68f79b0 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2070,7 +2070,7 @@ static int mmu_alloc_roots(struct kvm_vcpu *vcpu)
 			root_gfn = 0;
 		}
 		spin_lock(&vcpu->kvm->mmu_lock);
-		kvm_mmu_free_some_pages(vcpu->kvm);
+		kvm_mmu_free_some_pages(vcpu);
 		sp = kvm_mmu_get_page(vcpu, root_gfn, 0,
 				      PT64_ROOT_LEVEL, direct,
 				      ACC_ALL, NULL);
@@ -2101,7 +2101,7 @@ static int mmu_alloc_roots(struct kvm_vcpu *vcpu)
 			root_gfn = i << 30;
 		}
 		spin_lock(&vcpu->kvm->mmu_lock);
-		kvm_mmu_free_some_pages(vcpu->kvm);
+		kvm_mmu_free_some_pages(vcpu);
 		sp = kvm_mmu_get_page(vcpu, root_gfn, i << 30,
 				      PT32_ROOT_LEVEL, direct,
 				      ACC_ALL, NULL);
-- 
1.6.1.2

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

* [PATCH 5/5] KVM x86: cleanup unused local variable
  2010-05-13  2:08     ` [PATCH 4/5] KVM MMU: fix two typos Xiao Guangrong
@ 2010-05-13  2:09       ` Xiao Guangrong
  0 siblings, 0 replies; 6+ messages in thread
From: Xiao Guangrong @ 2010-05-13  2:09 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, KVM list, LKML

fix:
 arch/x86/kvm/x86.c: In function ‘handle_emulation_failure’:
 arch/x86/kvm/x86.c:3844: warning: unused variable ‘ctxt’

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 arch/x86/kvm/x86.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4b1433f..23a7716 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3841,8 +3841,6 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu)
 
 static int handle_emulation_failure(struct kvm_vcpu *vcpu)
 {
-	struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
-
 	++vcpu->stat.insn_emulation_fail;
 	trace_kvm_emulate_insn_failed(vcpu);
 	vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
-- 
1.6.1.2

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

* Re: [PATCH 1/5] KVM MMU: fix objects free
  2010-05-13  2:06 [PATCH 1/5] KVM MMU: fix objects free Xiao Guangrong
  2010-05-13  2:07 ` [PATCH 2/5] KVM MMU: remove rmap before clear spte Xiao Guangrong
@ 2010-05-14 22:50 ` Marcelo Tosatti
  1 sibling, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2010-05-14 22:50 UTC (permalink / raw)
  To: Xiao Guangrong; +Cc: Avi Kivity, KVM list, LKML

On Thu, May 13, 2010 at 10:06:02AM +0800, Xiao Guangrong wrote:
> Where to alloc, where to free
> 
> Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
> ---
>  arch/x86/kvm/mmu.c |   18 ++++++++++--------
>  1 files changed, 10 insertions(+), 8 deletions(-)

Applied all (4 was already fixed), thanks.

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

end of thread, other threads:[~2010-05-14 22:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-13  2:06 [PATCH 1/5] KVM MMU: fix objects free Xiao Guangrong
2010-05-13  2:07 ` [PATCH 2/5] KVM MMU: remove rmap before clear spte Xiao Guangrong
2010-05-13  2:08   ` [PATCH 3/5] KVM MMU: fix for got gfn when sync shadow pages Xiao Guangrong
2010-05-13  2:08     ` [PATCH 4/5] KVM MMU: fix two typos Xiao Guangrong
2010-05-13  2:09       ` [PATCH 5/5] KVM x86: cleanup unused local variable Xiao Guangrong
2010-05-14 22:50 ` [PATCH 1/5] KVM MMU: fix objects free Marcelo Tosatti

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).