public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] Handle vma regions with no backing page
@ 2008-06-03 11:17 Ben-Ami Yassour
  2008-06-03 11:39 ` Andrea Arcangeli
  2008-06-04  9:48 ` Avi Kivity
  0 siblings, 2 replies; 13+ messages in thread
From: Ben-Ami Yassour @ 2008-06-03 11:17 UTC (permalink / raw)
  To: aliguori
  Cc: Han Weidong, Kay, Allen M, Muli Ben-Yehuda, Amit Shah, andrea,
	kvm, avi

Anthony Liguori <aliguori@us.ibm.com> wrote on 04/29/2008 05:32:09 PM:

> Subject
>
> [PATCH] Handle vma regions with no backing page
>
> This patch allows VMA's that contain no backing page to be used for guest
> memory.  This is a drop-in replacement for Ben-Ami's first page in his direct
> mmio series.  Here, we continue to allow mmio pages to be represented in the
> rmap.

>  struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
>  {
> -   return pfn_to_page(gfn_to_pfn(kvm, gfn));
> +   pfn_t pfn;
> +
> +   pfn = gfn_to_pfn(kvm, gfn);
> +   if (pfn_valid(pfn))
> +      return pfn_to_page(pfn);
> +
> +   return NULL;
>  }

We noticed that pfn_valid does not always works as expected by this patch 
to indicate that a pfn has a backing page.
We have seen a case where CONFIG_NUMA was not set and then where pfn_valid 
returned 1 for an mmio pfn.
We then changed the config file with CONFIG_NUMA set and it worked fine as 
expected (since a different implementation of pfn_valid was used).

How should we overcome this issue?

Thanks,
Ben

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH] Handle vma regions with no backing page
@ 2008-04-29 14:32 Anthony Liguori
  2008-04-29 14:54 ` Andrea Arcangeli
  0 siblings, 1 reply; 13+ messages in thread
From: Anthony Liguori @ 2008-04-29 14:32 UTC (permalink / raw)
  To: kvm-devel; +Cc: Anthony Liguori, Andrea Arcangeli, Ben-Ami Yassour, Avi Kivity

This patch allows VMA's that contain no backing page to be used for guest
memory.  This is a drop-in replacement for Ben-Ami's first page in his direct
mmio series.  Here, we continue to allow mmio pages to be represented in the
rmap.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index f095b73..11b26f5 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -531,6 +531,7 @@ pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn)
 	struct page *page[1];
 	unsigned long addr;
 	int npages;
+	pfn_t pfn;
 
 	might_sleep();
 
@@ -543,19 +544,36 @@ pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn)
 	npages = get_user_pages(current, current->mm, addr, 1, 1, 1, page,
 				NULL);
 
-	if (npages != 1) {
-		get_page(bad_page);
-		return page_to_pfn(bad_page);
-	}
+	if (unlikely(npages != 1)) {
+		struct vm_area_struct *vma;
+
+		vma = find_vma(current->mm, addr);
+		if (vma == NULL) {
+			get_page(bad_page);
+			return page_to_pfn(bad_page);
+		}
+
+		BUG_ON(!(vma->vm_flags & VM_IO));
 
-	return page_to_pfn(page[0]);
+		pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
+		BUG_ON(pfn_valid(pfn));
+	} else
+		pfn = page_to_pfn(page[0]);
+
+	return pfn;
 }
 
 EXPORT_SYMBOL_GPL(gfn_to_pfn);
 
 struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
 {
-	return pfn_to_page(gfn_to_pfn(kvm, gfn));
+	pfn_t pfn;
+
+	pfn = gfn_to_pfn(kvm, gfn);
+	if (pfn_valid(pfn))
+		return pfn_to_page(pfn);
+
+	return NULL;
 }
 
 EXPORT_SYMBOL_GPL(gfn_to_page);
@@ -568,7 +586,8 @@ EXPORT_SYMBOL_GPL(kvm_release_page_clean);
 
 void kvm_release_pfn_clean(pfn_t pfn)
 {
-	put_page(pfn_to_page(pfn));
+	if (pfn_valid(pfn))
+		put_page(pfn_to_page(pfn));
 }
 EXPORT_SYMBOL_GPL(kvm_release_pfn_clean);
 
@@ -593,21 +612,25 @@ EXPORT_SYMBOL_GPL(kvm_set_page_dirty);
 
 void kvm_set_pfn_dirty(pfn_t pfn)
 {
-	struct page *page = pfn_to_page(pfn);
-	if (!PageReserved(page))
-		SetPageDirty(page);
+	if (pfn_valid(pfn)) {
+		struct page *page = pfn_to_page(pfn);
+		if (!PageReserved(page))
+			SetPageDirty(page);
+	}
 }
 EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty);
 
 void kvm_set_pfn_accessed(pfn_t pfn)
 {
-	mark_page_accessed(pfn_to_page(pfn));
+	if (pfn_valid(pfn))
+		mark_page_accessed(pfn_to_page(pfn));
 }
 EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed);
 
 void kvm_get_pfn(pfn_t pfn)
 {
-	get_page(pfn_to_page(pfn));
+	if (pfn_valid(pfn))
+		get_page(pfn_to_page(pfn));
 }
 EXPORT_SYMBOL_GPL(kvm_get_pfn);
 

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

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

end of thread, other threads:[~2008-06-04 19:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-03 11:17 [PATCH] Handle vma regions with no backing page Ben-Ami Yassour
2008-06-03 11:39 ` Andrea Arcangeli
2008-06-04 15:09   ` Ben-Ami Yassour
2008-06-04 16:17     ` Muli Ben-Yehuda
2008-06-04 19:34       ` Andrea Arcangeli
2008-06-04 19:41         ` Anthony Liguori
2008-06-04 19:51           ` Andrea Arcangeli
2008-06-04 19:59             ` Dave Hansen
2008-06-04  9:48 ` Avi Kivity
2008-06-04 16:48   ` Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2008-04-29 14:32 Anthony Liguori
2008-04-29 14:54 ` Andrea Arcangeli
2008-04-29 15:14   ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox