Skip to contentSkip to conversation

drm/amdgpu: fix gfx12 mes packet status return check

PATCH In review Jonathan Kim 2 participants 4 messages Oct 10, 2025

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

PATCH 1/3 drm/amdgpu: fix gfx12 mes packet status return check

GFX12 MES uses low 32 bits of status return for success (1 or 0) and high bits for debug information if low bits are 0.

GFX11 MES doesn't do this so checking full 64-bit status return for 1 or 0 is still valid.

v2: user lower_32_bits to check status and write some inline comments to explain the status pointer value.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +6 -1
index aff06f06aeee..e3149196143e 100644
@@ -228,7 +228,12 @@ static int mes_v12_0_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
 			pipe, x_pkt->header.opcode);
 
 	r = amdgpu_fence_wait_polling(ring, seq, timeout);
-	if (r < 1 || !*status_ptr) {
+
+	/*
+	 * status_ptr[31:0] == 0 (fail) or status_ptr[63:0] == 1 (success).
+	 * If status_ptr[31:0] == 0 then status_ptr[63:32] will have debug error information.
+	 */
+	if (r < 1 || !(lower_32_bits(*status_ptr))) {
 
 		if (misc_op_str)
 			dev_err(adev->dev, "MES(%d) failed to respond to msg=%s (%s)\n",
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 drm/amdgpu: fix hung reset queue array memory allocation

By design the MES will return an array result that is twice the number of hung doorbells it can report.

i.e. if up k reported doorbells are supported, then the second half of the array, also of length k, holds the HQD information (type/queue/pipe) where queue 1 corresponds to index 0 and k, queue 2 corresponds to index 1 and k + 1 etc ...

The driver will use the HDQ info to target queue/pipe reset for hardware scheduled user compute queues.

v2: only extend memory to accommodate HQD info for now as it will be used later.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c    | 7 ++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h    | 1 +
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 6 +++---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c     | 8 +++++---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c     | 8 +++++---
 5 files changed, 20 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +6 -1
index 01ac942c1bb1..45bf8309cb37 100644
@@ -420,12 +420,17 @@ int amdgpu_mes_detect_and_reset_hung_queues(struct amdgpu_device *adev,
 		dev_err(adev->dev, "failed to detect and reset\n");
 	} else {
 		*hung_db_num = 0;
-		for (i = 0; i < adev->mes.hung_queue_db_array_size; i++) {
+		for (i = 0; i < adev->mes.hung_queue_hqd_info_offset; i++) {
 			if (db_array[i] != AMDGPU_MES_INVALID_DB_OFFSET) {
 				hung_db_array[i] = db_array[i];
 				*hung_db_num += 1;
 			}
 		}
+
+		/*
+		 * TODO: return HQD info for MES scheduled user compute queue reset cases
+		 * stored in hung_db_array hqd info offset to full array size
+		 */
 	}
 
 	return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
index 6b506fc72f58..97c137c90f97 100644
@@ -149,6 +149,7 @@ struct amdgpu_mes {
 	void                *resource_1_addr[AMDGPU_MAX_MES_PIPES];
 
 	int				hung_queue_db_array_size;
+	int				hung_queue_hqd_info_offset;
 	struct amdgpu_bo		*hung_queue_db_array_gpu_obj;
 	uint64_t			hung_queue_db_array_gpu_addr;
 	void				*hung_queue_db_array_cpu_addr;
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3 -3
index 829129ad7bd1..5c63480dda9c 100644
@@ -208,10 +208,10 @@ static int mes_userq_detect_and_reset(struct amdgpu_device *adev,
 	struct amdgpu_userq_mgr *uqm, *tmp;
 	unsigned int hung_db_num = 0;
 	int queue_id, r, i;
-	u32 db_array[4];
+	u32 db_array[8];
 
-	if (db_array_size > 4) {
-		dev_err(adev->dev, "DB array size (%d vs 4) too small\n",
+	if (db_array_size > 8) {
+		dev_err(adev->dev, "DB array size (%d vs 8) too small\n",
 			db_array_size);
 		return -EINVAL;
 	}
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +5 -3
index e82188431f79..da575bb1377f 100644
@@ -66,7 +66,8 @@ static int mes_v11_0_kiq_hw_fini(struct amdgpu_device *adev);
 #define GFX_MES_DRAM_SIZE	0x80000
 #define MES11_HW_RESOURCE_1_SIZE (128 * AMDGPU_GPU_PAGE_SIZE)
 
-#define MES11_HUNG_DB_OFFSET_ARRAY_SIZE 4
+#define MES11_HUNG_DB_OFFSET_ARRAY_SIZE 8 /* [0:3] = db offset, [4:7] = hqd info */
+#define MES11_HUNG_HQD_INFO_OFFSET	4
 
 static void mes_v11_0_ring_set_wptr(struct amdgpu_ring *ring)
 {
@@ -1720,8 +1721,9 @@ static int mes_v11_0_early_init(struct amdgpu_ip_block *ip_block)
 	struct amdgpu_device *adev = ip_block->adev;
 	int pipe, r;
 
-	adev->mes.hung_queue_db_array_size =
-		MES11_HUNG_DB_OFFSET_ARRAY_SIZE;
+	adev->mes.hung_queue_db_array_size = MES11_HUNG_DB_OFFSET_ARRAY_SIZE;
+	adev->mes.hung_queue_hqd_info_offset = MES11_HUNG_HQD_INFO_OFFSET;
+
 	for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
 		if (!adev->enable_mes_kiq && pipe == AMDGPU_MES_KIQ_PIPE)
 			continue;
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +5 -3
index e3149196143e..7f3512d9de07 100644
@@ -47,7 +47,8 @@ static int mes_v12_0_kiq_hw_fini(struct amdgpu_device *adev);
 
 #define MES_EOP_SIZE   2048
 
-#define MES12_HUNG_DB_OFFSET_ARRAY_SIZE 4
+#define MES12_HUNG_DB_OFFSET_ARRAY_SIZE 8 /* [0:3] = db offset [4:7] hqd info */
+#define MES12_HUNG_HQD_INFO_OFFSET	4
 
 static void mes_v12_0_ring_set_wptr(struct amdgpu_ring *ring)
 {
@@ -1904,8 +1905,9 @@ static int mes_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 	struct amdgpu_device *adev = ip_block->adev;
 	int pipe, r;
 
-	adev->mes.hung_queue_db_array_size =
-		MES12_HUNG_DB_OFFSET_ARRAY_SIZE;
+	adev->mes.hung_queue_db_array_size = MES12_HUNG_DB_OFFSET_ARRAY_SIZE;
+	adev->mes.hung_queue_hqd_info_offset = MES12_HUNG_HQD_INFO_OFFSET;
+
 	for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
 		r = amdgpu_mes_init_microcode(adev, pipe);
 		if (r)
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/3 drm/amdgpu: update remove after reset flag for MES remove queue

In reply to Jonathan Kim

Remove queue after reset flag is required to remove a queue that has been successfully reset to clean up the MES' internal state.

v2: add mes fw version checks when setting the bit

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       | 1 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        | 4 ++++
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        | 4 ++++
 drivers/gpu/drm/amd/include/mes_v11_api_def.h | 3 ++-
 drivers/gpu/drm/amd/include/mes_v12_api_def.h | 3 ++-
 5 files changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
index 97c137c90f97..9c27a68cb82f 100644
@@ -239,6 +239,7 @@ struct mes_add_queue_input {
 struct mes_remove_queue_input {
 	uint32_t	doorbell_offset;
 	uint64_t	gang_context_addr;
+	bool		remove_queue_after_reset;
 };
 
 struct mes_map_legacy_queue_input {
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +4 -0
index da575bb1377f..3a52754b5cad 100644
@@ -369,6 +369,7 @@ static int mes_v11_0_remove_hw_queue(struct amdgpu_mes *mes,
 				     struct mes_remove_queue_input *input)
 {
 	union MESAPI__REMOVE_QUEUE mes_remove_queue_pkt;
+	uint32_t mes_rev = mes->sched_version & AMDGPU_MES_VERSION_MASK;
 
 	memset(&mes_remove_queue_pkt, 0, sizeof(mes_remove_queue_pkt));
 
@@ -379,6 +380,9 @@ static int mes_v11_0_remove_hw_queue(struct amdgpu_mes *mes,
 	mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset;
 	mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr;
 
+	if (mes_rev >= 0x60)
+		mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;
+
 	return mes_v11_0_submit_pkt_and_poll_completion(mes,
 			&mes_remove_queue_pkt, sizeof(mes_remove_queue_pkt),
 			offsetof(union MESAPI__REMOVE_QUEUE, api_status));
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +4 -0
index 7f3512d9de07..744e95d3984a 100644
@@ -361,6 +361,7 @@ static int mes_v12_0_remove_hw_queue(struct amdgpu_mes *mes,
 				     struct mes_remove_queue_input *input)
 {
 	union MESAPI__REMOVE_QUEUE mes_remove_queue_pkt;
+	uint32_t mes_rev = mes->sched_version & AMDGPU_MES_VERSION_MASK;
 
 	memset(&mes_remove_queue_pkt, 0, sizeof(mes_remove_queue_pkt));
 
@@ -371,6 +372,9 @@ static int mes_v12_0_remove_hw_queue(struct amdgpu_mes *mes,
 	mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset;
 	mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr;
 
+	if (mes_rev >= 0x5a)
+		mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;
+
 	return mes_v12_0_submit_pkt_and_poll_completion(mes,
 			AMDGPU_MES_SCHED_PIPE,
 			&mes_remove_queue_pkt, sizeof(mes_remove_queue_pkt),
drivers/gpu/drm/amd/include/mes_v11_api_def.h +2 -1
index ab1cfc92dbeb..f9629d42ada2 100644
@@ -345,7 +345,8 @@ union MESAPI__REMOVE_QUEUE {
 			uint32_t unmap_kiq_utility_queue  : 1;
 			uint32_t preempt_legacy_gfx_queue : 1;
 			uint32_t unmap_legacy_queue       : 1;
-			uint32_t reserved                 : 28;
+			uint32_t remove_queue_after_reset : 1;
+			uint32_t reserved                 : 27;
 		};
 		struct MES_API_STATUS	    api_status;
 
drivers/gpu/drm/amd/include/mes_v12_api_def.h +2 -1
index 69611c7e30e3..2f12cba4eb66 100644
@@ -399,7 +399,8 @@ union MESAPI__REMOVE_QUEUE {
 			uint32_t unmap_kiq_utility_queue  : 1;
 			uint32_t preempt_legacy_gfx_queue : 1;
 			uint32_t unmap_legacy_queue	  : 1;
-			uint32_t reserved		  : 28;
+			uint32_t remove_queue_after_reset : 1;
+			uint32_t reserved		  : 27;
 		};
 		struct MES_API_STATUS		api_status;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/3
#3 lore raw
In reply to Jonathan Kim
Quoted 11 lines · Jonathan Kim

GFX12 MES uses low 32 bits of status return for success (1 or 0) and high bits for debug information if low bits are 0.

GFX11 MES doesn't do this so checking full 64-bit status return for 1 or 0 is still valid.

v2: user lower_32_bits to check status and write some inline comments to explain the status pointer value.

Series is:

Quoted 25 lines
---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +6 -2
index aff06f06aeee..e3149196143e 100644
@@ -228,7 +228,12 @@ static int mes_v12_0_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
                        pipe, x_pkt->header.opcode);
 
        r = amdgpu_fence_wait_polling(ring, seq, timeout);
-       if (r < 1 || !*status_ptr) {
+
+       /*
+        * status_ptr[31:0] == 0 (fail) or status_ptr[63:0] == 1 (success).
+        * If status_ptr[31:0] == 0 then status_ptr[63:32] will have debug error information.
+        */
+       if (r < 1 || !(lower_32_bits(*status_ptr))) {
 
                if (misc_op_str)
                        dev_err(adev->dev, "MES(%d) failed to respond to msg=%s (%s)\n",
--

2.34.1