aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/0797-drm-amdgpu-SEM-some-modification-on-SEM-logic.patch
blob: 49cac13b4ed09873fd0d4c77c9fc0c3248ab2076 (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
102
103
104
105
106
107
108
109
110
111
112
113
From da6b156014ba0303d1be6ad93180d0bbb3f64dac Mon Sep 17 00:00:00 2001
From: Monk Liu <Monk.Liu@amd.com>
Date: Tue, 11 Apr 2017 17:11:39 +0800
Subject: [PATCH 0797/4131] drm/amdgpu/SEM:some modification on SEM logic

1):Cannot del list on sem->list in sem_free

because you don't have this operation go under the protection
of sem_lock

no reason to del list in sem_free, sem_add_cs will do it, and
even cs_ioctl is never called after sem_wait, it doesn't harm to
leave this list in there.

2):In sem_wait, should get the kref of sem otherwise a sem_desctory
followed by will kill the sem and make all reference to sem invalid
pointer.

should also put the sem in sem_add_cs() to balance the kref.
And should also put the sem in ctx_do_release to balance the kref
of those sem which only do the sem_wait but without cs_submit following.

Change-Id: If3a5ac4757b8acb716cad57ceb60d96d0ff108e0
Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>

 Conflicts:
	drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 17 +++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_sem.c |  5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_sem.h |  1 +
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 6a2a1ce..0f84e4d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -87,11 +87,20 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)
 	if (!adev)
 		return;
 
-	for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
-		for (j = 0; j < amdgpu_sched_jobs; ++j) {
+	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+		struct amdgpu_sem *sem, *tmp;
+
+		mutex_lock(&ctx->rings[i].sem_lock);
+		/* release all the reset inserted SEM here */
+		list_for_each_entry_safe(sem, tmp, &ctx->rings[i].sem_list, list)
+			amdgpu_sem_put(sem);
+
+		mutex_unlock(&ctx->rings[i].sem_lock);
+		mutex_destroy(&ctx->rings[i].sem_lock);
+
+		for (j = 0; j < amdgpu_sched_jobs; ++j)
 			dma_fence_put(ctx->rings[i].fences[j]);
-			mutex_destroy(&ctx->rings[i].sem_lock);
-		}
+	}
 	kfree(ctx->fences);
 	ctx->fences = NULL;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.c
index 6d60e7b..fab6164 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.c
@@ -55,7 +55,6 @@ static void amdgpu_sem_free(struct kref *kref)
 	struct amdgpu_sem *sem = container_of(
 		kref, struct amdgpu_sem, kref);
 
-	list_del(&sem->list);
 	kref_put(&sem->base->kref, amdgpu_sem_core_free);
 	kfree(sem);
 }
@@ -66,7 +65,7 @@ static inline void amdgpu_sem_get(struct amdgpu_sem *sem)
 		kref_get(&sem->kref);
 }
 
-static inline void amdgpu_sem_put(struct amdgpu_sem *sem)
+void amdgpu_sem_put(struct amdgpu_sem *sem)
 {
 	if (sem)
 		kref_put(&sem->kref, amdgpu_sem_free);
@@ -375,6 +374,7 @@ static int amdgpu_sem_cring_add(struct amdgpu_fpriv *fpriv,
 	mutex_lock(&ctx->rings[out_ring->idx].sem_lock);
 	list_add(&sem->list, &ctx->rings[out_ring->idx].sem_list);
 	mutex_unlock(&ctx->rings[out_ring->idx].sem_lock);
+	amdgpu_sem_get(sem);
 
 err:
 	amdgpu_ctx_put(ctx);
@@ -401,6 +401,7 @@ int amdgpu_sem_add_cs(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
 		sem->base->fence = NULL;
 		mutex_unlock(&sem->base->lock);
 		list_del_init(&sem->list);
+		amdgpu_sem_put(sem);
 	}
 err:
 	mutex_unlock(&ctx->rings[ring->idx].sem_lock);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.h
index 40854ff..6a62729 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sem.h
@@ -47,4 +47,5 @@ struct amdgpu_sem {
 	struct list_head        list;
 };
 
+void amdgpu_sem_put(struct amdgpu_sem *sem);
 #endif /* _LINUX_AMDGPU_SEM_H */
-- 
2.7.4