Skip to contentSkip to conversation

drm/radeon: fix bo creation retry path

PATCH In review [email protected] 4 participants 5 messages Jul 12, 2012 – Aug 21, 2012

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

PATCH 1/1 drm/radeon: fix bo creation retry path

From: Jerome Glisse <[email protected]>

Retry label was at wrong place in function leading to memory leak.

---
 drivers/gpu/drm/radeon/radeon_object.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_object.c +2 -1
index 6ecb200..f71e472 100644
@@ -138,7 +138,6 @@ int radeon_bo_create(struct radeon_device *rdev,
 	acc_size = ttm_bo_dma_acc_size(&rdev->mman.bdev, size,
 				       sizeof(struct radeon_bo));
 
-retry:
 	bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
 	if (bo == NULL)
 		return -ENOMEM;
@@ -152,6 +151,8 @@ retry:
 	bo->surface_reg = -1;
 	INIT_LIST_HEAD(&bo->list);
 	INIT_LIST_HEAD(&bo->va);
+
+retry:
 	radeon_ttm_placement_from_domain(bo, domain);
 	/* Kernel allocation are uninterruptible */
 	down_read(&rdev->pm.mclk_lock);
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · On Don, 2012-07-12 at 18:23 -0400, [email protected] wrote:

From: Jerome Glisse <[email protected]>

Retry label was at wrong place in function leading to memory leak.

---
 drivers/gpu/drm/radeon/radeon_object.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_object.c +0 -1
index 6ecb200..f71e472 100644
@@ -138,7 +138,6 @@ int radeon_bo_create(struct radeon_device *rdev,
 	acc_size = ttm_bo_dma_acc_size(&rdev->mman.bdev, size,
 				       sizeof(struct radeon_bo));
 
-retry:
 	bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
 	if (bo == NULL)
 		return -ENOMEM;

drivers/gpu/drm/radeon/radeon_object.c retry: · line 158

Quoted 8 lines
drivers/gpu/drm/radeon/radeon_object.c +2 -0
@@ -152,6 +151,8 @@ retry:
 	bo->surface_reg = -1;
 	INIT_LIST_HEAD(&bo->list);
 	INIT_LIST_HEAD(&bo->va);
+
+retry:
 	radeon_ttm_placement_from_domain(bo, domain);
 	/* Kernel allocation are uninterruptible */
 	down_read(&rdev->pm.mclk_lock);
Signature · 2 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer
#2 lore raw
Quoted 20 lines · Michel Dänzer
Quoted 19 lines · On Don, 2012-07-12 at 18:23 -0400, [email protected] wrote:

From: Jerome Glisse <[email protected]>

Retry label was at wrong place in function leading to memory leak.

---
 drivers/gpu/drm/radeon/radeon_object.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 6ecb200..f71e472 100644
@@ -138,7 +138,6 @@ int radeon_bo_create(struct radeon_device *rdev,
 	acc_size = ttm_bo_dma_acc_size(&rdev->mman.bdev, size,
 				       sizeof(struct radeon_bo));
 
Quoted 15 lines

drivers/gpu/drm/radeon/radeon_object.c retry: · line 158

Quoted 13 lines
drivers/gpu/drm/radeon/radeon_object.c +2 -1
-retry:
 	bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
 	if (bo == NULL)
 		return -ENOMEM;
@@ -152,6 +151,8 @@ retry:
 	bo->surface_reg = -1;
 	INIT_LIST_HEAD(&bo->list);
 	INIT_LIST_HEAD(&bo->va);
+
+retry:
 	radeon_ttm_placement_from_domain(bo, domain);
 	/* Kernel allocation are uninterruptible */
 	down_read(&rdev->pm.mclk_lock);

Actually, this is wrong: ttm_bo_init() destroys the BO on failure. So this patch makes the retry path work with freed memory. I see on IRC that this is causing panics with some piglit tests for several people, please submit a patch to revert this.

Sorry I didn't remember this when reviewing the patch. :(

Signature · 2 lines
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer
#3 lore raw
Quoted 37 lines · Michel Dänzer
Quoted 20 lines · Michel Dänzer
Quoted 19 lines · On Don, 2012-07-12 at 18:23 -0400, [email protected] wrote:

From: Jerome Glisse <[email protected]>

Retry label was at wrong place in function leading to memory leak.

---
 drivers/gpu/drm/radeon/radeon_object.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_object.c +0 -0
index 6ecb200..f71e472 100644
@@ -138,7 +138,6 @@ int radeon_bo_create(struct radeon_device *rdev,
    acc_size = ttm_bo_dma_acc_size(&rdev->mman.bdev, size,
                                   sizeof(struct radeon_bo));
 
Quoted 15 lines

drivers/gpu/drm/radeon/radeon_object.c retry: · line 158

Quoted 13 lines
drivers/gpu/drm/radeon/radeon_object.c +2 -1
-retry:
    bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
    if (bo == NULL)
            return -ENOMEM;
@@ -152,6 +151,8 @@ retry:
    bo->surface_reg = -1;
    INIT_LIST_HEAD(&bo->list);
    INIT_LIST_HEAD(&bo->va);
+
+retry:
    radeon_ttm_placement_from_domain(bo, domain);
    /* Kernel allocation are uninterruptible */
    down_read(&rdev->pm.mclk_lock);
Quoted 6 lines

Actually, this is wrong: ttm_bo_init() destroys the BO on failure. So this patch makes the retry path work with freed memory. I see on IRC that this is causing panics with some piglit tests for several people, please submit a patch to revert this.

Sorry I didn't remember this when reviewing the patch. :(

Reverted in my -fixes queue.

Alex

Reviewed-by on v1 1/1
#4 lore raw
In reply to [email protected]
Quoted 7 lines · On 13.07.2012 00:23, [email protected] wrote:

From: Jerome Glisse <[email protected]>

Retry label was at wrong place in function leading to memory leak.

Quoted 25 lines
---
  drivers/gpu/drm/radeon/radeon_object.c |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_object.c +2 -1
index 6ecb200..f71e472 100644
@@ -138,7 +138,6 @@ int radeon_bo_create(struct radeon_device *rdev,
  	acc_size = ttm_bo_dma_acc_size(&rdev->mman.bdev, size,
  				       sizeof(struct radeon_bo));
 
-retry:
  	bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
  	if (bo == NULL)
  		return -ENOMEM;
@@ -152,6 +151,8 @@ retry:
  	bo->surface_reg = -1;
  	INIT_LIST_HEAD(&bo->list);
  	INIT_LIST_HEAD(&bo->va);
+
+retry:
  	radeon_ttm_placement_from_domain(bo, domain);
  	/* Kernel allocation are uninterruptible */
  	down_read(&rdev->pm.mclk_lock);