aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/3726-drm-amdgpu-fix-prime-teardown-order.patch
blob: bc5df59eddde4f85bbd5f78bd31f1284a1554ce1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
From a6ab7d1f283ccbaa9460fcaaf03c4678c2ab7c17 Mon Sep 17 00:00:00 2001
From: Christian Koenig <christian.koenig@amd.com>
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 <christian.koenig@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
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