drm/amdgpu: fix VM page table reference counting
authorChristian König <christian.koenig@amd.com>
Fri, 27 Nov 2015 15:49:00 +0000 (16:49 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 30 Nov 2015 19:41:33 +0000 (14:41 -0500)
We use the reservation object of the page directory for the page tables as
well, because of this the page directory should be freed last. Ensure that
by keeping a reference from the page tables to the directory.

Signed-off-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index 251b14736de92b7ff429d01f9d257c3b918b6547..670fefb56945258faf899b708047a2bd83685a59 100644 (file)
@@ -539,6 +539,7 @@ struct amdgpu_bo {
        /* Constant after initialization */
        struct amdgpu_device            *adev;
        struct drm_gem_object           gem_base;
+       struct amdgpu_bo                *parent;
 
        struct ttm_bo_kmap_obj          dma_buf_vmap;
        pid_t                           pid;
index 0d524384ff79c3b49d2dbaa1489d8cbff231d80a..c3ce103b6a33b2ef3a0a6f7f14877e18150ca405 100644 (file)
@@ -100,6 +100,7 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
        list_del_init(&bo->list);
        mutex_unlock(&bo->adev->gem.mutex);
        drm_gem_object_release(&bo->gem_base);
+       amdgpu_bo_unref(&bo->parent);
        kfree(bo->metadata);
        kfree(bo);
 }
index ae037e5b6ad016d6ee70545b814d082da84f22c3..a582ef5534992f7d2e1e3b69bc6a666591958016 100644 (file)
@@ -1079,6 +1079,11 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
                if (r)
                        goto error_free;
 
+               /* Keep a reference to the page table to avoid freeing
+                * them up in the wrong order.
+                */
+               pt->parent = amdgpu_bo_ref(vm->page_directory);
+
                r = amdgpu_vm_clear_bo(adev, pt);
                if (r) {
                        amdgpu_bo_unref(&pt);