Skip to contentSkip to conversation

drm/amdgpu: enable traps for compute user queues with an L2 trap handler on GFX 11.0.x

PATCH In review Jesse Zhang 2 participants 2 messages Nov 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: enable traps for compute user queues with an L2 trap handler on GFX 11.0.x

On GFX 11.0.0-11.0.3 only waves in the first shader array (SA0) of each SE can enter the trap handler, see commit 69a8c3ae2dea ("drm/amdkfd:
apply trap workaround for gfx11"). User queues are mapped with traps disabled there, so a handler installed with AMDGPU_VM_OP_SET_L2_TRAP never runs.

Like KFD does for debug sessions, restrict the compute user queues created while a second-level trap handler is installed to SA0 of each SE through the MQD CU mask, and map them with traps enabled. The decision is made at queue creation and kept across unmap/map.

The MQD mask is only the initial value: COMPUTE_STATIC_THREAD_MGMT_SE* writes from the queue override it, so the UMD must keep its dispatches on SA0 as well.

Also set the mask for SE4-SE7, which were left at 0 and thus disabled SE4/SE5 on Navi31.

GFX user queues are not covered: the GFX11 MES firmware does not program TBA/TMA for the GFX queue VMID.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c   |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h   | 21 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c     |  4 ++++
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 13 ++++++++++++-
 4 files changed, 41 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +4 -0
index fea1f2b32b42..6e7ad1411071 100644
@@ -696,6 +696,8 @@ int amdgpu_trap_vm_set_l2_trap(struct amdgpu_device *adev,
 		goto out_unreserve;
 
 	r = amdgpu_trap_update_l2_handler(trap_obj, tba_va, tma_va);
+	if (!r)
+		trap_obj->l2_trap = true;
 
 out_unreserve:
 	amdgpu_bo_unreserve(vm->root.bo);
@@ -729,6 +731,8 @@ int amdgpu_trap_vm_clear_l2_trap(struct amdgpu_device *adev,
 	}
 
 	r = amdgpu_trap_clear_l2_handler(vm, trap_obj);
+	if (!r)
+		trap_obj->l2_trap = false;
 
 out_unreserve:
 	amdgpu_bo_unreserve(vm->root.bo);
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h +21 -0
index 523f65cb3d3d..516840c6fa40 100644
@@ -45,6 +45,9 @@ struct amdgpu_trap_obj {
 	struct amdgpu_bo *tma_bo;
 	struct amdgpu_bo_va *tba_va;
 	struct amdgpu_bo_va *tma_va;
+
+	/* A second-level trap handler is installed for the GPUVM */
+	bool l2_trap;
 };
 
 struct amdgpu_trap_info {
@@ -107,6 +110,24 @@ static inline bool amdgpu_trap_has_dbg_wa(struct amdgpu_device *adev)
 	       gc_ver <= IP_VERSION(11, 0, 3);
 }
 
+/**
+ * amdgpu_trap_vm_dbg_wa - check if user queues need the trap workaround
+ * @adev: AMDGPU device
+ * @trap_obj: first-level trap object of the GPUVM
+ *
+ * On GFX 11.0.0-11.0.3 only waves in the first shader array of each SE can
+ * enter the trap handler, so traps stay disabled there. Compute user queues
+ * created while the GPUVM has a second-level trap handler are restricted to
+ * the first shader array of each SE instead, and get traps enabled.
+ *
+ * Return: true if new compute user queues of the GPUVM need the workaround.
+ */
+static inline bool amdgpu_trap_vm_dbg_wa(struct amdgpu_device *adev,
+					 struct amdgpu_trap_obj *trap_obj)
+{
+	return amdgpu_trap_has_dbg_wa(adev) && trap_obj && trap_obj->l2_trap;
+}
+
 /**
  * amdgpu_trap_vm_set_l2_trap - install the second-level trap handler
  * @adev: AMDGPU device
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -0
index fff8f1de23ea..e05130dc80ad 100644
@@ -4245,6 +4245,10 @@ static void gfx_v11_0_compute_mqd_set_cu_mask(struct amdgpu_device *adev,
 		mqd->compute_static_thread_mgmt_se1 = wa_mask;
 		mqd->compute_static_thread_mgmt_se2 = wa_mask;
 		mqd->compute_static_thread_mgmt_se3 = wa_mask;
+		mqd->compute_static_thread_mgmt_se4 = wa_mask;
+		mqd->compute_static_thread_mgmt_se5 = wa_mask;
+		mqd->compute_static_thread_mgmt_se6 = wa_mask;
+		mqd->compute_static_thread_mgmt_se7 = wa_mask;
 		return;
 	}
 
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +12 -1
index 5fdaac36b9f3..4be550abab4f 100644
@@ -179,7 +179,13 @@ static int mes_userq_map(struct amdgpu_usermode_queue *queue)
 	if (fpriv->vm.trap_obj) {
 		queue_input.tba_addr = fpriv->vm.trap_obj->tba_gpu_va_addr;
 		queue_input.tma_addr = fpriv->vm.trap_obj->tma_gpu_va_addr;
-		queue_input.trap_en = !amdgpu_trap_has_dbg_wa(adev);
+		/*
+		 * Only the queues restricted to the CUs that can enter the
+		 * trap handler get traps enabled with the workaround.
+		 */
+		queue_input.trap_en = !amdgpu_trap_has_dbg_wa(adev) ||
+			(userq_props->cu_flags &
+			 AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE);
 	}
 
 	if (mes->use_rs64mem) {
@@ -575,6 +581,11 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 			mqd_user->flags &
 			AMDGPU_USERQ_CREATE_FLAGS_QUEUE_AQL_COMPUTE;
 
+		/* Keep the waves where they can enter the trap handler */
+		if (amdgpu_trap_vm_dbg_wa(adev,
+					  uq_mgr_to_fpriv(queue->userq_mgr)->vm.trap_obj))
+			userq_props->cu_flags = AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE;
+
 		if (amdgpu_trap_is_enabled(adev)) {
 			struct amdgpu_fpriv *fpriv =
 				uq_mgr_to_fpriv(queue->userq_mgr);
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 125 lines · Jesse Zhang

On GFX 11.0.0-11.0.3 only waves in the first shader array (SA0) of each SE can enter the trap handler, see commit 69a8c3ae2dea ("drm/amdkfd:
apply trap workaround for gfx11"). User queues are mapped with traps disabled there, so a handler installed with AMDGPU_VM_OP_SET_L2_TRAP never runs.

Like KFD does for debug sessions, restrict the compute user queues created while a second-level trap handler is installed to SA0 of each SE through the MQD CU mask, and map them with traps enabled. The decision is made at queue creation and kept across unmap/map.

The MQD mask is only the initial value: COMPUTE_STATIC_THREAD_MGMT_SE* writes from the queue override it, so the UMD must keep its dispatches on SA0 as well.

Also set the mask for SE4-SE7, which were left at 0 and thus disabled SE4/SE5 on Navi31.

GFX user queues are not covered: the GFX11 MES firmware does not program TBA/TMA for the GFX queue VMID.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c   |  4 ++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h   | 21 +++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c     |  4 ++++
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 13 ++++++++++++-
  4 files changed, 41 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +4 -0
index fea1f2b32b42..6e7ad1411071 100644
@@ -696,6 +696,8 @@ int amdgpu_trap_vm_set_l2_trap(struct amdgpu_device *adev,
  		goto out_unreserve;
 
  	r = amdgpu_trap_update_l2_handler(trap_obj, tba_va, tma_va);
+	if (!r)
+		trap_obj->l2_trap = true;
 
  out_unreserve:
  	amdgpu_bo_unreserve(vm->root.bo);
@@ -729,6 +731,8 @@ int amdgpu_trap_vm_clear_l2_trap(struct amdgpu_device *adev,
  	}
 
  	r = amdgpu_trap_clear_l2_handler(vm, trap_obj);
+	if (!r)
+		trap_obj->l2_trap = false;
 
  out_unreserve:
  	amdgpu_bo_unreserve(vm->root.bo);
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h +21 -0
index 523f65cb3d3d..516840c6fa40 100644
@@ -45,6 +45,9 @@ struct amdgpu_trap_obj {
  	struct amdgpu_bo *tma_bo;
  	struct amdgpu_bo_va *tba_va;
  	struct amdgpu_bo_va *tma_va;
+
+	/* A second-level trap handler is installed for the GPUVM */
+	bool l2_trap;
  };
 
  struct amdgpu_trap_info {
@@ -107,6 +110,24 @@ static inline bool amdgpu_trap_has_dbg_wa(struct amdgpu_device *adev)
  	       gc_ver <= IP_VERSION(11, 0, 3);
  }
 
+/**
+ * amdgpu_trap_vm_dbg_wa - check if user queues need the trap workaround
+ * @adev: AMDGPU device
+ * @trap_obj: first-level trap object of the GPUVM
+ *
+ * On GFX 11.0.0-11.0.3 only waves in the first shader array of each SE can
+ * enter the trap handler, so traps stay disabled there. Compute user queues
+ * created while the GPUVM has a second-level trap handler are restricted to
+ * the first shader array of each SE instead, and get traps enabled.
+ *
+ * Return: true if new compute user queues of the GPUVM need the workaround.
+ */
+static inline bool amdgpu_trap_vm_dbg_wa(struct amdgpu_device *adev,
+					 struct amdgpu_trap_obj *trap_obj)
+{
+	return amdgpu_trap_has_dbg_wa(adev) && trap_obj && trap_obj->l2_trap;
+}
+
  /**
   * amdgpu_trap_vm_set_l2_trap - install the second-level trap handler
   * @adev: AMDGPU device
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -0
index fff8f1de23ea..e05130dc80ad 100644
@@ -4245,6 +4245,10 @@ static void gfx_v11_0_compute_mqd_set_cu_mask(struct amdgpu_device *adev,
  		mqd->compute_static_thread_mgmt_se1 = wa_mask;
  		mqd->compute_static_thread_mgmt_se2 = wa_mask;
  		mqd->compute_static_thread_mgmt_se3 = wa_mask;
+		mqd->compute_static_thread_mgmt_se4 = wa_mask;
+		mqd->compute_static_thread_mgmt_se5 = wa_mask;
+		mqd->compute_static_thread_mgmt_se6 = wa_mask;
+		mqd->compute_static_thread_mgmt_se7 = wa_mask;
  		return;
  	}
 
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +7 -1
index 5fdaac36b9f3..4be550abab4f 100644
@@ -179,7 +179,13 @@ static int mes_userq_map(struct amdgpu_usermode_queue *queue)
  	if (fpriv->vm.trap_obj) {
  		queue_input.tba_addr = fpriv->vm.trap_obj->tba_gpu_va_addr;
  		queue_input.tma_addr = fpriv->vm.trap_obj->tma_gpu_va_addr;
-		queue_input.trap_en = !amdgpu_trap_has_dbg_wa(adev);
+		/*
+		 * Only the queues restricted to the CUs that can enter the
+		 * trap handler get traps enabled with the workaround.
+		 */
+		queue_input.trap_en = !amdgpu_trap_has_dbg_wa(adev) ||
+			(userq_props->cu_flags &
+			 AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE);
  	}
 
  	if (mes->use_rs64mem) {

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, · line 587

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +4 -0
@@ -575,6 +581,11 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
  			mqd_user->flags &
  			AMDGPU_USERQ_CREATE_FLAGS_QUEUE_AQL_COMPUTE;
 
+		/* Keep the waves where they can enter the trap handler */
+		if (amdgpu_trap_vm_dbg_wa(adev,
+					  uq_mgr_to_fpriv(queue->userq_mgr)->vm.trap_obj))
+			userq_props->cu_flags = AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE;

This makes sense to me. Reusing the existing GFX11 workaround path when an L2 trap handler is installed looks like the right approach. Restricting the compute queues to the trap-capable SA0 path should make SLTH behavior consistent on GFX11.0.x, and the SE4-SE7 mask update also looks reasonable.