]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
drm/amdgpu: validate shadow before restoring from it
authorRoger.He <Hongbo.He@amd.com>
Fri, 21 Apr 2017 05:08:43 +0000 (13:08 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 28 Apr 2017 21:33:08 +0000 (17:33 -0400)
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Roger.He <Hongbo.He@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h

index 234d90a1248244e91536ecb649b829e501eb6463..3c1754df4c40a08b223a39c8051411fb9d5ceaa5 100644 (file)
@@ -2429,6 +2429,18 @@ static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
        domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
        /* if bo has been evicted, then no need to recover */
        if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
+               r = amdgpu_bo_validate(bo->shadow);
+               if (r) {
+                       DRM_ERROR("bo validate failed!\n");
+                       goto err;
+               }
+
+               r = amdgpu_ttm_bind(&bo->shadow->tbo, &bo->shadow->tbo.mem);
+               if (r) {
+                       DRM_ERROR("%p bind failed\n", bo->shadow);
+                       goto err;
+               }
+
                r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
                                                 NULL, fence, true);
                if (r) {
index 60de77b153b7ecf9381e94b14f8433cbcd9427b2..365883d7948d2ab8ab2bea71163f1eae2c1b2eb6 100644 (file)
@@ -543,6 +543,27 @@ err:
        return r;
 }
 
+int amdgpu_bo_validate(struct amdgpu_bo *bo)
+{
+       uint32_t domain;
+       int r;
+
+       if (bo->pin_count)
+               return 0;
+
+       domain = bo->prefered_domains;
+
+retry:
+       amdgpu_ttm_placement_from_domain(bo, domain);
+       r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+       if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
+               domain = bo->allowed_domains;
+               goto retry;
+       }
+
+       return r;
+}
+
 int amdgpu_bo_restore_from_shadow(struct amdgpu_device *adev,
                                  struct amdgpu_ring *ring,
                                  struct amdgpu_bo *bo,
index 15a723adca764903f21ef0f220852c70093b0a36..382485115b0641b059602d21fa92be33281ac8de 100644 (file)
@@ -175,6 +175,7 @@ int amdgpu_bo_backup_to_shadow(struct amdgpu_device *adev,
                               struct amdgpu_bo *bo,
                               struct reservation_object *resv,
                               struct dma_fence **fence, bool direct);
+int amdgpu_bo_validate(struct amdgpu_bo *bo);
 int amdgpu_bo_restore_from_shadow(struct amdgpu_device *adev,
                                  struct amdgpu_ring *ring,
                                  struct amdgpu_bo *bo,