drm/ttm: fix error handling if no BO can be swapped out v4
authorShiwu Zhang <shiwu.zhang@amd.com>
Thu, 22 Apr 2021 08:37:49 +0000 (16:37 +0800)
committerChristian König <christian.koenig@amd.com>
Fri, 23 Apr 2021 12:08:04 +0000 (14:08 +0200)
In case that all pre-allocated BOs are busy, just continue to populate
BOs since likely half of system memory in total is still free.

v4 (chk): fix code moved to VMWGFX as well

Signed-off-by: Shiwu Zhang <shiwu.zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210422115757.3946-1-christian.koenig@amd.com
drivers/gpu/drm/ttm/ttm_device.c
drivers/gpu/drm/ttm/ttm_tt.c
drivers/gpu/drm/vmwgfx/ttm_memory.c

index 528cc5a..b169e9a 100644 (file)
@@ -112,7 +112,7 @@ int ttm_global_swapout(struct ttm_operation_ctx *ctx, gfp_t gfp_flags)
 {
        struct ttm_global *glob = &ttm_glob;
        struct ttm_device *bdev;
-       int ret = -EBUSY;
+       int ret = 0;
 
        mutex_lock(&ttm_global_mutex);
        list_for_each_entry(bdev, &glob->device_list, device_list) {
index 48c407c..539e023 100644 (file)
@@ -329,6 +329,8 @@ int ttm_tt_populate(struct ttm_device *bdev,
               ttm_dma32_pages_limit) {
 
                ret = ttm_global_swapout(ctx, GFP_KERNEL);
+               if (ret == 0)
+                       break;
                if (ret < 0)
                        goto error;
        }
index 104b95a..aeb0a22 100644 (file)
@@ -280,7 +280,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
                spin_unlock(&glob->lock);
                ret = ttm_global_swapout(ctx, GFP_KERNEL);
                spin_lock(&glob->lock);
-               if (unlikely(ret < 0))
+               if (unlikely(ret <= 0))
                        break;
        }