Commit 47d35c1c authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm: Set vm_ops to GEM object's values during mmap

The GEM mmap code relies on the GEM object's mmap callback to set the
VMA's vm_ops field. This is easily forgotten and already led to a memory
leak in the CMA helpers. Instead set the vm_ops field in the DRM core
code to the GEM object's value. Drivers with different needs can override
this in their mmap callback.

v2:
	* support (vm_ops == NULL) if mmap is given; required by VRAM
	  helpers
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Fixes: f5ca8eb6 ("drm/cma-helper: Implement mmap as GEM CMA object functions")
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Reported-by: default avatarKieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Tested-by: default avatarKieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Eric Anholt <eric@anholt.net>
Cc: dri-devel@lists.freedesktop.org
Link: https://patchwork.freedesktop.org/patch/msgid/20210115093038.10345-1-tzimmermann@suse.de
parent 85dd1dd6
...@@ -1068,20 +1068,17 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, ...@@ -1068,20 +1068,17 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
drm_gem_object_get(obj); drm_gem_object_get(obj);
vma->vm_private_data = obj; vma->vm_private_data = obj;
vma->vm_ops = obj->funcs->vm_ops;
if (obj->funcs->mmap) { if (obj->funcs->mmap) {
ret = obj->funcs->mmap(obj, vma); ret = obj->funcs->mmap(obj, vma);
if (ret) { if (ret)
drm_gem_object_put(obj); goto err_drm_gem_object_put;
return ret;
}
WARN_ON(!(vma->vm_flags & VM_DONTEXPAND)); WARN_ON(!(vma->vm_flags & VM_DONTEXPAND));
} else { } else {
if (obj->funcs->vm_ops) if (!vma->vm_ops) {
vma->vm_ops = obj->funcs->vm_ops; ret = -EINVAL;
else { goto err_drm_gem_object_put;
drm_gem_object_put(obj);
return -EINVAL;
} }
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
...@@ -1090,6 +1087,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, ...@@ -1090,6 +1087,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
} }
return 0; return 0;
err_drm_gem_object_put:
drm_gem_object_put(obj);
return ret;
} }
EXPORT_SYMBOL(drm_gem_mmap_obj); EXPORT_SYMBOL(drm_gem_mmap_obj);
......
...@@ -717,6 +717,8 @@ int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) ...@@ -717,6 +717,8 @@ int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
vma->vm_pgoff += drm_vma_node_start(&obj->vma_node); vma->vm_pgoff += drm_vma_node_start(&obj->vma_node);
if (obj->funcs && obj->funcs->mmap) { if (obj->funcs && obj->funcs->mmap) {
vma->vm_ops = obj->funcs->vm_ops;
ret = obj->funcs->mmap(obj, vma); ret = obj->funcs->mmap(obj, vma);
if (ret) if (ret)
return ret; return ret;
......
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