kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] KVM: fix fault page leak
@ 2012-07-03  6:31 Xiao Guangrong
  2012-07-03  6:31 ` [PATCH 2/3] KVM: MMU: fix shrinking page from the empty mmu Xiao Guangrong
  2012-07-03  6:32 ` [PATCH 3/3] KVM: MMU: track the refcount when unmap the page Xiao Guangrong
  0 siblings, 2 replies; 4+ messages in thread
From: Xiao Guangrong @ 2012-07-03  6:31 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, LKML, KVM

fault_page is forgot to be freed

Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
---
 virt/kvm/kvm_main.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 02cb440..157226d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2857,6 +2857,7 @@ void kvm_exit(void)
 	kvm_arch_hardware_unsetup();
 	kvm_arch_exit();
 	free_cpumask_var(cpus_hardware_enabled);
+	__free_page(fault_page);
 	__free_page(hwpoison_page);
 	__free_page(bad_page);
 }
-- 
1.7.7.6

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

* [PATCH 2/3] KVM: MMU: fix shrinking page from the empty mmu
  2012-07-03  6:31 [PATCH 1/3] KVM: fix fault page leak Xiao Guangrong
@ 2012-07-03  6:31 ` Xiao Guangrong
  2012-07-03  6:32 ` [PATCH 3/3] KVM: MMU: track the refcount when unmap the page Xiao Guangrong
  1 sibling, 0 replies; 4+ messages in thread
From: Xiao Guangrong @ 2012-07-03  6:31 UTC (permalink / raw)
  To: Xiao Guangrong; +Cc: Avi Kivity, Marcelo Tosatti, LKML, KVM

Fix:

 [ 3190.059226] BUG: unable to handle kernel NULL pointer dereference at           (null)
 [ 3190.062224] IP: [<ffffffffa02aac66>] mmu_page_zap_pte+0x10/0xa7 [kvm]
 [ 3190.063760] PGD 104f50067 PUD 112bea067 PMD 0
 [ 3190.065309] Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
 [ 3190.066860] CPU 1
[ ...... ]
 [ 3190.109629] Call Trace:
 [ 3190.111342]  [<ffffffffa02aada6>] kvm_mmu_prepare_zap_page+0xa9/0x1fc [kvm]
 [ 3190.113091]  [<ffffffffa02ab2f5>] mmu_shrink+0x11f/0x1f3 [kvm]
 [ 3190.114844]  [<ffffffffa02ab25d>] ? mmu_shrink+0x87/0x1f3 [kvm]
 [ 3190.116598]  [<ffffffff81150c9d>] ? prune_super+0x142/0x154
 [ 3190.118333]  [<ffffffff8110a4f4>] ? shrink_slab+0x39/0x31e
 [ 3190.120043]  [<ffffffff8110a687>] shrink_slab+0x1cc/0x31e
 [ 3190.121718]  [<ffffffff8110ca1d>] do_try_to_free_pages

This is caused by shrinking page from the empty mmu, although we have
checked n_used_mmu_pages, it is useless since the check is out of mmu-lock

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

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 24dd43d..cac3408 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3936,6 +3936,9 @@ static void kvm_mmu_remove_some_alloc_mmu_pages(struct kvm *kvm,
 {
 	struct kvm_mmu_page *page;

+	if (list_empty(&kvm->arch.active_mmu_pages))
+		return;
+
 	page = container_of(kvm->arch.active_mmu_pages.prev,
 			    struct kvm_mmu_page, link);
 	kvm_mmu_prepare_zap_page(kvm, page, invalid_list);
-- 
1.7.7.6

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

* [PATCH 3/3] KVM: MMU: track the refcount when unmap the page
  2012-07-03  6:31 [PATCH 1/3] KVM: fix fault page leak Xiao Guangrong
  2012-07-03  6:31 ` [PATCH 2/3] KVM: MMU: fix shrinking page from the empty mmu Xiao Guangrong
@ 2012-07-03  6:32 ` Xiao Guangrong
  2012-07-03 20:30   ` Marcelo Tosatti
  1 sibling, 1 reply; 4+ messages in thread
From: Xiao Guangrong @ 2012-07-03  6:32 UTC (permalink / raw)
  To: Xiao Guangrong; +Cc: Avi Kivity, Marcelo Tosatti, LKML, KVM

It will trigger a WARN_ON if the page has been freed but it is still
used in mmu, it can help us to detect mm bug early

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

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index cac3408..af7e076 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -527,6 +527,14 @@ static int mmu_spte_clear_track_bits(u64 *sptep)
 		return 0;

 	pfn = spte_to_pfn(old_spte);
+
+	/*
+	 * KVM does not hold the refcount of the page used by
+	 * kvm mmu, before reclaiming the page, we should
+	 * unmap it from mmu first.
+	 */
+	WARN_ON(!page_count(pfn_to_page(pfn)));
+
 	if (!shadow_accessed_mask || old_spte & shadow_accessed_mask)
 		kvm_set_pfn_accessed(pfn);
 	if (!shadow_dirty_mask || (old_spte & shadow_dirty_mask))
-- 
1.7.7.6

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

* Re: [PATCH 3/3] KVM: MMU: track the refcount when unmap the page
  2012-07-03  6:32 ` [PATCH 3/3] KVM: MMU: track the refcount when unmap the page Xiao Guangrong
@ 2012-07-03 20:30   ` Marcelo Tosatti
  0 siblings, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2012-07-03 20:30 UTC (permalink / raw)
  To: Xiao Guangrong; +Cc: Avi Kivity, LKML, KVM

On Tue, Jul 03, 2012 at 02:32:14PM +0800, Xiao Guangrong wrote:
> It will trigger a WARN_ON if the page has been freed but it is still
> used in mmu, it can help us to detect mm bug early
> 
> Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
> ---
>  arch/x86/kvm/mmu.c |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index cac3408..af7e076 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -527,6 +527,14 @@ static int mmu_spte_clear_track_bits(u64 *sptep)
>  		return 0;
> 
>  	pfn = spte_to_pfn(old_spte);
> +
> +	/*
> +	 * KVM does not hold the refcount of the page used by
> +	 * kvm mmu, before reclaiming the page, we should
> +	 * unmap it from mmu first.
> +	 */
> +	WARN_ON(!page_count(pfn_to_page(pfn)));
> +

Except for mmio pfns.

Applied patch 1 and 2 to master, thanks.

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

end of thread, other threads:[~2012-07-03 20:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-03  6:31 [PATCH 1/3] KVM: fix fault page leak Xiao Guangrong
2012-07-03  6:31 ` [PATCH 2/3] KVM: MMU: fix shrinking page from the empty mmu Xiao Guangrong
2012-07-03  6:32 ` [PATCH 3/3] KVM: MMU: track the refcount when unmap the page Xiao Guangrong
2012-07-03 20:30   ` 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).