Skip to contentSkip to conversation

drm/amdgpu: Implement MES Suspend and Resume APIs for GFX11

PATCH Superseded Mukul Joshi 4 participants 12 messages Aug 14, 2024 – Aug 15, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 drm/amdgpu: Implement MES Suspend and Resume APIs for GFX11

Add implementation for MES Suspend and Resume APIs to unmap/map all queues for GFX11. Support for GFX12 will be added when the corresponding firmware support is in place.

---
v1->v2:
- Add MES FW version check.
- Update amdgpu_mes_suspend/amdgpu_mes_resume handling.

 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 71 +++++++++++++------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  | 32 ++++++++++-
 3 files changed, 69 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +37 -34
index c598c3edff7e..e551943da77a 100644
@@ -501,60 +501,50 @@ int amdgpu_mes_remove_gang(struct amdgpu_device *adev, int gang_id)
 
 int amdgpu_mes_suspend(struct amdgpu_device *adev)
 {
-	struct idr *idp;
-	struct amdgpu_mes_process *process;
-	struct amdgpu_mes_gang *gang;
 	struct mes_suspend_gang_input input;
-	int r, pasid;
+	int r;
+
+	if (!amdgpu_mes_suspend_resume_all_supported(adev))
+		return 0;
+
+	memset(&input, 0x0, sizeof(struct mes_suspend_gang_input));
+	input.suspend_all_gangs = 1;
 
 	/*
 	 * Avoid taking any other locks under MES lock to avoid circular
 	 * lock dependencies.
 	 */
 	amdgpu_mes_lock(&adev->mes);
-
-	idp = &adev->mes.pasid_idr;
-
-	idr_for_each_entry(idp, process, pasid) {
-		list_for_each_entry(gang, &process->gang_list, list) {
-			r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
-			if (r)
-				DRM_ERROR("failed to suspend pasid %d gangid %d",
-					 pasid, gang->gang_id);
-		}
-	}
-
+	r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
 	amdgpu_mes_unlock(&adev->mes);
-	return 0;
+	if (r)
+		DRM_ERROR("failed to suspend all gangs");
+
+	return r;
 }
 
 int amdgpu_mes_resume(struct amdgpu_device *adev)
 {
-	struct idr *idp;
-	struct amdgpu_mes_process *process;
-	struct amdgpu_mes_gang *gang;
 	struct mes_resume_gang_input input;
-	int r, pasid;
+	int r;
+
+	if (!amdgpu_mes_suspend_resume_all_supported(adev))
+		return 0;
+
+	memset(&input, 0x0, sizeof(struct mes_resume_gang_input));
+	input.resume_all_gangs = 1;
 
 	/*
 	 * Avoid taking any other locks under MES lock to avoid circular
 	 * lock dependencies.
 	 */
 	amdgpu_mes_lock(&adev->mes);
-
-	idp = &adev->mes.pasid_idr;
-
-	idr_for_each_entry(idp, process, pasid) {
-		list_for_each_entry(gang, &process->gang_list, list) {
-			r = adev->mes.funcs->resume_gang(&adev->mes, &input);
-			if (r)
-				DRM_ERROR("failed to resume pasid %d gangid %d",
-					 pasid, gang->gang_id);
-		}
-	}
-
+	r = adev->mes.funcs->resume_gang(&adev->mes, &input);
 	amdgpu_mes_unlock(&adev->mes);
-	return 0;
+	if (r)
+		DRM_ERROR("failed to resume all gangs");
+
+	return r;
 }
 
 static int amdgpu_mes_queue_alloc_mqd(struct amdgpu_device *adev,
@@ -1608,6 +1598,19 @@ int amdgpu_mes_init_microcode(struct amdgpu_device *adev, int pipe)
 	return r;
 }
 
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
+{
+	uint32_t mes_rev = adev->mes.sched_version & AMDGPU_MES_VERSION_MASK;
+	bool is_supported = false;
+
+	if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(11, 0, 0) &&
+	    amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(12, 0, 0) &&
+	    mes_rev >= 0x63)
+		is_supported = true;
+
+	return is_supported;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +2 -0
index 548e724e3a75..b2db62e50454 100644
@@ -494,4 +494,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
 	memalloc_noreclaim_restore(mes->saved_flags);
 	mutex_unlock(&mes->mutex_hidden);
 }
+
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +30 -2
index c0340ee3dec0..a5c582674db9 100644
@@ -421,13 +421,41 @@ static int mes_v11_0_unmap_legacy_queue(struct amdgpu_mes *mes,
 static int mes_v11_0_suspend_gang(struct amdgpu_mes *mes,
 				  struct mes_suspend_gang_input *input)
 {
-	return 0;
+	union MESAPI__SUSPEND mes_suspend_gang_pkt;
+
+	memset(&mes_suspend_gang_pkt, 0, sizeof(mes_suspend_gang_pkt));
+
+	mes_suspend_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+	mes_suspend_gang_pkt.header.opcode = MES_SCH_API_SUSPEND;
+	mes_suspend_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+	mes_suspend_gang_pkt.suspend_all_gangs = input->suspend_all_gangs;
+	mes_suspend_gang_pkt.gang_context_addr = input->gang_context_addr;
+	mes_suspend_gang_pkt.suspend_fence_addr = input->suspend_fence_addr;
+	mes_suspend_gang_pkt.suspend_fence_value = input->suspend_fence_value;
+
+	return mes_v11_0_submit_pkt_and_poll_completion(mes,
+			&mes_suspend_gang_pkt, sizeof(mes_suspend_gang_pkt),
+			offsetof(union MESAPI__SUSPEND, api_status));
 }
 
 static int mes_v11_0_resume_gang(struct amdgpu_mes *mes,
 				 struct mes_resume_gang_input *input)
 {
-	return 0;
+	union MESAPI__RESUME mes_resume_gang_pkt;
+
+	memset(&mes_resume_gang_pkt, 0, sizeof(mes_resume_gang_pkt));
+
+	mes_resume_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+	mes_resume_gang_pkt.header.opcode = MES_SCH_API_RESUME;
+	mes_resume_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+	mes_resume_gang_pkt.resume_all_gangs = input->resume_all_gangs;
+	mes_resume_gang_pkt.gang_context_addr = input->gang_context_addr;
+
+	return mes_v11_0_submit_pkt_and_poll_completion(mes,
+			&mes_resume_gang_pkt, sizeof(mes_resume_gang_pkt),
+			offsetof(union MESAPI__RESUME, api_status));
 }
 
 static int mes_v11_0_query_sched_status(struct amdgpu_mes *mes)
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 2/3 drm/amdkfd: Update queue unmap after VM fault with MES

MEC FW expects MES to unmap all queues when a VM fault is observed on a queue and then resumed once the affected process is terminated. Use the MES Suspend and Resume APIs to achieve this.

---
v1->v2:
- Add MES FW version check.
- Separate out the kfd_dqm_evict_pasid into another function.
- Use amdgpu_mes_suspend/amdgpu_mes_resume to suspend/resume queues.

 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 79 ++++++++++++++++++-
 1 file changed, 77 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +77 -2
index f6e211070299..cb5b866eee3b 100644
@@ -319,6 +319,42 @@ static int remove_all_queues_mes(struct device_queue_manager *dqm)
 	return retval;
 }
 
+static int suspend_all_queues_mes(struct device_queue_manager *dqm)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+	int r = 0;
+
+	if (dqm->is_hws_hang)
+		return -EIO;
+
+	r = amdgpu_mes_suspend(adev);
+	if (r) {
+		dev_err(adev->dev, "failed to suspend gangs from MES\n");
+		dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+		kfd_hws_hang(dqm);
+	}
+
+	return r;
+}
+
+static int resume_all_queues_mes(struct device_queue_manager *dqm)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+	int r = 0;
+
+	if (dqm->is_hws_hang)
+		return -EIO;
+
+	r = amdgpu_mes_resume(adev);
+	if (r) {
+		dev_err(adev->dev, "failed to resume gangs from MES\n");
+		dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+		kfd_hws_hang(dqm);
+	}
+
+	return r;
+}
+
 static void increment_queue_count(struct device_queue_manager *dqm,
 				  struct qcm_process_device *qpd,
 				  struct queue *q)
