aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/files/0192-drm-amdgpu-make-the-CTX-ioctl-thread-safe.patch
blob: a638049df4574f7240f2366db726afdbbc45b22c (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
From 0147ee0f5921af606ac0f822107b69b53dd29358 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= <marek.olsak@amd.com>
Date: Tue, 5 May 2015 20:52:00 +0200
Subject: [PATCH 0192/1050] drm/amdgpu: make the CTX ioctl thread-safe
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The existing locks were protecting the list, but not the elements.

v2: rename hlock to lock

Signed-off-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 20 ++++++++++----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 65246abc..cef3a43 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1056,7 +1056,7 @@ struct amdgpu_ctx_mgr {
 	struct amdgpu_device *adev;
 	struct idr ctx_handles;
 	/* lock for IDR system */
-	struct mutex hlock;
+	struct mutex lock;
 };
 
 /*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index ffb13a6..0dc3a4e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -33,9 +33,7 @@ static void amdgpu_ctx_do_release(struct kref *ref)
 	ctx = container_of(ref, struct amdgpu_ctx, refcount);
 	mgr = &ctx->fpriv->ctx_mgr;
 
-	mutex_lock(&mgr->hlock);
 	idr_remove(&mgr->ctx_handles, ctx->id);
-	mutex_unlock(&mgr->hlock);
 	kfree(ctx);
 }
 
@@ -49,20 +47,20 @@ int amdgpu_ctx_alloc(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uin
 	if (!ctx)
 		return -ENOMEM;
 
-	mutex_lock(&mgr->hlock);
+	mutex_lock(&mgr->lock);
 	r = idr_alloc(&mgr->ctx_handles, ctx, 0, 0, GFP_KERNEL);
 	if (r < 0) {
-		mutex_unlock(&mgr->hlock);
+		mutex_unlock(&mgr->lock);
 		kfree(ctx);
 		return r;
 	}
-	mutex_unlock(&mgr->hlock);
 	*id = (uint32_t)r;
 
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->id = *id;
 	ctx->fpriv = fpriv;
 	kref_init(&ctx->refcount);
+	mutex_unlock(&mgr->lock);
 
 	return 0;
 }
@@ -72,13 +70,14 @@ int amdgpu_ctx_free(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uint
 	struct amdgpu_ctx *ctx;
 	struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;
 
-	rcu_read_lock();
+	mutex_lock(&mgr->lock);
 	ctx = idr_find(&mgr->ctx_handles, id);
-	rcu_read_unlock();
 	if (ctx) {
 		kref_put(&ctx->refcount, amdgpu_ctx_do_release);
+		mutex_unlock(&mgr->lock);
 		return 0;
 	}
+	mutex_unlock(&mgr->lock);
 	return -EINVAL;
 }
 
@@ -87,14 +86,15 @@ int amdgpu_ctx_query(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uin
 	struct amdgpu_ctx *ctx;
 	struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;
 
-	rcu_read_lock();
+	mutex_lock(&mgr->lock);
 	ctx = idr_find(&mgr->ctx_handles, id);
-	rcu_read_unlock();
 	if (ctx) {
 		/* state should alter with CS activity */
 		*state = ctx->state;
+		mutex_unlock(&mgr->lock);
 		return 0;
 	}
+	mutex_unlock(&mgr->lock);
 	return -EINVAL;
 }
 
@@ -111,7 +111,7 @@ void amdgpu_ctx_fini(struct amdgpu_fpriv *fpriv)
 			DRM_ERROR("ctx (id=%ul) is still alive\n",ctx->id);
 	}
 
-	mutex_destroy(&mgr->hlock);
+	mutex_destroy(&mgr->lock);
 }
 
 int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 2d50c6d..02c450d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -497,7 +497,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	idr_init(&fpriv->bo_list_handles);
 
 	/* init context manager */
-	mutex_init(&fpriv->ctx_mgr.hlock);
+	mutex_init(&fpriv->ctx_mgr.lock);
 	idr_init(&fpriv->ctx_mgr.ctx_handles);
 	fpriv->ctx_mgr.adev = adev;
 
-- 
1.9.1