<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Acked-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Wednesday, February 23, 2022 8:38 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Koenig, Christian <Christian.Koenig@amd.com>; Xue, Ken <Ken.Xue@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdgpu: install ctx entities with cmpxchg</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Since we removed the context lock we need to make sure that not two threads<br>
are trying to install an entity at the same time.<br>
<br>
Signed-off-by: Christian König <christian.koenig@amd.com><br>
Fixes: e68efb27647f ("drm/amdgpu: remove ctx->lock")<br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 +++++++-<br>
 1 file changed, 7 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
index f522b52725e4..16eb1ee600ed 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
@@ -204,9 +204,15 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,<br>
         if (r)<br>
                 goto error_free_entity;<br>
 <br>
-       ctx->entities[hw_ip][ring] = entity;<br>
+       /* It's not an error if we fail to install the new entity */<br>
+       if (cmpxchg(&ctx->entities[hw_ip][ring], NULL, entity))<br>
+               goto cleanup_entity;<br>
+<br>
         return 0;<br>
 <br>
+cleanup_entity:<br>
+       drm_sched_entity_fini(&entity->entity);<br>
+<br>
 error_free_entity:<br>
         kfree(entity);<br>
 <br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>