From a6ab7d1f283ccbaa9460fcaaf03c4678c2ab7c17 Mon Sep 17 00:00:00 2001 From: Christian Koenig Date: Fri, 9 Mar 2018 14:42:54 +0100 Subject: [PATCH 3726/4131] drm/amdgpu: fix prime teardown order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We unmapped imported DMA-bufs when the GEM handle was dropped, not when the hardware was done with the buffere. Signed-off-by: Christian König Reviewed-by: Michel Dänzer CC: stable@vger.kernel.org --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 38 +++++------------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++ 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 05c558d..d5a265e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -33,21 +33,11 @@ void amdgpu_gem_object_free(struct drm_gem_object *gobj) { - struct amdgpu_gem_object *aobj; - - aobj = container_of((gobj), struct amdgpu_gem_object, base); - if (aobj->base.import_attach) - drm_prime_gem_destroy(&aobj->base, aobj->bo->tbo.sg); - - ww_mutex_lock(&aobj->bo->tbo.resv->lock, NULL); - list_del(&aobj->list); - ww_mutex_unlock(&aobj->bo->tbo.resv->lock); - - amdgpu_mn_unregister(aobj->bo); - amdgpu_bo_unref(&aobj->bo); - drm_gem_object_release(&aobj->base); - kfree(aobj); - + struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj); + if (robj) { + amdgpu_mn_unregister(robj); + amdgpu_bo_unref(&robj); + } } int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, @@ -104,23 +94,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, return r; } - gobj = kzalloc(sizeof(struct amdgpu_gem_object), GFP_KERNEL); - if (unlikely(!gobj)) { - amdgpu_bo_unref(&robj); - return -ENOMEM; - } - - r = drm_gem_object_init(adev->ddev, &gobj->base, amdgpu_bo_size(robj)); - if (unlikely(r)) { - kfree(gobj); - amdgpu_bo_unref(&robj); - return r; - } - - list_add(&gobj->list, &robj->gem_objects); - gobj->bo = robj; - *obj = &gobj->base; - + *obj = &bo->gem_base; return 0; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 4104eb6..94331fd 100755 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -54,15 +54,18 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) { struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev); struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo); + u64 offset; if (bo->tbo.mem.mem_type == AMDGPU_PL_DGMA_IMPORT) kfree(tbo->mem.bus.addr); if (bo->kfd_bo) amdgpu_amdkfd_unreserve_system_memory_limit(bo); + amdgpu_bo_kunmap(bo); if (bo->gem_base.import_attach) drm_prime_gem_destroy(&bo->gem_base, bo->tbo.sg); + drm_gem_object_release(&bo->gem_base); amdgpu_bo_unref(&bo->parent); if (!list_empty(&bo->shadow_list)) { mutex_lock(&adev->shadow_list_lock); -- 2.7.4