drm/i915/userptr: Hold mmref whilst calling get-user-pages

Holding a reference to the containing task_struct is not sufficient to
prevent the mm_struct from being reaped under memory pressure. If this
happens whilst we are calling get_user_pages(), explosions erupt -
sometimes an immediate GPF, sometimes page flag corruption. To prevent
the target mm from being reaped as we are reading from it, acquire a
reference before we begin.

Testcase: igt/gem_shrink/*userptr
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: stable@vger.kernel.org
Reviewed-by: Michał Winiarski <michal.winiarski@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1459864801-28606-2-git-send-email-chris@chris-wilson.co.uk
(cherry picked from commit 40313f0cd0)
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
This commit is contained in:
Chris Wilson 2016-04-05 15:00:00 +01:00 committed by Jani Nikula
parent d43f3ebf12
commit db9f9203e2
1 changed files with 16 additions and 11 deletions

View File

@ -501,19 +501,24 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)
if (pvec != NULL) { if (pvec != NULL) {
struct mm_struct *mm = obj->userptr.mm->mm; struct mm_struct *mm = obj->userptr.mm->mm;
down_read(&mm->mmap_sem); ret = -EFAULT;
while (pinned < npages) { if (atomic_inc_not_zero(&mm->mm_users)) {
ret = get_user_pages_remote(work->task, mm, down_read(&mm->mmap_sem);
obj->userptr.ptr + pinned * PAGE_SIZE, while (pinned < npages) {
npages - pinned, ret = get_user_pages_remote
!obj->userptr.read_only, 0, (work->task, mm,
pvec + pinned, NULL); obj->userptr.ptr + pinned * PAGE_SIZE,
if (ret < 0) npages - pinned,
break; !obj->userptr.read_only, 0,
pvec + pinned, NULL);
if (ret < 0)
break;
pinned += ret; pinned += ret;
}
up_read(&mm->mmap_sem);
mmput(mm);
} }
up_read(&mm->mmap_sem);
} }
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);