@@ -2835,6 +2871,40 @@ void device_queue_manager_uninit(struct device_queue_manager *dqm)
 	kfree(dqm);
 }
 
+static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,
+				   struct qcm_process_device *qpd)
+{
+	struct device *dev = dqm->dev->adev->dev;
+	int ret = 0;
+
+	/* Check if process is already evicted */
+	dqm_lock(dqm);
+	if (qpd->evicted) {
+		dqm_unlock(dqm);
+		goto out;
+	}
+	dqm_unlock(dqm);
+
+	ret = suspend_all_queues_mes(dqm);
+	if (ret) {
+		dev_err(dev, "Suspending all queues failed");
+		goto out;
+	}
+
+	ret = dqm->ops.evict_process_queues(dqm, qpd);
+	if (ret) {
+		dev_err(dev, "Evicting process queues failed");
+		goto out;
+	}
+
+	ret = resume_all_queues_mes(dqm);
+	if (ret)
+		dev_err(dev, "Resuming all queues failed");
+
+out:
+	return ret;
+}
+
 int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
 {
 	struct kfd_process_device *pdd;
@@ -2845,8 +2915,13 @@ int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
 		return -EINVAL;
 	WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);
 	pdd = kfd_get_process_device_data(dqm->dev, p);
-	if (pdd)
-		ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+	if (pdd) {
+		if (dqm->dev->kfd->shared_resources.enable_mes)
+			ret = kfd_dqm_evict_pasid_mes(dqm, &pdd->qpd);
+		else
+			ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+	}
+
 	kfd_unref_process(p);
 
 	return ret;
Signature · 1 line
2.35.1
Acked-by on v2 2/3
#2 lore raw

Re: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

Quoted 6 lines · Mukul Joshi

MEC FW expects MES to unmap all queues when a VM fault is observed on a queue and then resumed once the affected process is terminated. Use the MES Suspend and Resume APIs to achieve this.

Quoted 116 lines

---
v1->v2:
- Add MES FW version check.
- Separate out the kfd_dqm_evict_pasid into another function.
- Use amdgpu_mes_suspend/amdgpu_mes_resume to suspend/resume queues.

 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 79 ++++++++++++++++++-
 1 file changed, 77 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +77 -3
index f6e211070299..cb5b866eee3b 100644
@@ -319,6 +319,42 @@ static int remove_all_queues_mes(struct device_queue_manager *dqm)
        return retval;
 }
 
+static int suspend_all_queues_mes(struct device_queue_manager *dqm)
+{
+       struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+       int r = 0;
+
+       if (dqm->is_hws_hang)
+               return -EIO;
+
+       r = amdgpu_mes_suspend(adev);
+       if (r) {
+               dev_err(adev->dev, "failed to suspend gangs from MES\n");
+               dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+               kfd_hws_hang(dqm);
+       }
+
+       return r;
+}
+
+static int resume_all_queues_mes(struct device_queue_manager *dqm)
+{
+       struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+       int r = 0;
+
+       if (dqm->is_hws_hang)
+               return -EIO;
+
+       r = amdgpu_mes_resume(adev);
+       if (r) {
+               dev_err(adev->dev, "failed to resume gangs from MES\n");
+               dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+               kfd_hws_hang(dqm);
+       }
+
+       return r;
+}
+
 static void increment_queue_count(struct device_queue_manager *dqm,
                                  struct qcm_process_device *qpd,
                                  struct queue *q)
@@ -2835,6 +2871,40 @@ void device_queue_manager_uninit(struct device_queue_manager *dqm)
        kfree(dqm);
 }
 
+static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,
+                                  struct qcm_process_device *qpd)
+{
+       struct device *dev = dqm->dev->adev->dev;
+       int ret = 0;
+
+       /* Check if process is already evicted */
+       dqm_lock(dqm);
+       if (qpd->evicted) {
+               dqm_unlock(dqm);
+               goto out;
+       }
+       dqm_unlock(dqm);
+
+       ret = suspend_all_queues_mes(dqm);
+       if (ret) {
+               dev_err(dev, "Suspending all queues failed");
+               goto out;
+       }
+
+       ret = dqm->ops.evict_process_queues(dqm, qpd);
+       if (ret) {
+               dev_err(dev, "Evicting process queues failed");
+               goto out;
+       }
+
+       ret = resume_all_queues_mes(dqm);
+       if (ret)
+               dev_err(dev, "Resuming all queues failed");
+
+out:
+       return ret;
+}
+
 int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
 {
        struct kfd_process_device *pdd;
@@ -2845,8 +2915,13 @@ int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
                return -EINVAL;
        WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);
        pdd = kfd_get_process_device_data(dqm->dev, p);
-       if (pdd)
-               ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+       if (pdd) {
+               if (dqm->dev->kfd->shared_resources.enable_mes)
+                       ret = kfd_dqm_evict_pasid_mes(dqm, &pdd->qpd);
+               else
+                       ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+       }
+
        kfd_unref_process(p);
 
        return ret;
--

2.35.1

maintainer
#3 lore raw

Re: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

In reply to Mukul Joshi
Quoted 66 lines · Mukul Joshi

MEC FW expects MES to unmap all queues when a VM fault is observed on a queue and then resumed once the affected process is terminated. Use the MES Suspend and Resume APIs to achieve this.

---
v1->v2:
- Add MES FW version check.
- Separate out the kfd_dqm_evict_pasid into another function.
- Use amdgpu_mes_suspend/amdgpu_mes_resume to suspend/resume queues.

  .../drm/amd/amdkfd/kfd_device_queue_manager.c | 79 ++++++++++++++++++-
  1 file changed, 77 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +37 -0
index f6e211070299..cb5b866eee3b 100644
@@ -319,6 +319,42 @@ static int remove_all_queues_mes(struct device_queue_manager *dqm)
  	return retval;
  }
 
+static int suspend_all_queues_mes(struct device_queue_manager *dqm)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+	int r = 0;
+
+	if (dqm->is_hws_hang)
+		return -EIO;
+
+	r = amdgpu_mes_suspend(adev);
+	if (r) {
+		dev_err(adev->dev, "failed to suspend gangs from MES\n");
+		dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+		kfd_hws_hang(dqm);
+	}
+
+	return r;
+}
+
+static int resume_all_queues_mes(struct device_queue_manager *dqm)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+	int r = 0;
+
+	if (dqm->is_hws_hang)
+		return -EIO;
+
+	r = amdgpu_mes_resume(adev);
+	if (r) {
+		dev_err(adev->dev, "failed to resume gangs from MES\n");
+		dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+		kfd_hws_hang(dqm);
+	}
+
+	return r;
+}
+
  static void increment_queue_count(struct device_queue_manager *dqm,
  				  struct qcm_process_device *qpd,
  				  struct queue *q)
@@ -2835,6 +2871,40 @@ void device_queue_manager_uninit(struct device_queue_manager *dqm)
  	kfree(dqm);
  }
 
+static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c void device_queue_manager_uninit(struct device_queue_manager *dqm) · line 2884

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +10 -0
+				   struct qcm_process_device *qpd)
+{
+	struct device *dev = dqm->dev->adev->dev;
+	int ret = 0;
+
+	/* Check if process is already evicted */
+	dqm_lock(dqm);
+	if (qpd->evicted) {
+		dqm_unlock(dqm);
+		goto out;

qpd->evicted is a reference count. Without this shortcut, dqm->ops.evict_process_queues will increment the ref count. You probably need to increment it here before dropping the lock. Otherwise two things can go wrong:

1. The corresponding dqm->ops.restore_process_queues will underflow the reference count
2. A race condition where the queues get restored too early

Regards,
  Felix

Quoted 42 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +30 -2
+	}
+	dqm_unlock(dqm);
+
+	ret = suspend_all_queues_mes(dqm);
+	if (ret) {
+		dev_err(dev, "Suspending all queues failed");
+		goto out;
+	}
+
+	ret = dqm->ops.evict_process_queues(dqm, qpd);
+	if (ret) {
+		dev_err(dev, "Evicting process queues failed");
+		goto out;
+	}
+
+	ret = resume_all_queues_mes(dqm);
+	if (ret)
+		dev_err(dev, "Resuming all queues failed");
+
+out:
+	return ret;
+}
+
  int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
  {
  	struct kfd_process_device *pdd;
@@ -2845,8 +2915,13 @@ int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
  		return -EINVAL;
  	WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);
  	pdd = kfd_get_process_device_data(dqm->dev, p);
-	if (pdd)
-		ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+	if (pdd) {
+		if (dqm->dev->kfd->shared_resources.enable_mes)
+			ret = kfd_dqm_evict_pasid_mes(dqm, &pdd->qpd);
+		else
+			ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+	}
+
  	kfd_unref_process(p);
 
  	return ret;
#4 lore raw

RE: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Felix Kuehling
Sent: Thursday, August 15, 2024 2:25 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

Quoted 19 lines · Mukul Joshi

MEC FW expects MES to unmap all queues when a VM fault is observed on a queue and then resumed once the affected process is terminated. Use the MES Suspend and Resume APIs to achieve this.

---
v1->v2:
- Add MES FW version check.
- Separate out the kfd_dqm_evict_pasid into another function.
- Use amdgpu_mes_suspend/amdgpu_mes_resume to suspend/resume queues.

  .../drm/amd/amdkfd/kfd_device_queue_manager.c | 79 ++++++++++++++++++-
  1 file changed, 77 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -0
index f6e211070299..cb5b866eee3b 100644

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int remove_all_queues_mes(struct device_queue_manager *dqm) · line 328

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +7 -0
@@ -319,6 +319,42 @@ static int remove_all_queues_mes(struct device_queue_manager *dqm)
      return retval;
  }
 
+static int suspend_all_queues_mes(struct device_queue_manager *dqm)
+{
+     struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+     int r = 0;
+
+     if (dqm->is_hws_hang)
+             return -EIO;

This check might need to be reconciled with the following commit. May be check has to be if (!down_read_trylock(&dqm->dev->adev->reset_domain->sem))

                return -EIO;

git show d4ed16fa760e79235ef214318a8389ecedcb9ad6 --stat commit d4ed16fa760e79235ef214318a8389ecedcb9ad6

Author: Yunxiang Li <[email protected]>
Date:   Fri May 24 13:46:50 2024 -0400

drm/amdgpu/kfd: remove is_hws_hang and is_resetting

Quoted 37 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +30 -0
+
+     r = amdgpu_mes_suspend(adev);
+     if (r) {
+             dev_err(adev->dev, "failed to suspend gangs from MES\n");
+             dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+             kfd_hws_hang(dqm);
+     }
+
+     return r;
+}
+
+static int resume_all_queues_mes(struct device_queue_manager *dqm)
+{
+     struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
+     int r = 0;
+
+     if (dqm->is_hws_hang)
+             return -EIO;
+
+     r = amdgpu_mes_resume(adev);
+     if (r) {
+             dev_err(adev->dev, "failed to resume gangs from MES\n");
+             dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
+             kfd_hws_hang(dqm);
+     }
+
+     return r;
+}
+
  static void increment_queue_count(struct device_queue_manager *dqm,
                                struct qcm_process_device *qpd,
                                struct queue *q)
@@ -2835,6 +2871,40 @@ void device_queue_manager_uninit(struct device_queue_manager *dqm)
      kfree(dqm);
  }
 
+static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c void device_queue_manager_uninit(struct device_queue_manager *dqm) · line 2884

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +10 -0
+                                struct qcm_process_device *qpd)
+{
+     struct device *dev = dqm->dev->adev->dev;
+     int ret = 0;
+
+     /* Check if process is already evicted */
+     dqm_lock(dqm);
+     if (qpd->evicted) {
+             dqm_unlock(dqm);
+             goto out;

qpd->evicted is a reference count. Without this shortcut, dqm->ops.evict_process_queues will increment the ref count. You probably need to increment it here before dropping the lock. Otherwise two things can go wrong:

1. The corresponding dqm->ops.restore_process_queues will underflow the reference count
2. A race condition where the queues get restored too early

Regards,
Felix

Quoted 42 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +30 -2
+     }
+     dqm_unlock(dqm);
+
+     ret = suspend_all_queues_mes(dqm);
+     if (ret) {
+             dev_err(dev, "Suspending all queues failed");
+             goto out;
+     }
+
+     ret = dqm->ops.evict_process_queues(dqm, qpd);
+     if (ret) {
+             dev_err(dev, "Evicting process queues failed");
+             goto out;
+     }
+
+     ret = resume_all_queues_mes(dqm);
+     if (ret)
+             dev_err(dev, "Resuming all queues failed");
+
+out:
+     return ret;
+}
+
  int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
  {
      struct kfd_process_device *pdd;
@@ -2845,8 +2915,13 @@ int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
              return -EINVAL;
      WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);
      pdd = kfd_get_process_device_data(dqm->dev, p);
-     if (pdd)
-             ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+     if (pdd) {
+             if (dqm->dev->kfd->shared_resources.enable_mes)
+                     ret = kfd_dqm_evict_pasid_mes(dqm, &pdd->qpd);
+             else
+                     ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+     }
+
      kfd_unref_process(p);
 
      return ret;
#5 lore raw

RE: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

In reply to Felix Kuehling

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Felix,

Quoted 97 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Thursday, August 15, 2024 2:25 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

Quoted 10 lines · Mukul Joshi

MEC FW expects MES to unmap all queues when a VM fault is observed on a queue and then resumed once the affected process is terminated. Use the MES Suspend and Resume APIs to achieve this.

---
v1->v2:
- Add MES FW version check.
- Separate out the kfd_dqm_evict_pasid into another function.
- Use amdgpu_mes_suspend/amdgpu_mes_resume to suspend/resume

queues.

Quoted 2 lines
  .../drm/amd/amdkfd/kfd_device_queue_manager.c | 79

++++++++++++++++++-

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int remove_all_queues_mes(struct

Quoted 8 lines
  1 file changed, 77 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -0
index f6e211070299..cb5b866eee3b 100644
@@ -319,6 +319,42 @@ static int remove_all_queues_mes(struct

device_queue_manager *dqm)

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2 -0
    return retval;
  }
 
+static int suspend_all_queues_mes(struct device_queue_manager *dqm) {
+   struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev-

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int remove_all_queues_mes(struct device_queue_manager *dqm)

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +9 -0
 adev;
+   int r = 0;
+
+   if (dqm->is_hws_hang)
+           return -EIO;
+
+   r = amdgpu_mes_suspend(adev);
+   if (r) {
+           dev_err(adev->dev, "failed to suspend gangs from MES\n");
+           dev_err(adev->dev, "MES might be in unrecoverable state,

issue a GPU reset\n");

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +8 -0
+           kfd_hws_hang(dqm);
+   }
+
+   return r;
+}
+
+static int resume_all_queues_mes(struct device_queue_manager *dqm) {
+   struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev-

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int remove_all_queues_mes(struct device_queue_manager *dqm)

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +9 -0
 adev;
+   int r = 0;
+
+   if (dqm->is_hws_hang)
+           return -EIO;
+
+   r = amdgpu_mes_resume(adev);
+   if (r) {
+           dev_err(adev->dev, "failed to resume gangs from MES\n");
+           dev_err(adev->dev, "MES might be in unrecoverable state,

issue a GPU reset\n");

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c void device_queue_manager_uninit(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -0
+           kfd_hws_hang(dqm);
+   }
+
+   return r;
+}
+
  static void increment_queue_count(struct device_queue_manager *dqm,
                              struct qcm_process_device *qpd,
                              struct queue *q)
@@ -2835,6 +2871,40 @@ void device_queue_manager_uninit(struct

device_queue_manager *dqm)

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c void device_queue_manager_uninit(struct device_queue_manager *dqm) · line 2884

Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +10 -0
    kfree(dqm);
  }
 
+static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,
+                              struct qcm_process_device *qpd) {
+   struct device *dev = dqm->dev->adev->dev;
+   int ret = 0;
+
+   /* Check if process is already evicted */
+   dqm_lock(dqm);
+   if (qpd->evicted) {
+           dqm_unlock(dqm);
+           goto out;

qpd->evicted is a reference count. Without this shortcut, dqm->ops.evict_process_queues will increment the ref count. You probably need to increment it here before dropping the lock. Otherwise two things can go wrong:

Quoted 4 lines

1. The corresponding dqm->ops.restore_process_queues will underflow the reference count
2. A race condition where the queues get restored too early

The intent here is to check if the process queues are already evicted or not. If its not, then we want to suspend all queues, evict all queues (which also updates the evicted refcount) of the affected process, and resume all queues.
If I increment the refcount here, then dqm->ops.evict_process_queues will not evict the queues unless we change that function.
And this function would be called only for the VM fault case, so the process is going to be terminated. Is it possible to have dqm->ops.restore_process_queues called on it? Even if it called, I don't think we can have underflow of the refcount with the current code.

Can you please explain the case where the dqm->ops.restore_process_queues can cause an underflow with the current code? And the scenario for the race?

Regards,
Mukul

Quoted 48 lines

Regards,
Felix

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c int kfd_dqm_evict_pasid(struct

Quoted 27 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +23 -0
+   }
+   dqm_unlock(dqm);
+
+   ret = suspend_all_queues_mes(dqm);
+   if (ret) {
+           dev_err(dev, "Suspending all queues failed");
+           goto out;
+   }
+
+   ret = dqm->ops.evict_process_queues(dqm, qpd);
+   if (ret) {
+           dev_err(dev, "Evicting process queues failed");
+           goto out;
+   }
+
+   ret = resume_all_queues_mes(dqm);
+   if (ret)
+           dev_err(dev, "Resuming all queues failed");
+
+out:
+   return ret;
+}
+
  int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
  {
    struct kfd_process_device *pdd;
@@ -2845,8 +2915,13 @@ int kfd_dqm_evict_pasid(struct

device_queue_manager *dqm, u32 pasid)

Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +7 -2
            return -EINVAL;
    WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);
    pdd = kfd_get_process_device_data(dqm->dev, p);
-   if (pdd)
-           ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+   if (pdd) {
+           if (dqm->dev->kfd->shared_resources.enable_mes)
+                   ret = kfd_dqm_evict_pasid_mes(dqm, &pdd->qpd);
+           else
+                   ret = dqm->ops.evict_process_queues(dqm, &pdd-
 qpd);
+   }
+
    kfd_unref_process(p);
 
    return ret;
maintainer
#6 lore raw

Re: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

Quoted 112 lines · Mukul

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Felix,

Quoted 95 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Thursday, August 15, 2024 2:25 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCHv2 2/3] drm/amdkfd: Update queue unmap after VM fault with MES

Quoted 10 lines · Mukul Joshi

MEC FW expects MES to unmap all queues when a VM fault is observed on a queue and then resumed once the affected process is terminated. Use the MES Suspend and Resume APIs to achieve this.

---
v1->v2:
- Add MES FW version check.
- Separate out the kfd_dqm_evict_pasid into another function.
- Use amdgpu_mes_suspend/amdgpu_mes_resume to suspend/resume

queues.

Quoted 1 line
   .../drm/amd/amdkfd/kfd_device_queue_manager.c | 79

++++++++++++++++++-

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int remove_all_queues_mes(struct

Quoted 8 lines
   1 file changed, 77 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -0
index f6e211070299..cb5b866eee3b 100644
@@ -319,6 +319,42 @@ static int remove_all_queues_mes(struct

device_queue_manager *dqm)

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2 -0
     return retval;
   }
 
+static int suspend_all_queues_mes(struct device_queue_manager *dqm) {
+   struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev-

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int remove_all_queues_mes(struct device_queue_manager *dqm)

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +9 -0
 adev;
+   int r = 0;
+
+   if (dqm->is_hws_hang)
+           return -EIO;
+
+   r = amdgpu_mes_suspend(adev);
+   if (r) {
+           dev_err(adev->dev, "failed to suspend gangs from MES\n");
+           dev_err(adev->dev, "MES might be in unrecoverable state,

issue a GPU reset\n");

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +8 -0
+           kfd_hws_hang(dqm);
+   }
+
+   return r;
+}
+
+static int resume_all_queues_mes(struct device_queue_manager *dqm) {
+   struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev-

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int remove_all_queues_mes(struct device_queue_manager *dqm)

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +9 -0
 adev;
+   int r = 0;
+
+   if (dqm->is_hws_hang)
+           return -EIO;
+
+   r = amdgpu_mes_resume(adev);
+   if (r) {
+           dev_err(adev->dev, "failed to resume gangs from MES\n");
+           dev_err(adev->dev, "MES might be in unrecoverable state,

issue a GPU reset\n");

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c void device_queue_manager_uninit(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -0
+           kfd_hws_hang(dqm);
+   }
+
+   return r;
+}
+
   static void increment_queue_count(struct device_queue_manager *dqm,
                               struct qcm_process_device *qpd,
                               struct queue *q)
@@ -2835,6 +2871,40 @@ void device_queue_manager_uninit(struct

device_queue_manager *dqm)

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c void device_queue_manager_uninit(struct device_queue_manager *dqm) · line 2884

Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +10 -0
     kfree(dqm);
   }
 
+static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,
+                              struct qcm_process_device *qpd) {
+   struct device *dev = dqm->dev->adev->dev;
+   int ret = 0;
+
+   /* Check if process is already evicted */
+   dqm_lock(dqm);
+   if (qpd->evicted) {
+           dqm_unlock(dqm);
+           goto out;

qpd->evicted is a reference count. Without this shortcut, dqm->ops.evict_process_queues will increment the ref count. You probably need to increment it here before dropping the lock. Otherwise two things can go wrong:

Quoted 4 lines

1. The corresponding dqm->ops.restore_process_queues will underflow the reference count
2. A race condition where the queues get restored too early

The intent here is to check if the process queues are already evicted or not. If its not, then we want to suspend all queues, evict all queues (which also updates the evicted refcount) of the affected process, and resume all queues.
If I increment the refcount here, then dqm->ops.evict_process_queues will not evict the queues unless we change that function.
And this function would be called only for the VM fault case, so the process is going to be terminated. Is it possible to have dqm->ops.restore_process_queues called on it? Even if it called, I don't think we can have underflow of the refcount with the current code.

Quoted 2 lines

Can you please explain the case where the dqm->ops.restore_process_queues can cause an underflow with the current code? And the scenario for the race?

On GPUs with MES, you pair kfd_dqm_evict_pasid_mes with dqm->ops.restore_process_queues. For every call of kfd_dqm_evict_pasid_mes there will be a corresponding call of dqm->ops.restore_process_queues. If kfd_dqm_evict_pasid_mes doesn't increment the qpd->evicted refcount for some cases, the refcount will underflow in dqm->ops.restore_process_queues.

Regards,
  Felix

Quoted 53 lines

Regards,
Mukul

Quoted 48 lines

Regards,
Felix

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c int kfd_dqm_evict_pasid(struct

Quoted 27 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +23 -0
+   }
+   dqm_unlock(dqm);
+
+   ret = suspend_all_queues_mes(dqm);
+   if (ret) {
+           dev_err(dev, "Suspending all queues failed");
+           goto out;
+   }
+
+   ret = dqm->ops.evict_process_queues(dqm, qpd);
+   if (ret) {
+           dev_err(dev, "Evicting process queues failed");
+           goto out;
+   }
+
+   ret = resume_all_queues_mes(dqm);
+   if (ret)
+           dev_err(dev, "Resuming all queues failed");
+
+out:
+   return ret;
+}
+
   int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid)
   {
     struct kfd_process_device *pdd;
@@ -2845,8 +2915,13 @@ int kfd_dqm_evict_pasid(struct

device_queue_manager *dqm, u32 pasid)

Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +7 -2
             return -EINVAL;
     WARN(debug_evictions, "Evicting pid %d", p->lead_thread->pid);
     pdd = kfd_get_process_device_data(dqm->dev, p);
-   if (pdd)
-           ret = dqm->ops.evict_process_queues(dqm, &pdd->qpd);
+   if (pdd) {
+           if (dqm->dev->kfd->shared_resources.enable_mes)
+                   ret = kfd_dqm_evict_pasid_mes(dqm, &pdd->qpd);
+           else
+                   ret = dqm->ops.evict_process_queues(dqm, &pdd-
 qpd);
+   }
+
     kfd_unref_process(p);
 
     return ret;
#7 lore raw

PATCH v2 3/3 drm/amdkfd: Update BadOpcode Interrupt handling with MES

In reply to Mukul Joshi

Based on the recommendation of MEC FW, update BadOpcode interrupt handling by unmapping all queues, removing the queue that got the interrupt from scheduling and remapping rest of the queues back when using MES scheduler. This is done to prevent the case where unmapping of the bad queue can fail thereby causing a GPU reset.

---
v1->v2:
- No change.

 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 51 +++++++++++++++++++
 .../gpu/drm/amd/amdkfd/kfd_int_process_v11.c  |  9 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  1 +
 3 files changed, 58 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +51 -0
index cb5b866eee3b..67b97d86e65e 100644
@@ -2871,6 +2871,57 @@ void device_queue_manager_uninit(struct device_queue_manager *dqm)
 	kfree(dqm);
 }
 
+int kfd_dqm_suspend_bad_queue_mes(struct kfd_node *knode, u32 pasid, u32 doorbell_id)
+{
+	struct kfd_process_device *pdd;
+	struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+	struct device_queue_manager *dqm = knode->dqm;
+	struct device *dev = dqm->dev->adev->dev;
+	struct qcm_process_device *qpd;
+	struct queue *q = NULL;
+	int ret = 0;
+
+	if (!p)
+		return -EINVAL;
+
+	dqm_lock(dqm);
+
+	pdd = kfd_get_process_device_data(dqm->dev, p);
+	if (pdd) {
+		qpd = &pdd->qpd;
+
+		list_for_each_entry(q, &qpd->queues_list, list) {
+			if (q->doorbell_id == doorbell_id && q->properties.is_active) {
+				ret = suspend_all_queues_mes(dqm);
+				if (ret) {
+					dev_err(dev, "Suspending all queues failed");
+					goto out;
+				}
+
+				q->properties.is_evicted = true;
+				q->properties.is_active = false;
+				decrement_queue_count(dqm, qpd, q);
+
+				ret = remove_queue_mes(dqm, q, qpd);
+				if (ret) {
+					dev_err(dev, "Removing bad queue failed");
+					goto out;
+				}
+
+				ret = resume_all_queues_mes(dqm);
+				if (ret)
+					dev_err(dev, "Resuming all queues failed");
+
+				break;
+			}
+		}
+	}
+
+out:
+	dqm_unlock(dqm);
+	return ret;
+}
+
 static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,
 				   struct qcm_process_device *qpd)
 {
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v11.c +6 -3
index f524a55eee11..b3f988b275a8 100644
@@ -330,11 +330,14 @@ static void event_interrupt_wq_v11(struct kfd_node *dev,
 		if (source_id == SOC15_INTSRC_CP_END_OF_PIPE)
 			kfd_signal_event_interrupt(pasid, context_id0, 32);
 		else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE &&
-			 KFD_DBG_EC_TYPE_IS_PACKET(KFD_CTXID0_CP_BAD_OP_ECODE(context_id0)))
-			kfd_set_dbg_ev_from_interrupt(dev, pasid,
-				KFD_CTXID0_DOORBELL_ID(context_id0),
+			 KFD_DBG_EC_TYPE_IS_PACKET(KFD_CTXID0_CP_BAD_OP_ECODE(context_id0))) {
+			u32 doorbell_id = KFD_CTXID0_DOORBELL_ID(context_id0);
+
+			kfd_set_dbg_ev_from_interrupt(dev, pasid, doorbell_id,
 				KFD_EC_MASK(KFD_CTXID0_CP_BAD_OP_ECODE(context_id0)),
 				NULL, 0);
+			kfd_dqm_suspend_bad_queue_mes(dev, pasid, doorbell_id);
+		}
 
 		/* SDMA */
 		else if (source_id == SOC21_INTSRC_SDMA_TRAP)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
index f7c12d4f0abb..7bba6bed2f48 100644
@@ -1324,6 +1324,7 @@ struct kernel_queue *kernel_queue_init(struct kfd_node *dev,
 					enum kfd_queue_type type);
 void kernel_queue_uninit(struct kernel_queue *kq);
 int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid);
+int kfd_dqm_suspend_bad_queue_mes(struct kfd_node *knode, u32 pasid, u32 doorbell_id);
 
 /* Process Queue Manager */
 struct process_queue_node {
Signature · 1 line
2.35.1
Acked-by on v2 3/3
#8 lore raw

Re: [PATCHv2 3/3] drm/amdkfd: Update BadOpcode Interrupt handling with MES

Quoted 9 lines · Mukul Joshi

Based on the recommendation of MEC FW, update BadOpcode interrupt handling by unmapping all queues, removing the queue that got the interrupt from scheduling and remapping rest of the queues back when using MES scheduler. This is done to prevent the case where unmapping of the bad queue can fail thereby causing a GPU reset.

Quoted 108 lines

---
v1->v2:
- No change.

 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 51 +++++++++++++++++++
 .../gpu/drm/amd/amdkfd/kfd_int_process_v11.c  |  9 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  1 +
 3 files changed, 58 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +51 -0
index cb5b866eee3b..67b97d86e65e 100644
@@ -2871,6 +2871,57 @@ void device_queue_manager_uninit(struct device_queue_manager *dqm)
        kfree(dqm);
 }
 
+int kfd_dqm_suspend_bad_queue_mes(struct kfd_node *knode, u32 pasid, u32 doorbell_id)
+{
+       struct kfd_process_device *pdd;
+       struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
+       struct device_queue_manager *dqm = knode->dqm;
+       struct device *dev = dqm->dev->adev->dev;
+       struct qcm_process_device *qpd;
+       struct queue *q = NULL;
+       int ret = 0;
+
+       if (!p)
+               return -EINVAL;
+
+       dqm_lock(dqm);
+
+       pdd = kfd_get_process_device_data(dqm->dev, p);
+       if (pdd) {
+               qpd = &pdd->qpd;
+
+               list_for_each_entry(q, &qpd->queues_list, list) {
+                       if (q->doorbell_id == doorbell_id && q->properties.is_active) {
+                               ret = suspend_all_queues_mes(dqm);
+                               if (ret) {
+                                       dev_err(dev, "Suspending all queues failed");
+                                       goto out;
+                               }
+
+                               q->properties.is_evicted = true;
+                               q->properties.is_active = false;
+                               decrement_queue_count(dqm, qpd, q);
+
+                               ret = remove_queue_mes(dqm, q, qpd);
+                               if (ret) {
+                                       dev_err(dev, "Removing bad queue failed");
+                                       goto out;
+                               }
+
+                               ret = resume_all_queues_mes(dqm);
+                               if (ret)
+                                       dev_err(dev, "Resuming all queues failed");
+
+                               break;
+                       }
+               }
+       }
+
+out:
+       dqm_unlock(dqm);
+       return ret;
+}
+
 static int kfd_dqm_evict_pasid_mes(struct device_queue_manager *dqm,
                                   struct qcm_process_device *qpd)
 {
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v11.c +6 -3
index f524a55eee11..b3f988b275a8 100644
@@ -330,11 +330,14 @@ static void event_interrupt_wq_v11(struct kfd_node *dev,
                if (source_id == SOC15_INTSRC_CP_END_OF_PIPE)
                        kfd_signal_event_interrupt(pasid, context_id0, 32);
                else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE &&
-                        KFD_DBG_EC_TYPE_IS_PACKET(KFD_CTXID0_CP_BAD_OP_ECODE(context_id0)))
-                       kfd_set_dbg_ev_from_interrupt(dev, pasid,
-                               KFD_CTXID0_DOORBELL_ID(context_id0),
+                        KFD_DBG_EC_TYPE_IS_PACKET(KFD_CTXID0_CP_BAD_OP_ECODE(context_id0))) {
+                       u32 doorbell_id = KFD_CTXID0_DOORBELL_ID(context_id0);
+
+                       kfd_set_dbg_ev_from_interrupt(dev, pasid, doorbell_id,
                                KFD_EC_MASK(KFD_CTXID0_CP_BAD_OP_ECODE(context_id0)),
                                NULL, 0);
+                       kfd_dqm_suspend_bad_queue_mes(dev, pasid, doorbell_id);
+               }
 
                /* SDMA */
                else if (source_id == SOC21_INTSRC_SDMA_TRAP)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
index f7c12d4f0abb..7bba6bed2f48 100644
@@ -1324,6 +1324,7 @@ struct kernel_queue *kernel_queue_init(struct kfd_node *dev,
                                        enum kfd_queue_type type);
 void kernel_queue_uninit(struct kernel_queue *kq);
 int kfd_dqm_evict_pasid(struct device_queue_manager *dqm, u32 pasid);
+int kfd_dqm_suspend_bad_queue_mes(struct kfd_node *knode, u32 pasid, u32 doorbell_id);
 
 /* Process Queue Manager */
 struct process_queue_node {
--

2.35.1

Reviewed-by on v2 1/3
#9 lore raw
In reply to Mukul Joshi
Quoted 6 lines · Mukul Joshi

Add implementation for MES Suspend and Resume APIs to unmap/map all queues for GFX11. Support for GFX12 will be added when the corresponding firmware support is in place.

Quoted 181 lines

---
v1->v2:
- Add MES FW version check.
- Update amdgpu_mes_suspend/amdgpu_mes_resume handling.

 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 71 +++++++++++++------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  | 32 ++++++++++-
 3 files changed, 69 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +37 -34
index c598c3edff7e..e551943da77a 100644
@@ -501,60 +501,50 @@ int amdgpu_mes_remove_gang(struct amdgpu_device *adev, int gang_id)
 
 int amdgpu_mes_suspend(struct amdgpu_device *adev)
 {
-       struct idr *idp;
-       struct amdgpu_mes_process *process;
-       struct amdgpu_mes_gang *gang;
        struct mes_suspend_gang_input input;
-       int r, pasid;
+       int r;
+
+       if (!amdgpu_mes_suspend_resume_all_supported(adev))
+               return 0;
+
+       memset(&input, 0x0, sizeof(struct mes_suspend_gang_input));
+       input.suspend_all_gangs = 1;
 
        /*
         * Avoid taking any other locks under MES lock to avoid circular
         * lock dependencies.
         */
        amdgpu_mes_lock(&adev->mes);
-
-       idp = &adev->mes.pasid_idr;
-
-       idr_for_each_entry(idp, process, pasid) {
-               list_for_each_entry(gang, &process->gang_list, list) {
-                       r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
-                       if (r)
-                               DRM_ERROR("failed to suspend pasid %d gangid %d",
-                                        pasid, gang->gang_id);
-               }
-       }
-
+       r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
        amdgpu_mes_unlock(&adev->mes);
-       return 0;
+       if (r)
+               DRM_ERROR("failed to suspend all gangs");
+
+       return r;
 }
 
 int amdgpu_mes_resume(struct amdgpu_device *adev)
 {
-       struct idr *idp;
-       struct amdgpu_mes_process *process;
-       struct amdgpu_mes_gang *gang;
        struct mes_resume_gang_input input;
-       int r, pasid;
+       int r;
+
+       if (!amdgpu_mes_suspend_resume_all_supported(adev))
+               return 0;
+
+       memset(&input, 0x0, sizeof(struct mes_resume_gang_input));
+       input.resume_all_gangs = 1;
 
        /*
         * Avoid taking any other locks under MES lock to avoid circular
         * lock dependencies.
         */
        amdgpu_mes_lock(&adev->mes);
-
-       idp = &adev->mes.pasid_idr;
-
-       idr_for_each_entry(idp, process, pasid) {
-               list_for_each_entry(gang, &process->gang_list, list) {
-                       r = adev->mes.funcs->resume_gang(&adev->mes, &input);
-                       if (r)
-                               DRM_ERROR("failed to resume pasid %d gangid %d",
-                                        pasid, gang->gang_id);
-               }
-       }
-
+       r = adev->mes.funcs->resume_gang(&adev->mes, &input);
        amdgpu_mes_unlock(&adev->mes);
-       return 0;
+       if (r)
+               DRM_ERROR("failed to resume all gangs");
+
+       return r;
 }
 
 static int amdgpu_mes_queue_alloc_mqd(struct amdgpu_device *adev,
@@ -1608,6 +1598,19 @@ int amdgpu_mes_init_microcode(struct amdgpu_device *adev, int pipe)
        return r;
 }
 
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
+{
+       uint32_t mes_rev = adev->mes.sched_version & AMDGPU_MES_VERSION_MASK;
+       bool is_supported = false;
+
+       if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(11, 0, 0) &&
+           amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(12, 0, 0) &&
+           mes_rev >= 0x63)
+               is_supported = true;
+
+       return is_supported;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +2 -0
index 548e724e3a75..b2db62e50454 100644
@@ -494,4 +494,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
        memalloc_noreclaim_restore(mes->saved_flags);
        mutex_unlock(&mes->mutex_hidden);
 }
+
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +30 -3
index c0340ee3dec0..a5c582674db9 100644
@@ -421,13 +421,41 @@ static int mes_v11_0_unmap_legacy_queue(struct amdgpu_mes *mes,
 static int mes_v11_0_suspend_gang(struct amdgpu_mes *mes,
                                  struct mes_suspend_gang_input *input)
 {
-       return 0;
+       union MESAPI__SUSPEND mes_suspend_gang_pkt;
+
+       memset(&mes_suspend_gang_pkt, 0, sizeof(mes_suspend_gang_pkt));
+
+       mes_suspend_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+       mes_suspend_gang_pkt.header.opcode = MES_SCH_API_SUSPEND;
+       mes_suspend_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_suspend_gang_pkt.suspend_all_gangs = input->suspend_all_gangs;
+       mes_suspend_gang_pkt.gang_context_addr = input->gang_context_addr;
+       mes_suspend_gang_pkt.suspend_fence_addr = input->suspend_fence_addr;
+       mes_suspend_gang_pkt.suspend_fence_value = input->suspend_fence_value;
+
+       return mes_v11_0_submit_pkt_and_poll_completion(mes,
+                       &mes_suspend_gang_pkt, sizeof(mes_suspend_gang_pkt),
+                       offsetof(union MESAPI__SUSPEND, api_status));
 }
 
 static int mes_v11_0_resume_gang(struct amdgpu_mes *mes,
                                 struct mes_resume_gang_input *input)
 {
-       return 0;
+       union MESAPI__RESUME mes_resume_gang_pkt;
+
+       memset(&mes_resume_gang_pkt, 0, sizeof(mes_resume_gang_pkt));
+
+       mes_resume_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+       mes_resume_gang_pkt.header.opcode = MES_SCH_API_RESUME;
+       mes_resume_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_resume_gang_pkt.resume_all_gangs = input->resume_all_gangs;
+       mes_resume_gang_pkt.gang_context_addr = input->gang_context_addr;
+
+       return mes_v11_0_submit_pkt_and_poll_completion(mes,
+                       &mes_resume_gang_pkt, sizeof(mes_resume_gang_pkt),
+                       offsetof(union MESAPI__RESUME, api_status));
 }
 
 static int mes_v11_0_query_sched_status(struct amdgpu_mes *mes)
--

2.35.1

#10 lore raw
In reply to Mukul Joshi

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mukul Joshi
Sent: Wednesday, August 14, 2024 7:28 PM
To: [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: [PATCHv2 1/3] drm/amdgpu: Implement MES Suspend and Resume APIs for GFX11

Add implementation for MES Suspend and Resume APIs to unmap/map all queues for GFX11. Support for GFX12 will be added when the corresponding firmware support is in place.

---
v1->v2:
- Add MES FW version check.
- Update amdgpu_mes_suspend/amdgpu_mes_resume handling.

 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 71 +++++++++++++------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  | 32 ++++++++++-
 3 files changed, 69 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +37 -34
index c598c3edff7e..e551943da77a 100644
@@ -501,60 +501,50 @@ int amdgpu_mes_remove_gang(struct amdgpu_device *adev, int gang_id)
 
 int amdgpu_mes_suspend(struct amdgpu_device *adev)
 {
-       struct idr *idp;
-       struct amdgpu_mes_process *process;
-       struct amdgpu_mes_gang *gang;
        struct mes_suspend_gang_input input;
-       int r, pasid;
+       int r;
+
+       if (!amdgpu_mes_suspend_resume_all_supported(adev))
+               return 0;
+
+       memset(&input, 0x0, sizeof(struct mes_suspend_gang_input));
+       input.suspend_all_gangs = 1;
 
        /*
         * Avoid taking any other locks under MES lock to avoid circular
         * lock dependencies.
         */
        amdgpu_mes_lock(&adev->mes);
-
-       idp = &adev->mes.pasid_idr;
-
-       idr_for_each_entry(idp, process, pasid) {
-               list_for_each_entry(gang, &process->gang_list, list) {
-                       r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
-                       if (r)
-                               DRM_ERROR("failed to suspend pasid %d gangid %d",
-                                        pasid, gang->gang_id);
-               }
-       }
-
+       r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
        amdgpu_mes_unlock(&adev->mes);
-       return 0;
+       if (r)
+               DRM_ERROR("failed to suspend all gangs");
+
+       return r;
 }
 
 int amdgpu_mes_resume(struct amdgpu_device *adev)
 {
-       struct idr *idp;
-       struct amdgpu_mes_process *process;
-       struct amdgpu_mes_gang *gang;
        struct mes_resume_gang_input input;
-       int r, pasid;
+       int r;
+
+       if (!amdgpu_mes_suspend_resume_all_supported(adev))
+               return 0;
+
+       memset(&input, 0x0, sizeof(struct mes_resume_gang_input));
+       input.resume_all_gangs = 1;
 
        /*
         * Avoid taking any other locks under MES lock to avoid circular
         * lock dependencies.
         */
        amdgpu_mes_lock(&adev->mes);
-
-       idp = &adev->mes.pasid_idr;
-
-       idr_for_each_entry(idp, process, pasid) {
-               list_for_each_entry(gang, &process->gang_list, list) {
-                       r = adev->mes.funcs->resume_gang(&adev->mes, &input);
-                       if (r)
-                               DRM_ERROR("failed to resume pasid %d gangid %d",
-                                        pasid, gang->gang_id);
-               }
-       }
-
+       r = adev->mes.funcs->resume_gang(&adev->mes, &input);
        amdgpu_mes_unlock(&adev->mes);
-       return 0;
+       if (r)
+               DRM_ERROR("failed to resume all gangs");
+
+       return r;
 }
 
 static int amdgpu_mes_queue_alloc_mqd(struct amdgpu_device *adev,
@@ -1608,6 +1598,19 @@ int amdgpu_mes_init_microcode(struct amdgpu_device *adev, int pipe)
        return r;
 }
 
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)
+{
+       uint32_t mes_rev = adev->mes.sched_version & AMDGPU_MES_VERSION_MASK;
+       bool is_supported = false;
+
+       if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(11, 0, 0) &&
+           amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(12, 0, 0) &&
+           mes_rev >= 0x63)
+               is_supported = true;
+
+       return is_supported;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +2 -0
index 548e724e3a75..b2db62e50454 100644
@@ -494,4 +494,6 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)
        memalloc_noreclaim_restore(mes->saved_flags);
        mutex_unlock(&mes->mutex_hidden);
 }
+
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev);
 #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +9 -1
index c0340ee3dec0..a5c582674db9 100644
@@ -421,13 +421,41 @@ static int mes_v11_0_unmap_legacy_queue(struct amdgpu_mes *mes,
 static int mes_v11_0_suspend_gang(struct amdgpu_mes *mes,
                                  struct mes_suspend_gang_input *input)
 {
-       return 0;
+       union MESAPI__SUSPEND mes_suspend_gang_pkt;
+
+       memset(&mes_suspend_gang_pkt, 0, sizeof(mes_suspend_gang_pkt));
+
+       mes_suspend_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+       mes_suspend_gang_pkt.header.opcode = MES_SCH_API_SUSPEND;
+       mes_suspend_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_suspend_gang_pkt.suspend_all_gangs = input->suspend_all_gangs;
 

Only suspend_all_gangs and resume_all_gangs are set by the caller. None of the variables below are set by caller. Is that ok?

+       mes_suspend_gang_pkt.gang_context_addr = input->gang_context_addr;
+       mes_suspend_gang_pkt.suspend_fence_addr = input->suspend_fence_addr;
+       mes_suspend_gang_pkt.suspend_fence_value = input->suspend_fence_value;

+
+ return mes_v11_0_submit_pkt_and_poll_completion(mes,
+ &mes_suspend_gang_pkt, sizeof(mes_suspend_gang_pkt),
+ offsetof(union MESAPI__SUSPEND, api_status));
}

static int mes_v11_0_resume_gang(struct amdgpu_mes *mes,
struct mes_resume_gang_input *input)
{
- return 0;
+ union MESAPI__RESUME mes_resume_gang_pkt;
+
+ memset(&mes_resume_gang_pkt, 0, sizeof(mes_resume_gang_pkt));
+

+       mes_resume_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+       mes_resume_gang_pkt.header.opcode = MES_SCH_API_RESUME;
+       mes_resume_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;

+
+ mes_resume_gang_pkt.resume_all_gangs = input->resume_all_gangs;
+ mes_resume_gang_pkt.gang_context_addr = input->gang_context_addr;
+
+ return mes_v11_0_submit_pkt_and_poll_completion(mes,
+ &mes_resume_gang_pkt, sizeof(mes_resume_gang_pkt),
+ offsetof(union MESAPI__RESUME, api_status));
}

static int mes_v11_0_query_sched_status(struct amdgpu_mes *mes)
--
2.35.1

#11 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 181 lines

-----Original Message-----
From: Kasiviswanathan, Harish <[email protected]>
Sent: Thursday, August 15, 2024 4:32 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: RE: [PATCHv2 1/3] drm/amdgpu: Implement MES Suspend and Resume APIs for GFX11

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mukul Joshi
Sent: Wednesday, August 14, 2024 7:28 PM
To: [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: [PATCHv2 1/3] drm/amdgpu: Implement MES Suspend and Resume APIs for GFX11

Add implementation for MES Suspend and Resume APIs to unmap/map all queues for GFX11. Support for GFX12 will be added when the corresponding firmware support is in place.

---
v1->v2:
- Add MES FW version check.
- Update amdgpu_mes_suspend/amdgpu_mes_resume handling.

 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 71 +++++++++++++--------
----  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  2 +
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c  | 32 ++++++++++-
 3 files changed, 69 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +24 -34
index c598c3edff7e..e551943da77a 100644
@@ -501,60 +501,50 @@ int amdgpu_mes_remove_gang(struct
 amdgpu_device *adev, int gang_id)
 
 int amdgpu_mes_suspend(struct amdgpu_device *adev)  {
-       struct idr *idp;
-       struct amdgpu_mes_process *process;
-       struct amdgpu_mes_gang *gang;
        struct mes_suspend_gang_input input;
-       int r, pasid;
+       int r;
+
+       if (!amdgpu_mes_suspend_resume_all_supported(adev))
+               return 0;
+
+       memset(&input, 0x0, sizeof(struct mes_suspend_gang_input));
+       input.suspend_all_gangs = 1;
 
        /*
         * Avoid taking any other locks under MES lock to avoid circular
         * lock dependencies.
         */
        amdgpu_mes_lock(&adev->mes);
-
-       idp = &adev->mes.pasid_idr;
-
-       idr_for_each_entry(idp, process, pasid) {
-               list_for_each_entry(gang, &process->gang_list, list) {
-                       r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
-                       if (r)
-                               DRM_ERROR("failed to suspend pasid %d gangid %d",
-                                        pasid, gang->gang_id);
-               }
-       }
-
+       r = adev->mes.funcs->suspend_gang(&adev->mes, &input);
        amdgpu_mes_unlock(&adev->mes);
-       return 0;
+       if (r)
+               DRM_ERROR("failed to suspend all gangs");
+
+       return r;
 }
 
 int amdgpu_mes_resume(struct amdgpu_device *adev)  {
-       struct idr *idp;
-       struct amdgpu_mes_process *process;
-       struct amdgpu_mes_gang *gang;
        struct mes_resume_gang_input input;
-       int r, pasid;
+       int r;
+
+       if (!amdgpu_mes_suspend_resume_all_supported(adev))
+               return 0;
+
+       memset(&input, 0x0, sizeof(struct mes_resume_gang_input));
+       input.resume_all_gangs = 1;
 
        /*
         * Avoid taking any other locks under MES lock to avoid circular
         * lock dependencies.
         */
        amdgpu_mes_lock(&adev->mes);
-
-       idp = &adev->mes.pasid_idr;
-
-       idr_for_each_entry(idp, process, pasid) {
-               list_for_each_entry(gang, &process->gang_list, list) {
-                       r = adev->mes.funcs->resume_gang(&adev->mes, &input);
-                       if (r)
-                               DRM_ERROR("failed to resume pasid %d gangid %d",
-                                        pasid, gang->gang_id);
-               }
-       }
-
+       r = adev->mes.funcs->resume_gang(&adev->mes, &input);
        amdgpu_mes_unlock(&adev->mes);
-       return 0;
+       if (r)
+               DRM_ERROR("failed to resume all gangs");
+
+       return r;
 }
 
 static int amdgpu_mes_queue_alloc_mqd(struct amdgpu_device *adev, @@ -

1608,6 +1598,19 @@ int amdgpu_mes_init_microcode(struct amdgpu_device *adev, int pipe)

        return r;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +3 -0
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device
+*adev) {
+       uint32_t mes_rev = adev->mes.sched_version &

AMDGPU_MES_VERSION_MASK;

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +10 -0
+       bool is_supported = false;
+
+       if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(11, 0, 0) &&
+           amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(12, 0, 0) &&
+           mes_rev >= 0x63)
+               is_supported = true;
+
+       return is_supported;
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void

*unused) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h
index 548e724e3a75..b2db62e50454 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
@@ -494,4 +494,6 @@ static inline void amdgpu_mes_unlock(struct
 amdgpu_mes *mes)
        memalloc_noreclaim_restore(mes->saved_flags);
        mutex_unlock(&mes->mutex_hidden);  }
+
+bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device
+*adev);
 #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
index c0340ee3dec0..a5c582674db9 100644
@@ -421,13 +421,41 @@ static int mes_v11_0_unmap_legacy_queue(struct

amdgpu_mes *mes, static int mes_v11_0_suspend_gang(struct amdgpu_mes *mes,

                                  struct mes_suspend_gang_input *input)  {
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +10 -1
-       return 0;
+       union MESAPI__SUSPEND mes_suspend_gang_pkt;
+
+       memset(&mes_suspend_gang_pkt, 0, sizeof(mes_suspend_gang_pkt));
+
+       mes_suspend_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+       mes_suspend_gang_pkt.header.opcode = MES_SCH_API_SUSPEND;
+       mes_suspend_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_suspend_gang_pkt.suspend_all_gangs =
+ input->suspend_all_gangs;
Quoted 2 lines

Only suspend_all_gangs and resume_all_gangs are set by the caller. None of the variables below are set by caller. Is that ok?

Yes that is fine. The callers of these suspend/resume functions will set the appropriate values based on the need.
For our case, we need to suspend and resume all queues. Hence, the callers set suspend_all_gangs and resume_all_gangs=1.

Thanks,
Mukul

Quoted 37 lines

+ mes_suspend_gang_pkt.gang_context_addr = input-

Quoted 1 line

gang_context_addr;

+ mes_suspend_gang_pkt.suspend_fence_addr = input-

Quoted 1 line

suspend_fence_addr;

drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +21 -2
+       mes_suspend_gang_pkt.suspend_fence_value =
+ input->suspend_fence_value;
+
+       return mes_v11_0_submit_pkt_and_poll_completion(mes,
+                       &mes_suspend_gang_pkt, sizeof(mes_suspend_gang_pkt),
+                       offsetof(union MESAPI__SUSPEND, api_status));
 }
 
 static int mes_v11_0_resume_gang(struct amdgpu_mes *mes,
                                 struct mes_resume_gang_input *input)  {
-       return 0;
+       union MESAPI__RESUME mes_resume_gang_pkt;
+
+       memset(&mes_resume_gang_pkt, 0, sizeof(mes_resume_gang_pkt));
+
+       mes_resume_gang_pkt.header.type = MES_API_TYPE_SCHEDULER;
+       mes_resume_gang_pkt.header.opcode = MES_SCH_API_RESUME;
+       mes_resume_gang_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_resume_gang_pkt.resume_all_gangs = input->resume_all_gangs;
+       mes_resume_gang_pkt.gang_context_addr =
+ input->gang_context_addr;
+
+       return mes_v11_0_submit_pkt_and_poll_completion(mes,
+                       &mes_resume_gang_pkt, sizeof(mes_resume_gang_pkt),
+                       offsetof(union MESAPI__RESUME, api_status));
 }
 
 static int mes_v11_0_query_sched_status(struct amdgpu_mes *mes)
--

2.35.1