Skip to content

Commit 09bf649

Browse files
robclarkmartinezjavier
authored andcommitted
drm/shmem-helper: Avoid vm_open error paths
vm_open() is not allowed to fail. Fortunately we are guaranteed that the pages are already pinned, thanks to the initial mmap which is now being cloned into a forked process, and only need to increment the refcnt. So just increment it directly. Previously if a signal was delivered at the wrong time to the forking process, the mutex_lock_interruptible() could fail resulting in the pages_use_count not being incremented. Fixes: 2194a63 ("drm: Add library for shmem backed GEM objects") Cc: stable@vger.kernel.org Signed-off-by: Rob Clark <robdclark@chromium.org> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20221130185748.357410-3-robdclark@gmail.com
1 parent 2401331 commit 09bf649

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/gpu/drm/drm_gem_shmem_helper.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,20 @@ static void drm_gem_shmem_vm_open(struct vm_area_struct *vma)
571571
{
572572
struct drm_gem_object *obj = vma->vm_private_data;
573573
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
574-
int ret;
575574

576575
WARN_ON(shmem->base.import_attach);
577576

578-
ret = drm_gem_shmem_get_pages(shmem);
579-
WARN_ON_ONCE(ret != 0);
577+
mutex_lock(&shmem->pages_lock);
578+
579+
/*
580+
* We should have already pinned the pages when the buffer was first
581+
* mmap'd, vm_open() just grabs an additional reference for the new
582+
* mm the vma is getting copied into (ie. on fork()).
583+
*/
584+
if (!WARN_ON_ONCE(!shmem->pages_use_count))
585+
shmem->pages_use_count++;
586+
587+
mutex_unlock(&shmem->pages_lock);
580588

581589
drm_gem_vm_open(vma);
582590
}

0 commit comments

Comments
 (0)