diff mbox series

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

Message ID 20230111175015.1134923-1-zack@kde.org (mailing list archive)
State New, archived
Headers show
Series drm/ttm: Fix a regression causing kernel oops'es | expand

Commit Message

Zack Rusin Jan. 11, 2023, 5:50 p.m. UTC
From: Zack Rusin <zackr@vmware.com>

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.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Fixes: e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
Cc: Somalapuram Amaranath <Amaranath.Somalapuram@amd.com>
Cc: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Martin Krastev (VMware) Jan. 11, 2023, 9:04 p.m. UTC | #1
From: Martin Krastev <krastevm@vmware.com>


LGTM!
Reviewed-by: Martin Krastev <krastevm@vmware.com>


Regards,
Martin


On 11.01.23 г. 19:50 ч., Zack Rusin wrote:
> From: Zack Rusin <zackr@vmware.com>
>
> 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.
>
> Signed-off-by: Zack Rusin <zackr@vmware.com>
> Fixes: e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
> Cc: Somalapuram Amaranath <Amaranath.Somalapuram@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index fee7c20775c0..12017ec24d9f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -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);
Christian König Jan. 12, 2023, 7:01 a.m. UTC | #2
Am 11.01.23 um 18:50 schrieb Zack Rusin:
> From: Zack Rusin <zackr@vmware.com>
>
> 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.
>
> Signed-off-by: Zack Rusin <zackr@vmware.com>
> Fixes: e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
> Cc: Somalapuram Amaranath <Amaranath.Somalapuram@amd.com>
> Cc: Christian König <christian.koenig@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

Should I push it to drm-misc-fixes?

Thanks,
Christian.

> ---
>   drivers/gpu/drm/ttm/ttm_bo_util.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index fee7c20775c0..12017ec24d9f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -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);
Zack Rusin Jan. 12, 2023, 12:11 p.m. UTC | #3
On Thu, 2023-01-12 at 08:01 +0100, Christian König wrote:
> !! External Email
> 
> Am 11.01.23 um 18:50 schrieb Zack Rusin:
> > From: Zack Rusin <zackr@vmware.com>
> > 
> > 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.
> > 
> > Signed-off-by: Zack Rusin <zackr@vmware.com>
> > Fixes: e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
> > Cc: Somalapuram Amaranath <Amaranath.Somalapuram@amd.com>
> > Cc: Christian König <christian.koenig@amd.com>
> 
> Reviewed-by: Christian König <christian.koenig@amd.com>
> 
> 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
Christian König Jan. 12, 2023, 1:06 p.m. UTC | #4
Am 12.01.23 um 13:11 schrieb Zack Rusin:
> On Thu, 2023-01-12 at 08:01 +0100, Christian König wrote:
>> !! External Email
>>
>> Am 11.01.23 um 18:50 schrieb Zack Rusin:
>>> From: Zack Rusin <zackr@vmware.com>
>>>
>>> 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.
>>>
>>> Signed-off-by: Zack Rusin <zackr@vmware.com>
>>> Fixes: e3c92eb4a84f ("drm/ttm: rework on ttm_resource to use size_t type")
>>> Cc: Somalapuram Amaranath <Amaranath.Somalapuram@amd.com>
>>> Cc: Christian König <christian.koenig@amd.com>
>> Reviewed-by: Christian König <christian.koenig@amd.com>
>>
>> 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.

>
> z
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index fee7c20775c0..12017ec24d9f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -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);