Skip to content

Commit

Permalink
drm: call drm_gem_object_funcs.mmap with fake offset
Browse files Browse the repository at this point in the history
The fake offset is going to stay, so change the calling convention for
drm_gem_object_funcs.mmap to include the fake offset.  Update all users
accordingly.

Note that this reverts 83b8a6f ("drm/gem: Fix mmap fake offset
handling for drm_gem_object_funcs.mmap") and on top then adds the fake
offset to  drm_gem_prime_mmap to make sure all paths leading to
obj->funcs->mmap are consistent.

v3: move fake-offset tweak in drm_gem_prime_mmap() so we have this code
    only once in the function (Rob Herring).

Fixes: 83b8a6f ("drm/gem: Fix mmap fake offset handling for drm_gem_object_funcs.mmap")
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Rob Herring <robh@kernel.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20191127092523.5620-2-kraxel@redhat.com
  • Loading branch information
Gerd Hoffmann committed Dec 6, 2019
1 parent 3f5f742 commit e551655
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 15 deletions.
3 changes: 0 additions & 3 deletions drivers/gpu/drm/drm_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,6 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
return -EINVAL;

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);
if (ret)
return ret;
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/drm_gem_shmem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
struct drm_gem_shmem_object *shmem;
int ret;

/* Remove the fake offset */
vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);

shmem = to_drm_gem_shmem_obj(obj);

ret = drm_gem_shmem_get_pages(shmem);
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/drm_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
struct file *fil;
int ret;

/* Add the fake offset */
vma->vm_pgoff += drm_vma_node_start(&obj->vma_node);

if (obj->funcs && obj->funcs->mmap) {
ret = obj->funcs->mmap(obj, vma);
if (ret)
Expand All @@ -737,8 +740,6 @@ int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
if (ret)
goto out;

vma->vm_pgoff += drm_vma_node_start(&obj->vma_node);

ret = obj->dev->driver->fops->mmap(fil, vma);

drm_vma_node_revoke(&obj->vma_node, priv);
Expand Down
7 changes: 0 additions & 7 deletions drivers/gpu/drm/ttm/ttm_bo_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,6 @@ EXPORT_SYMBOL(ttm_bo_mmap);
int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *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);
return 0;
}
Expand Down
4 changes: 1 addition & 3 deletions include/drm/drm_gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ struct drm_gem_object_funcs {
*
* The callback is used by by both drm_gem_mmap_obj() and
* drm_gem_prime_mmap(). When @mmap is present @vm_ops is not
* 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.
* used, the @mmap callback must set vma->vm_ops instead.
*/
int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);

Expand Down

0 comments on commit e551655

Please sign in to comment.