drm/gem-vram: handle NULL bo->resource in move callback
authorMatthew Auld <matthew.auld@intel.com>
Wed, 8 Feb 2023 14:53:16 +0000 (14:53 +0000)
committerChristian König <christian.koenig@amd.com>
Thu, 23 Feb 2023 09:29:00 +0000 (10:29 +0100)
The ttm BO now initially has NULL bo->resource, and leaves the driver
the handle that. However it looks like we forgot to handle that for
ttm_bo_move_memcpy() users, like with vram-gem, since it just silently
returns zero. This seems to then trigger warnings like:

WARNING: CPU: 0 PID: 1 at drivers/gpu/drm/drm_gem_vram_helper.c:255 drm_gem_vram_offset (??:?)

Fix this by calling move_null() if the new resource is TTM_PL_SYSTEM,
otherwise do the multi-hop sequence to ensure can safely call into
ttm_bo_move_memcpy(), since it might also need to clear the memory.
This should give the same behaviour as before.

While we are here let's also treat calling ttm_bo_move_memcpy() with
NULL bo->resource as programmer error, where expectation is that upper
layers should now handle it.

Fixes: 180253782038 ("drm/ttm: stop allocating dummy resources during BO creation")
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230208145319.397235-1-matthew.auld@intel.com
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
drivers/gpu/drm/drm_gem_vram_helper.c
drivers/gpu/drm/ttm/ttm_bo_util.c

index d40b3edb52d07e867c6368c5930b627b4a1ce8cb..0bea3df2a16dcaff1c5ea38f343478c2d819bb08 100644 (file)
@@ -916,6 +916,17 @@ static int bo_driver_move(struct ttm_buffer_object *bo,
 {
        struct drm_gem_vram_object *gbo;
 
+       if (!bo->resource) {
+               if (new_mem->mem_type != TTM_PL_SYSTEM) {
+                       hop->mem_type = TTM_PL_SYSTEM;
+                       hop->flags = TTM_PL_FLAG_TEMPORARY;
+                       return -EMULTIHOP;
+               }
+
+               ttm_bo_move_null(bo, new_mem);
+               return 0;
+       }
+
        gbo = drm_gem_vram_of_bo(bo);
 
        return drm_gem_vram_bo_driver_move(gbo, evict, ctx, new_mem);
index d9d2b0903b2226e9596f4a673529a40eef4c830a..fd9fd3d15101c873758c6365eb4924214e23fe7b 100644 (file)
@@ -157,8 +157,8 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
        bool clear;
        int ret = 0;
 
-       if (!src_mem)
-               return 0;
+       if (WARN_ON(!src_mem))
+               return -EINVAL;
 
        src_man = ttm_manager_type(bdev, src_mem->mem_type);
        if (ttm && ((ttm->page_flags & TTM_TT_FLAG_SWAPPED) ||