[PATCH 10/10] drm/ttm: flip the switch for driver allocated resources v2

Thomas Hellström (Intel) thomas_os at shipmail.org
Mon Jun 7 10:15:24 UTC 2021


On 6/2/21 12:09 PM, Christian König wrote:
> Instead of both driver and TTM allocating memory finalize embedding the
> ttm_resource object as base into the driver backends.
>
> v2: fix typo in vmwgfx grid mgr and double init in amdgpu_vram_mgr.c
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> Reviewed-by: Matthew Auld <matthew.auld at intel.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   | 44 ++++++--------
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  2 +-
>   .../gpu/drm/amd/amdgpu/amdgpu_res_cursor.h    |  5 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  | 60 +++++++++----------
>   drivers/gpu/drm/drm_gem_vram_helper.c         |  3 +-
>   drivers/gpu/drm/nouveau/nouveau_bo.c          |  8 +--
>   drivers/gpu/drm/nouveau/nouveau_mem.c         | 11 ++--
>   drivers/gpu/drm/nouveau/nouveau_mem.h         | 14 ++---
>   drivers/gpu/drm/nouveau/nouveau_ttm.c         | 32 +++++-----
>   drivers/gpu/drm/ttm/ttm_range_manager.c       | 23 +++----
>   drivers/gpu/drm/ttm/ttm_resource.c            | 18 +-----
>   drivers/gpu/drm/ttm/ttm_sys_manager.c         | 12 ++--
>   drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 24 ++++----
>   drivers/gpu/drm/vmwgfx/vmwgfx_thp.c           | 27 ++++-----
>   include/drm/ttm/ttm_range_manager.h           |  3 +-
>   include/drm/ttm/ttm_resource.h                | 43 ++++++-------
>   16 files changed, 140 insertions(+), 189 deletions(-)
...
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c
> index ce5d07ca384c..c32e1aee2481 100644
> --- a/drivers/gpu/drm/ttm/ttm_range_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_range_manager.c
> @@ -58,7 +58,7 @@ to_range_manager(struct ttm_resource_manager *man)
>   static int ttm_range_man_alloc(struct ttm_resource_manager *man,
>   			       struct ttm_buffer_object *bo,
>   			       const struct ttm_place *place,
> -			       struct ttm_resource *mem)
> +			       struct ttm_resource **res)
>   {
>   	struct ttm_range_manager *rman = to_range_manager(man);
>   	struct ttm_range_mgr_node *node;
> @@ -83,37 +83,30 @@ static int ttm_range_man_alloc(struct ttm_resource_manager *man,
>   
>   	spin_lock(&rman->lock);
>   	ret = drm_mm_insert_node_in_range(mm, &node->mm_nodes[0],
> -					  mem->num_pages, bo->page_alignment, 0,
> +					  node->base.num_pages,
> +					  bo->page_alignment, 0,
>   					  place->fpfn, lpfn, mode);
>   	spin_unlock(&rman->lock);
>   
> -	if (unlikely(ret)) {
> +	if (unlikely(ret))
>   		kfree(node);
> -	} else {
> -		mem->mm_node = &node->mm_nodes[0];
> -		mem->start = node->mm_nodes[0].start;
> -	}
> +	else
> +		node->base.start = node->mm_nodes[0].start;
>   
>   	return ret;
>   }

Looks like this patch forgets to assign *@res. Null pointer derefs when 
testing i915.

BTW shouldn't we return the struct ttm_resource ptr here rather than 
passing it as an argument?

/Thomas




More information about the dri-devel mailing list