Skip to contentSkip to conversation

drm/amdgpu: add a missing lock for AMDGPU_SCHED

PATCH Superseded Chia-I Wu 3 participants 4 messages Apr 26, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chia-I Wu

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: add a missing lock for AMDGPU_SCHED

mgr->ctx_handles should be protected by mgr->lock.

v2: improve commit message

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +5 -1
index e9b45089a28a6..863b2a34b2d64 100644
@@ -38,6 +38,7 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
 {
 	struct fd f = fdget(fd);
 	struct amdgpu_fpriv *fpriv;
+	struct amdgpu_ctx_mgr *mgr;
 	struct amdgpu_ctx *ctx;
 	uint32_t id;
 	int r;
@@ -51,8 +52,11 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
 		return r;
 	}
 
-	idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
+	mgr = &fpriv->ctx_mgr;
+	mutex_lock(&mgr->lock);
+	idr_for_each_entry(&mgr->ctx_handles, ctx, id)
 		amdgpu_ctx_priority_override(ctx, priority);
+	mutex_unlock(&mgr->lock);
 
 	fdput(f);
 	return 0;
Signature · 1 line
2.40.1.495.gc816e09b53d-goog
maintainer
#2 lore raw
In reply to Chia-I Wu

Am 26.04.23 um 08:17 schrieb Chia-I Wu:

Quoted 6 lines

mgr->ctx_handles should be protected by mgr->lock.

v2: improve commit message

Please don't manually CC [email protected] while sending patches out, let us maintainers push that upstream with the appropriate tag and Greg picking it up from there.

A Fixes tag and figuring out to which stable versions this needs to be backported are nice to have as well, but Alex and I can take care of that as well.

Apart from that the technical side of the patch is Reviewed-by: Christian König <[email protected]>.

Regards,
Christian.

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +5 -1
index e9b45089a28a6..863b2a34b2d64 100644
@@ -38,6 +38,7 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
  {
  	struct fd f = fdget(fd);
  	struct amdgpu_fpriv *fpriv;
+	struct amdgpu_ctx_mgr *mgr;
  	struct amdgpu_ctx *ctx;
  	uint32_t id;
  	int r;
@@ -51,8 +52,11 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
  		return r;
  	}
 
-	idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
+	mgr = &fpriv->ctx_mgr;
+	mutex_lock(&mgr->lock);
+	idr_for_each_entry(&mgr->ctx_handles, ctx, id)
  		amdgpu_ctx_priority_override(ctx, priority);
+	mutex_unlock(&mgr->lock);
 
  	fdput(f);
  	return 0;
author
#3 lore raw
Quoted 13 lines · Christian König

Am 26.04.23 um 08:17 schrieb Chia-I Wu:

Quoted 6 lines

mgr->ctx_handles should be protected by mgr->lock.

v2: improve commit message

Please don't manually CC [email protected] while sending patches out, let us maintainers push that upstream with the appropriate tag and Greg picking it up from there.

Quoted 6 lines

A Fixes tag and figuring out to which stable versions this needs to be backported are nice to have as well, but Alex and I can take care of that as well.

Apart from that the technical side of the patch is Reviewed-by:
Christian König <[email protected]>.

All done. Thanks for clarifying the process and sorry for getting it wrong in the first place :(

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +5 -1
index e9b45089a28a6..863b2a34b2d64 100644
@@ -38,6 +38,7 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
  {
      struct fd f = fdget(fd);
      struct amdgpu_fpriv *fpriv;
+     struct amdgpu_ctx_mgr *mgr;
      struct amdgpu_ctx *ctx;
      uint32_t id;
      int r;
@@ -51,8 +52,11 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
              return r;
      }
 
-     idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
+     mgr = &fpriv->ctx_mgr;
+     mutex_lock(&mgr->lock);
+     idr_for_each_entry(&mgr->ctx_handles, ctx, id)
              amdgpu_ctx_priority_override(ctx, priority);
+     mutex_unlock(&mgr->lock);
 
      fdput(f);
      return 0;