drm/radeon: add userptr flag to limit it to anonymous memory v2
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / radeon / radeon_ttm.c
index b20933fa35c647b4a22a2016eaa910a2bf245d0a..12e37b1ddc4004b5948d7d91d8af43b8c47c9107 100644 (file)
@@ -538,6 +538,16 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm)
        if (current->mm != gtt->usermm)
                return -EPERM;
 
+       if (gtt->userflags & RADEON_GEM_USERPTR_ANONONLY) {
+               /* check that we only pin down anonymous memory
+                  to prevent problems with writeback */
+               unsigned long end = gtt->userptr + ttm->num_pages * PAGE_SIZE;
+               struct vm_area_struct *vma;
+               vma = find_vma(gtt->usermm, gtt->userptr);
+               if (!vma || vma->vm_file || vma->vm_end < end)
+                       return -EPERM;
+       }
+
        do {
                unsigned num_pages = ttm->num_pages - pinned;
                uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;