Skip to contentSkip to conversation

drm/ttm: Fix buffer object metadata accounting regression v2

PATCH In review Thomas Hellstrom 3 participants 3 messages Jun 12, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/ttm: Fix buffer object metadata accounting regression v2

A regression was introduced in the 3.3 rc series, commit "drm/ttm: simplify memory accounting for ttm user v2", causing the metadata of buffer objects created using the ttm_bo_create() function to be accounted twice.
That causes massive leaks with the vmwgfx driver running for example SpecViewperf Catia-03 test 2, eventually killing the app.

Furthermore, the same commit introduces a regression where metadata accounting is leaked if a buffer object is initialized with an illegal size. This is also fixed with this commit.

v2: Fixed an error path and removed an unused variable.

---
 drivers/gpu/drm/ttm/ttm_bo.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +3 -10
index b67cfca..36f4b28 100644
@@ -1204,6 +1204,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
 			(*destroy)(bo);
 		else
 			kfree(bo);
+		ttm_mem_global_free(mem_glob, acc_size);
 		return -EINVAL;
 	}
 	bo->destroy = destroy;
@@ -1307,22 +1308,14 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 			struct ttm_buffer_object **p_bo)
 {
 	struct ttm_buffer_object *bo;
-	struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
 	size_t acc_size;
 	int ret;
 
-	acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object));
-	ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false);
-	if (unlikely(ret != 0))
-		return ret;
-
 	bo = kzalloc(sizeof(*bo), GFP_KERNEL);
-
-	if (unlikely(bo == NULL)) {
-		ttm_mem_global_free(mem_glob, acc_size);
+	if (unlikely(bo == NULL))
 		return -ENOMEM;
-	}
 
+	acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object));
 	ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment,
 				buffer_start, interruptible,
 			  persistent_swap_storage, acc_size, NULL, NULL);
Signature · 1 line
1.7.7.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Thomas Hellstrom

A regression was introduced in the 3.3 rc series, commit "drm/ttm: simplify memory accounting for ttm user v2", causing the metadata of buffer objects created using the ttm_bo_create() function to be accounted twice.
That causes massive leaks with the vmwgfx driver running for example SpecViewperf Catia-03 test 2, eventually killing the app.

Furthermore, the same commit introduces a regression where metadata accounting is leaked if a buffer object is initialized with an illegal size. This is also fixed with this commit.

Quoted 5 lines

v2: Fixed an error path and removed an unused variable.

Quoted 48 lines
---
 drivers/gpu/drm/ttm/ttm_bo.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +3 -10
index b67cfca..36f4b28 100644
@@ -1204,6 +1204,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
 			(*destroy)(bo);
 		else
 			kfree(bo);
+		ttm_mem_global_free(mem_glob, acc_size);
 		return -EINVAL;
 	}
 	bo->destroy = destroy;
@@ -1307,22 +1308,14 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 			struct ttm_buffer_object **p_bo)
 {
 	struct ttm_buffer_object *bo;
-	struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
 	size_t acc_size;
 	int ret;
 
-	acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object));
-	ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false);
-	if (unlikely(ret != 0))
-		return ret;
-
 	bo = kzalloc(sizeof(*bo), GFP_KERNEL);
-
-	if (unlikely(bo == NULL)) {
-		ttm_mem_global_free(mem_glob, acc_size);
+	if (unlikely(bo == NULL))
 		return -ENOMEM;
-	}
 
+	acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object));
 	ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment,
 				buffer_start, interruptible,
 			  persistent_swap_storage, acc_size, NULL, NULL);
Signature · 6 lines
1.7.7.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by
#2 lore raw
Quoted 12 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Thomas Hellstrom

A regression was introduced in the 3.3 rc series, commit "drm/ttm: simplify memory accounting for ttm user v2", causing the metadata of buffer objects created using the ttm_bo_create() function to be accounted twice.
That causes massive leaks with the vmwgfx driver running for example SpecViewperf Catia-03 test 2, eventually killing the app.

Furthermore, the same commit introduces a regression where metadata accounting is leaked if a buffer object is initialized with an illegal size. This is also fixed with this commit.

Quoted 7 lines
Quoted 5 lines

v2: Fixed an error path and removed an unused variable.

Quoted 52 lines
Quoted 44 lines

---
 drivers/gpu/drm/ttm/ttm_bo.c |   13 +++----------

 1 files changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
index b67cfca..36f4b28 100644
@@ -1204,6 +1204,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev,
                       (*destroy)(bo);

              else
                      kfree(bo);
+             ttm_mem_global_free(mem_glob, acc_size); return -EINVAL;
      }
      bo->destroy = destroy;

drivers/gpu/drm/ttm/ttm_bo.c +2 -11
@@ -1307,22 +1308,14 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
                       struct ttm_buffer_object **p_bo)
  {
       struct ttm_buffer_object *bo;
-     struct ttm_mem_global *mem_glob = bdev->glob->mem_glob;
       size_t acc_size;
       int ret;
 
-     acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object));
-     ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false);
-     if (unlikely(ret != 0))
-             return ret;
-
       bo = kzalloc(sizeof(*bo), GFP_KERNEL);
-
-     if (unlikely(bo == NULL)) {
-             ttm_mem_global_free(mem_glob, acc_size);
+     if (unlikely(bo == NULL))
               return -ENOMEM;
-     }
 
+     acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object));
       ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment,
                               buffer_start, interruptible,
                         persistent_swap_storage, acc_size, NULL, NULL);
--

1.7.7.5

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel