Skip to contentSkip to conversation

drm/amdgpu: move tlb invalidation to mes sched pipe

PATCH New Alex Deucher 1 participant 3 messages Aug 21

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/3 drm/amdgpu: move tlb invalidation to mes sched pipe

From: Shaoyun Liu <[email protected]>

The heavy weight shootdown need special handling in MES sched pipe

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +3 -2
index 19bbf70e89b78..ba3dd72c56fa7 100644
@@ -572,7 +572,8 @@ static int mes_v12_1_misc_op(struct amdgpu_mes *mes,
 	union MESAPI__MISC misc_pkt;
 	int pipe;
 
-	if (mes->adev->enable_uni_mes)
+	/*OP_WRM_REG_WR_WAIT is used to do tlb invalidation which need to be handled in sched pipe for gfx_12_1.*/
+	if (mes->adev->enable_uni_mes && input->op != MES_MISC_OP_WRM_REG_WR_WAIT)
 		pipe = AMDGPU_MES_KIQ_PIPE;
 	else
 		pipe = AMDGPU_MES_SCHED_PIPE;
@@ -964,7 +965,7 @@ static int mes_v12_1_inv_tlbs_pasid(struct amdgpu_mes *mes,
 	if (ret < 0)
 		return -EINVAL;
 	mes_inv_tlbs.invalidate_tlbs.hub_id = ret;
-	return mes_v12_1_submit_pkt_and_poll_completion(mes, xcc_id, AMDGPU_MES_KIQ_PIPE,
+	return mes_v12_1_submit_pkt_and_poll_completion(mes, xcc_id, AMDGPU_MES_SCHED_PIPE,
 			&mes_inv_tlbs, sizeof(mes_inv_tlbs),
 			offsetof(union MESAPI__INV_TLBS, api_status));
 
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 2/3 drm/amdgpu: Fix MES wb status pointer overwriting adjacent wb slot

From: Philip Yang <[email protected]>

status_ptr was declared as u64 * but the WB allocation is only one u32. Writing through a u64 * pointer zeroed 8 bytes, corrupting the adjacent WB slot. Fix by using u32 * to match the actual allocation size.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +3 -3
index ba3dd72c56fa7..8ff31c924bef2 100644
@@ -167,7 +167,7 @@ static int mes_v12_1_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
 	unsigned long flags;
 	u64 status_gpu_addr;
 	u32 seq, status_offset;
-	u64 *status_ptr;
+	u32 *status_ptr;
 	signed long r;
 	int ret;
 
@@ -186,7 +186,7 @@ static int mes_v12_1_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
 		return ret;
 
 	status_gpu_addr = adev->wb.gpu_addr + (status_offset * 4);
-	status_ptr = (u64 *)&adev->wb.wb[status_offset];
+	status_ptr = &adev->wb.wb[status_offset];
 	*status_ptr = 0;
 
 	spin_lock_irqsave(ring_lock, flags);
@@ -235,7 +235,7 @@ static int mes_v12_1_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
 			xcc_id, pipe, x_pkt->header.opcode);
 
 	r = amdgpu_fence_wait_polling(ring, seq, timeout);
-	if (r < 1 || !lower_32_bits(*status_ptr)) {
+	if (r < 1 || !*status_ptr) {
 		if (misc_op_str)
 			dev_err(adev->dev,
 				"MES(%d, %d) failed to respond to msg=%s (%s)\n",
Signature · 1 line
2.55.0
author maintainer
#2 lore raw

PATCH 3/3 drm/amdkfd: disable debug before retiring MES process context on teardown

In reply to Alex Deucher

From: Alex Sierra <[email protected]>

On process teardown, kfd_process_notifier_release_internal() called kfd_process_dequeue_from_all_devices() (which issues the MES SET_SHADER_DEBUGGER process_ctx_flush=1 that retires the process context) before kfd_dbg_trap_disable(). For a process under a debugger, the debug teardown path (kfd_dbg_trap_disable -> kfd_dbg_trap_deactivate) then issues several SET_SHADER_DEBUGGER process_ctx_flush=0 packets (reset wave launch mode, clear debug flags, reset MES debug mode). Because those packets carry the process_context_addr, MES re-adds the process to its scheduler list after the flush had retired it.

Teardown then frees proc_ctx_bo, and a later MES scheduling pass dereferences the freed process context, producing a GPUVM page fault (vmid 0, GC_UTCL2) on the freed page. This is intermittent because it depends on an MES pass landing on the process before its GART page is reused. It is specific to the debugger path, where queues are added with skip_process_ctx_clear=1 so the last REMOVE_QUEUE does not clear the context and delisting relies on the flush.

Reorder teardown so debug is disabled first, and the process context is flushed/retired last, so nothing re-adds the process after it is retired. kfd_dbg_trap_disable() now runs while queues still exist, which matches the normal live debug-disable ordering.

---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 44 +++++++++++++++---------
 1 file changed, 28 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +28 -16
index 0a7c1900da959..dd938788bdd9a 100644
@@ -1408,23 +1408,16 @@ void kfd_process_notifier_release_internal(struct kfd_process *p)
 		kfd_unref_process(p);
 
 	/*
-	 * Dequeue and destroy user queues, it is not safe for GPU to access
-	 * system memory after mmu release notifier callback returns because
-	 * exit_mmap free process memory afterwards.
+	 * Disable debug BEFORE dequeuing/flushing the MES process context.
+	 *
+	 * kfd_dbg_trap_disable() -> kfd_dbg_trap_deactivate() issues
+	 * SET_SHADER_DEBUGGER (process_ctx_flush=0) packets that re-add the
+	 * process to the MES scheduler list. kfd_process_dequeue_from_all_devices()
+	 * sends the process_ctx_flush=1 that retires the context. If debug
+	 * teardown ran after the dequeue, those packets would put the process
+	 * back on the MES list and, once proc_ctx_bo is freed, MES would fault
+	 * on the freed process context. Retiring the context last avoids this.
 	 */
-	kfd_process_dequeue_from_all_devices(p);
-	pqm_uninit(&p->pqm);
-
-	for (i = 0; i < p->n_pdds; i++) {
-		struct kfd_process_device *pdd = p->pdds[i];
-
-		/* re-enable GFX OFF since runtime enable with ttmp setup disabled it. */
-		if (!kfd_dbg_is_rlc_restore_supported(pdd->dev) && p->runtime_info.ttmp_setup)
-			amdgpu_gfx_off_ctrl(pdd->dev->adev, true);
-	}
-
-	/* Indicate to other users that MM is no longer valid */
-	p->mm = NULL;
 	kfd_dbg_trap_disable(p);
 
 	if (atomic_read(&p->debugged_process_count) > 0) {
@@ -1445,6 +1438,25 @@ void kfd_process_notifier_release_internal(struct kfd_process *p)
 		srcu_read_unlock(&kfd_processes_srcu, idx);
 	}
 
+	/*
+	 * Dequeue and destroy user queues, it is not safe for GPU to access
+	 * system memory after mmu release notifier callback returns because
+	 * exit_mmap free process memory afterwards.
+	 */
+	kfd_process_dequeue_from_all_devices(p);
+	pqm_uninit(&p->pqm);
+
+	for (i = 0; i < p->n_pdds; i++) {
+		struct kfd_process_device *pdd = p->pdds[i];
+
+		/* re-enable GFX OFF since runtime enable with ttmp setup disabled it. */
+		if (!kfd_dbg_is_rlc_restore_supported(pdd->dev) && p->runtime_info.ttmp_setup)
+			amdgpu_gfx_off_ctrl(pdd->dev->adev, true);
+	}
+
+	/* Indicate to other users that MM is no longer valid */
+	p->mm = NULL;
+
 	if (p->context_id == KFD_CONTEXT_ID_PRIMARY)
 		mmu_notifier_put(&p->mmu_notifier);
 }
Signature · 1 line
2.55.0