From: David Vrabel Subject: [PATCH 14/14] xen/gntdev: provide find_page VMA operation Date: Mon, 12 Jan 2015 15:43:37 +0000 Message-ID: <1421077417-7162-15-git-send-email-david.vrabel@citrix.com> References: <1421077417-7162-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YAhaL-0005SQ-BW for xen-devel@lists.xenproject.org; Mon, 12 Jan 2015 16:11:21 +0000 In-Reply-To: <1421077417-7162-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Boris Ostrovsky , David Vrabel List-Id: xen-devel@lists.xenproject.org For a PV guest, use the find_page op to find the right page. To handle VMAs being split, remember the start of the original VMA so the correct index in the pages array can be calculated. Signed-off-by: David Vrabel --- drivers/xen/gntdev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 8ea10eb..2507675 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -93,6 +93,7 @@ struct grant_map { struct gnttab_map_grant_ref *kmap_ops; struct gnttab_unmap_grant_ref *kunmap_ops; struct page **pages; + unsigned long pages_vm_start; }; static int unmap_grant_pages(struct grant_map *map, int offset, int pages); @@ -444,9 +445,18 @@ static void gntdev_vma_close(struct vm_area_struct *vma) gntdev_put_map(priv, map); } +static struct page *gntdev_vma_find_page(struct vm_area_struct *vma, + unsigned long addr) +{ + struct grant_map *map = vma->vm_private_data; + + return map->pages[(addr - map->pages_vm_start) >> PAGE_SHIFT]; +} + static struct vm_operations_struct gntdev_vmops = { .open = gntdev_vma_open, .close = gntdev_vma_close, + .find_page = gntdev_vma_find_page, }; /* ------------------------------------------------------------------ */ @@ -870,6 +880,8 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) vma->vm_end - vma->vm_start, set_grant_ptes_as_special, NULL); } + + map->pages_vm_start = vma->vm_start; } return 0; -- 1.7.10.4