drm/exynos: call find_vma with the mmap_sem held
authorJonathan Gonzalez V <zeus@gnu.org>
Wed, 4 Jun 2014 23:07:30 +0000 (16:07 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Jun 2014 23:54:00 +0000 (16:54 -0700)
Performing vma lookups without taking the mm->mmap_sem is asking for
trouble.  While doing the search, the vma in question can be modified or
even removed before returning to the caller.  Take the lock (exclusively)
in order to avoid races while iterating through the vmacache and/or
rbtree.

Signed-off-by: Jonathan Gonzalez V <zeus@gnu.org>
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Joonyoung Shim <jy0922.shim@samsung.com>
Cc: David Airlie <airlied@linux.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/gpu/drm/exynos/exynos_drm_g2d.c

index 6c1885e..8001587 100644 (file)
@@ -467,14 +467,17 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct drm_device *drm_dev,
                goto err_free;
        }
 
+       down_read(&current->mm->mmap_sem);
        vma = find_vma(current->mm, userptr);
        if (!vma) {
+               up_read(&current->mm->mmap_sem);
                DRM_ERROR("failed to get vm region.\n");
                ret = -EFAULT;
                goto err_free_pages;
        }
 
        if (vma->vm_end < userptr + size) {
+               up_read(&current->mm->mmap_sem);
                DRM_ERROR("vma is too small.\n");
                ret = -EFAULT;
                goto err_free_pages;
@@ -482,6 +485,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct drm_device *drm_dev,
 
        g2d_userptr->vma = exynos_gem_get_vma(vma);
        if (!g2d_userptr->vma) {
+               up_read(&current->mm->mmap_sem);
                DRM_ERROR("failed to copy vma.\n");
                ret = -ENOMEM;
                goto err_free_pages;
@@ -492,10 +496,12 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct drm_device *drm_dev,
        ret = exynos_gem_get_pages_from_userptr(start & PAGE_MASK,
                                                npages, pages, vma);
        if (ret < 0) {
+               up_read(&current->mm->mmap_sem);
                DRM_ERROR("failed to get user pages from userptr.\n");
                goto err_put_vma;
        }
 
+       up_read(&current->mm->mmap_sem);
        g2d_userptr->pages = pages;
 
        sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);