Commit 83b8a6f2 authored by Rob Herring's avatar Rob Herring

drm/gem: Fix mmap fake offset handling for drm_gem_object_funcs.mmap

Commit c40069cb ("drm: add mmap() to drm_gem_object_funcs")
introduced a GEM object mmap() hook which is expected to subtract the
fake offset from vm_pgoff. However, for mmap() on dmabufs, there is not
a fake offset.

To fix this, let's always call mmap() object callback with an offset of 0,
and leave it up to drm_gem_mmap_obj() to remove the fake offset.

TTM still needs the fake offset, so we have to add it back until that's
fixed.

Fixes: c40069cb ("drm: add mmap() to drm_gem_object_funcs")
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
Acked-by: default avatarGerd Hoffmann <kraxel@redhat.com>
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20191024191859.31700-1-robh@kernel.org
parent 9e62b885
...@@ -1106,6 +1106,9 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, ...@@ -1106,6 +1106,9 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
return -EINVAL; return -EINVAL;
if (obj->funcs && obj->funcs->mmap) { if (obj->funcs && obj->funcs->mmap) {
/* Remove the fake offset */
vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
ret = obj->funcs->mmap(obj, vma); ret = obj->funcs->mmap(obj, vma);
if (ret) if (ret)
return ret; return ret;
......
...@@ -541,9 +541,6 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) ...@@ -541,9 +541,6 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
vma->vm_ops = &drm_gem_shmem_vm_ops; vma->vm_ops = &drm_gem_shmem_vm_ops;
/* Remove the fake offset */
vma->vm_pgoff -= drm_vma_node_start(&shmem->base.vma_node);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(drm_gem_shmem_mmap); EXPORT_SYMBOL_GPL(drm_gem_shmem_mmap);
......
...@@ -480,6 +480,13 @@ EXPORT_SYMBOL(ttm_bo_mmap); ...@@ -480,6 +480,13 @@ EXPORT_SYMBOL(ttm_bo_mmap);
int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo) int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
{ {
ttm_bo_get(bo); ttm_bo_get(bo);
/*
* FIXME: &drm_gem_object_funcs.mmap is called with the fake offset
* removed. Add it back here until the rest of TTM works without it.
*/
vma->vm_pgoff += drm_vma_node_start(&bo->base.vma_node);
ttm_bo_mmap_vma_setup(bo, vma); ttm_bo_mmap_vma_setup(bo, vma);
return 0; return 0;
} }
......
...@@ -159,8 +159,9 @@ struct drm_gem_object_funcs { ...@@ -159,8 +159,9 @@ struct drm_gem_object_funcs {
* *
* The callback is used by by both drm_gem_mmap_obj() and * The callback is used by by both drm_gem_mmap_obj() and
* drm_gem_prime_mmap(). When @mmap is present @vm_ops is not * drm_gem_prime_mmap(). When @mmap is present @vm_ops is not
* used, the @mmap callback must set vma->vm_ops instead. * used, the @mmap callback must set vma->vm_ops instead. The @mmap
* * callback is always called with a 0 offset. The caller will remove
* the fake offset as necessary.
*/ */
int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma); int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment