Skip to contentSkip to conversation

drm/ttm: fix the tt_populated check in ttm_tt_destroy()

PATCH In review Ben Skeggs 2 participants 2 messages Sep 17, 2013

Subsystems (3)
lore
Share & tools
lore

Ben Skeggs

author
#0 lore raw

PATCH 1/1 drm/ttm: fix the tt_populated check in ttm_tt_destroy()

From: Ben Skeggs <[email protected]>

After a vmalloc failure in ttm_dma_tt_alloc_page_directory(), ttm_dma_tt_init() will call ttm_tt_destroy() to cleanup, and end up inside the driver's unpopulate() hook when populate() has never yet been called.

On nouveau, the first issue to be hit because of this is that dma_address[] may be a NULL pointer. After working around this, ttm_pool_unpopulate() may potentially hit the same issue with the pages[] array.

It seems to make more sense to avoid calling unpopulate on already unpopulated TTMs than to add checks to all the implementations.

Cc Jerome Glisse <[email protected]>
Cc Thomas Hellstrom <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_tt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +1 -1
index 5e93a52..210d503 100644
@@ -170,7 +170,7 @@ void ttm_tt_destroy(struct ttm_tt *ttm)
 		ttm_tt_unbind(ttm);
 	}
 
-	if (likely(ttm->pages != NULL)) {
+	if (ttm->state == tt_unbound) {
 		ttm->bdev->driver->ttm_tt_unpopulate(ttm);
 	}
 
Signature · 1 line
1.8.3.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Ben Skeggs

From: Ben Skeggs <[email protected]>

After a vmalloc failure in ttm_dma_tt_alloc_page_directory(), ttm_dma_tt_init() will call ttm_tt_destroy() to cleanup, and end up inside the driver's unpopulate() hook when populate() has never yet been called.

On nouveau, the first issue to be hit because of this is that dma_address[] may be a NULL pointer. After working around this, ttm_pool_unpopulate() may potentially hit the same issue with the pages[] array.

It seems to make more sense to avoid calling unpopulate on already unpopulated TTMs than to add checks to all the implementations.

Cc Jerome Glisse <[email protected]>
Cc Thomas Hellstrom <[email protected]>
---
  drivers/gpu/drm/ttm/ttm_tt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -0
index 5e93a52..210d503 100644

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_destroy(struct ttm_tt *ttm) · line 176

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_tt.c +1 -1
@@ -170,7 +170,7 @@ void ttm_tt_destroy(struct ttm_tt *ttm)
  		ttm_tt_unbind(ttm);
  	}
 
-	if (likely(ttm->pages != NULL)) {
+	if (ttm->state == tt_unbound) {
  		ttm->bdev->driver->ttm_tt_unpopulate(ttm);
  	}
 

Looks good to me.