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.

Signed-off-by: Jesse Zhang <[email protected]>
---
 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(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c
index fea1f2b32b42..6e7ad1411071 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
index 523f65cb3d3d..516840c6fa40 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
@@ -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
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index fff8f1de23ea..e05130dc80ad 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -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;
        }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 5fdaac36b9f3..4be550abab4f 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -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);
-- 
2.50.1

Reply via email to