gallium/radeon: Fix potential address space loss in radeon_bomgr_force_va().
authorMichel Dänzer <michel.daenzer@amd.com>
Thu, 26 Apr 2012 10:10:02 +0000 (12:10 +0200)
committerMichel Dänzer <michel@daenzer.net>
Thu, 16 Aug 2012 09:58:23 +0000 (11:58 +0200)
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/winsys/radeon/drm/radeon_drm_bo.c

index 1bf22a71d91e33c2b9a5f6e93756940231268ae0..79355af79953f0182e41d201efeaed27f7f1d0c2 100644 (file)
@@ -268,18 +268,25 @@ static void radeon_bomgr_force_va(struct radeon_bomgr *mgr, uint64_t va, uint64_
         mgr->va_offset = va + size;
     } else {
         struct radeon_bo_va_hole *hole, *n;
-        uint64_t stmp, etmp;
+        uint64_t hole_end, va_end;
 
-        /* free all holes that fall into the range
-         * NOTE that we might lose virtual address space
+        /* Prune/free all holes that fall into the range
          */
         LIST_FOR_EACH_ENTRY_SAFE(hole, n, &mgr->va_holes, list) {
-            stmp = hole->offset;
-            etmp = stmp + hole->size;
-            if (va >= stmp && va < etmp) {
+            hole_end = hole->offset + hole->size;
+            va_end = va + size;
+            if (hole->offset >= va_end || hole_end <= va)
+                continue;
+            if (hole->offset >= va && hole_end <= va_end) {
                 list_del(&hole->list);
                 FREE(hole);
+                continue;
             }
+            if (hole->offset >= va)
+                hole->offset = va_end;
+            else
+                hole_end = va;
+            hole->size = hole_end - hole->offset;
         }
     }
     pipe_mutex_unlock(mgr->bo_va_mutex);