aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorNicolai Hähnle <nicolai.haehnle@amd.com>2017-02-18 16:59:56 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-05-14 08:00:22 -0400
commit48d9fa1ece5ee453d4c08a7feec74c966939a25c (patch)
treecfd58eb3c5d8e4558852076f0f7bdaa1a0a4e9cf /drivers/gpu
parent347d07bf3add9bc1a7d52fad2f8efea61aa75c38 (diff)
drm/ttm: fix use-after-free races in vm fault handling
commit 3089c1df10e2931b1d72d2ffa7d86431084c86b3 upstream. The vm fault handler relies on the fact that the VMA owns a reference to the BO. However, once mmap_sem is released, other tasks are free to destroy the VMA, which can lead to the BO being freed. Fix two code paths where that can happen, both related to vm fault retries. Found via a lock debugging warning which flagged &bo->wu_mutex as locked while being destroyed. Fixes: cbe12e74ee4e ("drm/ttm: Allow vm fault retries") Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index a6ed9d5e5167..750733a8cce2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -66,8 +66,11 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
66 if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) 66 if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT)
67 goto out_unlock; 67 goto out_unlock;
68 68
69 ttm_bo_reference(bo);
69 up_read(&vma->vm_mm->mmap_sem); 70 up_read(&vma->vm_mm->mmap_sem);
70 (void) fence_wait(bo->moving, true); 71 (void) fence_wait(bo->moving, true);
72 ttm_bo_unreserve(bo);
73 ttm_bo_unref(&bo);
71 goto out_unlock; 74 goto out_unlock;
72 } 75 }
73 76
@@ -120,8 +123,10 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
120 123
121 if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) { 124 if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {
122 if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) { 125 if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
126 ttm_bo_reference(bo);
123 up_read(&vma->vm_mm->mmap_sem); 127 up_read(&vma->vm_mm->mmap_sem);
124 (void) ttm_bo_wait_unreserved(bo); 128 (void) ttm_bo_wait_unreserved(bo);
129 ttm_bo_unref(&bo);
125 } 130 }
126 131
127 return VM_FAULT_RETRY; 132 return VM_FAULT_RETRY;
@@ -166,6 +171,13 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
166 ret = ttm_bo_vm_fault_idle(bo, vma, vmf); 171 ret = ttm_bo_vm_fault_idle(bo, vma, vmf);
167 if (unlikely(ret != 0)) { 172 if (unlikely(ret != 0)) {
168 retval = ret; 173 retval = ret;
174
175 if (retval == VM_FAULT_RETRY &&
176 !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
177 /* The BO has already been unreserved. */
178 return retval;
179 }
180
169 goto out_unlock; 181 goto out_unlock;
170 } 182 }
171 183