| 
     
      
      
      From: Muli Ben-Y. <mu...@il...> - 2008-04-30 06:09:16
      
     
   | 
On Tue, Apr 29, 2008 at 02:09:20PM -0500, Anthony Liguori wrote:
> 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.
> 
> Since v1, I've taken into account Andrea's suggestions at using VM_PFNMAP
> instead of VM_IO and changed the BUG_ON to a return of bad_page.
> 
> Signed-off-by: Anthony Liguori <ali...@us...>
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 1d7991a..64e5efe 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -532,6 +532,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();
>  
> @@ -544,19 +545,35 @@ 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;
>  
> -	return page_to_pfn(page[0]);
> +		vma = find_vma(current->mm, addr);
> +		if (vma == NULL || addr >= vma->vm_start ||
> +		    !(vma->vm_flags & VM_PFNMAP)) {
Isn't the check for addr backwards here? For the VMA we would like to
to find, vma->vm_start <= addr < vma->vm_end.
Cheers,
Muli
 |