<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:Calibri;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - AMD Internal Distribution Only]<br>
</p>
<br>
<div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Series is:</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com></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> Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Tuesday, June 11, 2024 7:43 AM<br>
<b>To:</b> Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Cc:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> [PATCH 2/2] drm/amdgpu: reject gang submit on reserved VMIDs</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">A gang submit won't work if the VMID is reserved and we can't flush out<br>
VM changes from multiple engines at the same time.<br>
<br>
Signed-off-by: Christian König <christian.koenig@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 15 +++++++++++++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 15 ++++++++++++++-<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h |  1 +<br>
 3 files changed, 30 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
index ec888fc6ead8..916b6b8cf7d9 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
@@ -1093,6 +1093,21 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)<br>
         unsigned int i;<br>
         int r;<br>
 <br>
+       /*<br>
+        * We can't use gang submit on with reserved VMIDs when the VM changes<br>
+        * can't be invalidated by more than one engine at the same time.<br>
+        */<br>
+       if (p->gang_size > 1 && !p->adev->vm_manager.concurrent_flush) {<br>
+               for (i = 0; i < p->gang_size; ++i) {<br>
+                       struct drm_sched_entity *entity = p->entities[i];<br>
+                       struct drm_gpu_scheduler *sched = entity->rq->sched;<br>
+                       struct amdgpu_ring *ring = to_amdgpu_ring(sched);<br>
+<br>
+                       if (amdgpu_vmid_uses_reserved(vm, ring->vm_hub))<br>
+                               return -EINVAL;<br>
+               }<br>
+       }<br>
+<br>
         r = amdgpu_vm_clear_freed(adev, vm, NULL);<br>
         if (r)<br>
                 return r;<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c<br>
index b5b9d4f40f53..b6a8bddada4c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c<br>
@@ -424,7 +424,7 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,<br>
         if (r || !idle)<br>
                 goto error;<br>
 <br>
-       if (vm->reserved_vmid[vmhub] || (enforce_isolation && (vmhub == AMDGPU_GFXHUB(0)))) {<br>
+       if (amdgpu_vmid_uses_reserved(vm, vmhub)) {<br>
                 r = amdgpu_vmid_grab_reserved(vm, ring, job, &id, fence);<br>
                 if (r || !id)<br>
                         goto error;<br>
@@ -474,6 +474,19 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,<br>
         return r;<br>
 }<br>
 <br>
+/*<br>
+ * amdgpu_vmid_uses_reserved - check if a VM will use a reserved VMID<br>
+ * @vm: the VM to check<br>
+ * @vmhub: the VMHUB which will be used<br>
+ *<br>
+ * Returns: True if the VM will use a reserved VMID.<br>
+ */<br>
+bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub)<br>
+{<br>
+       return vm->reserved_vmid[vmhub] ||<br>
+               (enforce_isolation && (vmhub == AMDGPU_GFXHUB(0)));<br>
+}<br>
+<br>
 int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,<br>
                                unsigned vmhub)<br>
 {<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h<br>
index fa8c42c83d5d..240fa6751260 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h<br>
@@ -78,6 +78,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,<br>
 <br>
 bool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev,<br>
                                struct amdgpu_vmid *id);<br>
+bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub);<br>
 int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,<br>
                                 unsigned vmhub);<br>
 void amdgpu_vmid_free_reserved(struct amdgpu_device *adev,<br>
-- <br>
2.34.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>