Skip to contentSkip to conversation

drm/ttm: Fix a regression causing kernel oops'es

PATCH In review Zack Rusin 4 participants 5 messages Jan 11, 2023 – Jan 12, 2023

Subsystems (3)
lore
Share & tools
lore

Zack Rusin

author
#0 lore raw

PATCH 1/1 drm/ttm: Fix a regression causing kernel oops'es

From: Zack Rusin <[email protected]>

The branch is explicitly taken if ttm == NULL which means that to avoid a null pointer reference the ttm object can not be used inside. Switch back to dst_mem to avoid kernel oops'es.

This fixes kernel oops'es with any buffer objects which don't have ttm_tt, e.g. with vram based screen objects on vmwgfx.

Fixes e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
Cc Somalapuram Amaranath <[email protected]>
Cc Christian König <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
index fee7c20775c0..12017ec24d9f 100644
@@ -183,7 +183,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 
 	clear = src_iter->ops->maps_tt && (!ttm || !ttm_tt_is_populated(ttm));
 	if (!(clear && ttm && !(ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC)))
-		ttm_move_memcpy(clear, ttm->num_pages, dst_iter, src_iter);
+		ttm_move_memcpy(clear, PFN_UP(dst_mem->size), dst_iter, src_iter);
 
 	if (!src_iter->ops->maps_tt)
 		ttm_kmap_iter_linear_io_fini(&_src_iter.io, bdev, src_mem);
Signature · 1 line
2.37.2
Reviewed-by Martin Krastev on v1 1/1
#1 lore raw

From: Martin Krastev <[email protected]>

LGTM!

Regards,
Martin

Quoted 30 lines · Zack Rusin

From: Zack Rusin <[email protected]>

The branch is explicitly taken if ttm == NULL which means that to avoid a null pointer reference the ttm object can not be used inside. Switch back to dst_mem to avoid kernel oops'es.

This fixes kernel oops'es with any buffer objects which don't have ttm_tt, e.g. with vram based screen objects on vmwgfx.

Fixes e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
Cc Somalapuram Amaranath <[email protected]>
Cc Christian König <[email protected]>
---
  drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
index fee7c20775c0..12017ec24d9f 100644
@@ -183,7 +183,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 
  	clear = src_iter->ops->maps_tt && (!ttm || !ttm_tt_is_populated(ttm));
  	if (!(clear && ttm && !(ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC)))
-		ttm_move_memcpy(clear, ttm->num_pages, dst_iter, src_iter);
+		ttm_move_memcpy(clear, PFN_UP(dst_mem->size), dst_iter, src_iter);
 
  	if (!src_iter->ops->maps_tt)
  		ttm_kmap_iter_linear_io_fini(&_src_iter.io, bdev, src_mem);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Zack Rusin

Am 11.01.23 um 18:50 schrieb Zack Rusin:

Quoted 6 lines

From: Zack Rusin <[email protected]>

The branch is explicitly taken if ttm == NULL which means that to avoid a null pointer reference the ttm object can not be used inside. Switch back to dst_mem to avoid kernel oops'es.

Quoted 7 lines

This fixes kernel oops'es with any buffer objects which don't have ttm_tt, e.g. with vram based screen objects on vmwgfx.

Fixes e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
Cc Somalapuram Amaranath <[email protected]>
Cc Christian König <[email protected]>

Should I push it to drm-misc-fixes?

Thanks,
Christian.

Quoted 17 lines
---
  drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_util.c +1 -1
index fee7c20775c0..12017ec24d9f 100644
@@ -183,7 +183,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 
  	clear = src_iter->ops->maps_tt && (!ttm || !ttm_tt_is_populated(ttm));
  	if (!(clear && ttm && !(ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC)))
-		ttm_move_memcpy(clear, ttm->num_pages, dst_iter, src_iter);
+		ttm_move_memcpy(clear, PFN_UP(dst_mem->size), dst_iter, src_iter);
 
  	if (!src_iter->ops->maps_tt)
  		ttm_kmap_iter_linear_io_fini(&_src_iter.io, bdev, src_mem);
#3 lore raw
Quoted 12 lines · Christian König

!! External Email

Am 11.01.23 um 18:50 schrieb Zack Rusin:

Quoted 9 lines

From: Zack Rusin <[email protected]>

The branch is explicitly taken if ttm == NULL which means that to avoid a null pointer reference the ttm object can not be used inside. Switch back to dst_mem to avoid kernel oops'es.

This fixes kernel oops'es with any buffer objects which don't have ttm_tt, e.g. with vram based screen objects on vmwgfx.

Quoted 8 lines
Quoted 4 lines
Fixes e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
Cc Somalapuram Amaranath <[email protected]>
Cc Christian König <[email protected]>

Should I push it to drm-misc-fixes?

If you're not too busy that'd be great. Otherwise I can do it tomorrow.

z

#4 lore raw

Am 12.01.23 um 13:11 schrieb Zack Rusin:

Quoted 13 lines · Christian König
Quoted 12 lines

!! External Email

Am 11.01.23 um 18:50 schrieb Zack Rusin:

Quoted 9 lines

From: Zack Rusin <[email protected]>

The branch is explicitly taken if ttm == NULL which means that to avoid a null pointer reference the ttm object can not be used inside. Switch back to dst_mem to avoid kernel oops'es.

This fixes kernel oops'es with any buffer objects which don't have ttm_tt, e.g. with vram based screen objects on vmwgfx.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Fixes e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
Cc Somalapuram Amaranath <[email protected]>
Cc Christian König <[email protected]>

Should I push it to drm-misc-fixes?

If you're not too busy that'd be great. Otherwise I can do it tomorrow.

Done.

Quoted 2 lines

z