drm/amdgpu: Fix size validation for non-exclusive domains (v4)
authorjsg <jsg@openbsd.org>
Fri, 13 Jan 2023 01:37:01 +0000 (01:37 +0000)
committerjsg <jsg@openbsd.org>
Fri, 13 Jan 2023 01:37:01 +0000 (01:37 +0000)
From Luben Tuikov
8ba7c55e112f4ffd2a95b99be1cb1c891ef08ba1 in linux-6.1.y/6.1.5
7554886daa31eacc8e7fac9e15bbce67d10b8f1f in mainline linux

sys/dev/pci/drm/amd/amdgpu/amdgpu_object.c

index 7194ff2..80e4bea 100644 (file)
@@ -447,27 +447,24 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
 
        /*
         * If GTT is part of requested domains the check must succeed to
-        * allow fall back to GTT
+        * allow fall back to GTT.
         */
        if (domain & AMDGPU_GEM_DOMAIN_GTT) {
                man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 
-               if (size < man->size)
+               if (man && size < man->size)
                        return true;
-               else
-                       goto fail;
-       }
-
-       if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
+               else if (!man)
+                       WARN_ON_ONCE("GTT domain requested but GTT mem manager uninitialized");
+               goto fail;
+       } else if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
                man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 
-               if (size < man->size)
+               if (man && size < man->size)
                        return true;
-               else
-                       goto fail;
+               goto fail;
        }
 
-
        /* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */
        return true;