Skip to contentSkip to conversation

drm/amdkfd: mark queues as reset after a full GPU reset

PATCH Superseded YuanShang Mao 3 participants 9 messages Aug 20 – Aug 28

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

PATCH 1/1 drm/amdkfd: mark queues as reset after a full GPU reset

From: Yuansheng Mao <[email protected]>

A full GPU reset reloads the MES firmware and wipes its queue table, but KFD keeps the queue objects with is_reset left false. Pre-reset cleanup cannot fix this: it runs with the reset domain write lock held, so remove_queue_mes() fails with -EIO and the cleanup loops bail out early.

When the process later exits, process_termination_cpsch() sends REMOVE_QUEUE for doorbells MES no longer knows about. MES rejects them, remove_queue_mes_on_reset_option() mistakes the rejection for a hung queue and ends up in kfd_hws_hang(), requesting another GPU reset. On SR-IOV that resets the whole card, so one injected hang costs two resets and disturbs the other VFs.

Observed on Navi32 SR-IOV with a compute workload running:

ring sdma1 timeout, signaled seq=239, emitted seq=240 GPU reset begin!. Source: 1
Failed to evict queue 2
GPU reset(1) succeeded!
[ ~34s later, when the killed process is reaped ] failed to remove queue from MES, doorbell=0x1002 MES might be in unrecoverable state, issue a GPU reset GPU reset begin!. Source: 3

remove_queue_mes_on_reset_option() already skips queues with is_reset set, but only the per-queue reset paths ever set it. Set it in kgd2kfd_post_reset() as well. Suspend/resume is unaffected:
it goes through kgd2kfd_resume(), where queues are re-added to MES.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +21 -0
index 586e640f13dc..d326e41a8656 100644
@@ -1033,6 +1033,27 @@ int kgd2kfd_post_reset(struct kfd_dev *kfd)
 	if (!kfd->init_complete)
 		return 0;
 
+	/*
+	 * The reset wiped the MES queue table. Mark the queues as reset so
+	 * that teardown does not try to remove them from MES again.
+	 */
+	if (kfd->shared_resources.enable_mes) {
+		for (i = 0; i < kfd->num_nodes; i++) {
+			struct device_queue_manager *dqm = kfd->nodes[i]->dqm;
+			struct device_process_node *cur;
+			struct qcm_process_device *qpd;
+			struct queue *q;
+
+			dqm_lock(dqm);
+			list_for_each_entry(cur, &dqm->queues, list) {
+				qpd = cur->qpd;
+				list_for_each_entry(q, &qpd->queues_list, list)
+					q->properties.is_reset = true;
+			}
+			dqm_unlock(dqm);
+		}
+	}
+
 	for (i = 0; i < kfd->num_nodes; i++) {
 		ret = kfd_resume(kfd->nodes[i]);
 		if (ret)
Signature · 1 line
2.25.1
#1 lore raw

AMD General

@Deucher, Alexander Could you help review this patch?

Thanks
River

-----Original Message-----
From: YuanShang Mao (River) <[email protected]>
Sent: Thursday, August 20, 2026 6:56 PM
To: [email protected]
Cc: YuanShang Mao (River) <[email protected]>
Subject: [PATCH] drm/amdkfd: mark queues as reset after a full GPU reset

From: Yuansheng Mao <[email protected]>

A full GPU reset reloads the MES firmware and wipes its queue table, but KFD keeps the queue objects with is_reset left false. Pre-reset cleanup cannot fix this: it runs with the reset domain write lock held, so remove_queue_mes() fails with -EIO and the cleanup loops bail out early.

When the process later exits, process_termination_cpsch() sends REMOVE_QUEUE for doorbells MES no longer knows about. MES rejects them, remove_queue_mes_on_reset_option() mistakes the rejection for a hung queue and ends up in kfd_hws_hang(), requesting another GPU reset. On SR-IOV that resets the whole card, so one injected hang costs two resets and disturbs the other VFs.

Observed on Navi32 SR-IOV with a compute workload running:

ring sdma1 timeout, signaled seq=239, emitted seq=240 GPU reset begin!. Source: 1
Failed to evict queue 2
GPU reset(1) succeeded!
[ ~34s later, when the killed process is reaped ] failed to remove queue from MES, doorbell=0x1002 MES might be in unrecoverable state, issue a GPU reset GPU reset begin!. Source: 3

remove_queue_mes_on_reset_option() already skips queues with is_reset set, but only the per-queue reset paths ever set it. Set it in kgd2kfd_post_reset() as well. Suspend/resume is unaffected:
it goes through kgd2kfd_resume(), where queues are re-added to MES.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +21 -0
index 586e640f13dc..d326e41a8656 100644
@@ -1033,6 +1033,27 @@ int kgd2kfd_post_reset(struct kfd_dev *kfd)
        if (!kfd->init_complete)
                return 0;
 
+       /*
+        * The reset wiped the MES queue table. Mark the queues as reset so
+        * that teardown does not try to remove them from MES again.
+        */
+       if (kfd->shared_resources.enable_mes) {
+               for (i = 0; i < kfd->num_nodes; i++) {
+                       struct device_queue_manager *dqm = kfd->nodes[i]->dqm;
+                       struct device_process_node *cur;
+                       struct qcm_process_device *qpd;
+                       struct queue *q;
+
+                       dqm_lock(dqm);
+                       list_for_each_entry(cur, &dqm->queues, list) {
+                               qpd = cur->qpd;
+                               list_for_each_entry(q, &qpd->queues_list, list)
+                                       q->properties.is_reset = true;
+                       }
+                       dqm_unlock(dqm);
+               }
+       }
+
        for (i = 0; i < kfd->num_nodes; i++) {
                ret = kfd_resume(kfd->nodes[i]);
                if (ret)

--
2.25.1

#2 lore raw

AMD General

@Deucher, Alexander<mailto:[email protected]> @Lazar, Lijo<mailto:[email protected]>

Could you help review this patch?

Thanks

River

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of YuanShang Mao (River)
Sent: Monday, August 24, 2026 2:40 PM
To: Deucher, Alexander <[email protected]>
Cc: Zhang, Tiantian (Celine) <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdkfd: mark queues as reset after a full GPU reset

AMD General

@Deucher, Alexander Could you help review this patch?

Thanks

River

-----Original Message-----

From: YuanShang Mao (River) <[email protected]<mailto:[email protected]>>

Sent: Thursday, August 20, 2026 6:56 PM

To: [email protected]<mailto:[email protected]>

Cc YuanShang Mao (River) <[email protected]<mailto:[email protected]>>

Subject: [PATCH] drm/amdkfd: mark queues as reset after a full GPU reset

From: Yuansheng Mao <[email protected]<mailto:[email protected]>>

A full GPU reset reloads the MES firmware and wipes its queue table, but KFD keeps the queue objects with is_reset left false.

Pre-reset cleanup cannot fix this: it runs with the reset domain write lock held, so remove_queue_mes() fails with -EIO and the cleanup loops bail out early.

When the process later exits, process_termination_cpsch() sends REMOVE_QUEUE for doorbells MES no longer knows about. MES rejects them, remove_queue_mes_on_reset_option() mistakes the rejection for a hung queue and ends up in kfd_hws_hang(), requesting another GPU reset. On SR-IOV that resets the whole card, so one injected hang costs two resets and disturbs the other VFs.

Observed on Navi32 SR-IOV with a compute workload running:

ring sdma1 timeout, signaled seq=239, emitted seq=240

GPU reset begin!. Source: 1

Failed to evict queue 2

GPU reset(1) succeeded!

[ ~34s later, when the killed process is reaped ]

failed to remove queue from MES, doorbell=0x1002

MES might be in unrecoverable state, issue a GPU reset

GPU reset begin!. Source: 3

remove_queue_mes_on_reset_option() already skips queues with is_reset set, but only the per-queue reset paths ever set it. Set it in kgd2kfd_post_reset() as well. Suspend/resume is unaffected:

it goes through kgd2kfd_resume(), where queues are re-added to MES.

---

drivers/gpu/drm/amd/amdkfd/kfd_device.c | 21 +++++++++++++++++++++

1 file changed, 21 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +0 -0

index 586e640f13dc..d326e41a8656 100644

--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c

+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c

@@ -1033,6 +1033,27 @@ int kgd2kfd_post_reset(struct kfd_dev *kfd)

        if (!kfd->init_complete)

                return 0;

+ /*

+ * The reset wiped the MES queue table. Mark the queues as reset so

+ * that teardown does not try to remove them from MES again.

+ */

+ if (kfd->shared_resources.enable_mes) {

+ for (i = 0; i < kfd->num_nodes; i++) {

+ struct device_queue_manager *dqm = kfd->nodes[i]->dqm;

+ struct device_process_node *cur;

+ struct qcm_process_device *qpd;

+ struct queue *q;

+

+ dqm_lock(dqm);

+ list_for_each_entry(cur, &dqm->queues, list) {

+ qpd = cur->qpd;

+ list_for_each_entry(q, &qpd->queues_list, list)

+ q->properties.is_reset = true;

+ }

+ dqm_unlock(dqm);

+ }

+ }

+

        for (i = 0; i < kfd->num_nodes; i++) {

                ret = kfd_resume(kfd->nodes[i]);

                if (ret)

--

2.25.1

#3 lore raw
In reply to YuanShang Mao (River)

AMD General

@Deucher, Alexander @Lazar, Lijo

Could you help review this patch?

Thanks
River

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of YuanShang Mao (River)
Sent: Monday, August 24, 2026 2:40 PM
To: Deucher, Alexander <[email protected]>
Cc: Zhang, Tiantian (Celine) <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdkfd: mark queues as reset after a full GPU reset

AMD General

@Deucher, Alexander Could you help review this patch?

Thanks
River

-----Original Message-----
From: YuanShang Mao (River) <[email protected]>
Sent: Thursday, August 20, 2026 6:56 PM
To: [email protected]
Cc: YuanShang Mao (River) <[email protected]>
Subject: [PATCH] drm/amdkfd: mark queues as reset after a full GPU reset

From: Yuansheng Mao <[email protected]>

A full GPU reset reloads the MES firmware and wipes its queue table, but KFD keeps the queue objects with is_reset left false. Pre-reset cleanup cannot fix this: it runs with the reset domain write lock held, so remove_queue_mes() fails with -EIO and the cleanup loops bail out early.

When the process later exits, process_termination_cpsch() sends REMOVE_QUEUE for doorbells MES no longer knows about. MES rejects them, remove_queue_mes_on_reset_option() mistakes the rejection for a hung queue and ends up in kfd_hws_hang(), requesting another GPU reset. On SR-IOV that resets the whole card, so one injected hang costs two resets and disturbs the other VFs.

Observed on Navi32 SR-IOV with a compute workload running:

ring sdma1 timeout, signaled seq=239, emitted seq=240 GPU reset begin!. Source: 1
Failed to evict queue 2
GPU reset(1) succeeded!
[ ~34s later, when the killed process is reaped ] failed to remove queue from MES, doorbell=0x1002 MES might be in unrecoverable state, issue a GPU reset GPU reset begin!. Source: 3

remove_queue_mes_on_reset_option() already skips queues with is_reset set, but only the per-queue reset paths ever set it. Set it in kgd2kfd_post_reset() as well. Suspend/resume is unaffected:
it goes through kgd2kfd_resume(), where queues are re-added to MES.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +21 -0
index 586e640f13dc..d326e41a8656 100644
@@ -1033,6 +1033,27 @@ int kgd2kfd_post_reset(struct kfd_dev *kfd)
        if (!kfd->init_complete)
                return 0;
 
+       /*
+        * The reset wiped the MES queue table. Mark the queues as reset so
+        * that teardown does not try to remove them from MES again.
+        */
+       if (kfd->shared_resources.enable_mes) {
+               for (i = 0; i < kfd->num_nodes; i++) {
+                       struct device_queue_manager *dqm = kfd->nodes[i]->dqm;
+                       struct device_process_node *cur;
+                       struct qcm_process_device *qpd;
+                       struct queue *q;
+
+                       dqm_lock(dqm);
+                       list_for_each_entry(cur, &dqm->queues, list) {
+                               qpd = cur->qpd;
+                               list_for_each_entry(q, &qpd->queues_list, list)
+                                       q->properties.is_reset = true;
+                       }
+                       dqm_unlock(dqm);
+               }
+       }
+
        for (i = 0; i < kfd->num_nodes; i++) {
                ret = kfd_resume(kfd->nodes[i]);
                if (ret)

--
2.25.1

#4 lore raw
In reply to YuanShang Mao
Quoted 42 lines · YuanShang Mao

From: Yuansheng Mao <[email protected]>

A full GPU reset reloads the MES firmware and wipes its queue table, but KFD keeps the queue objects with is_reset left false. Pre-reset cleanup cannot fix this: it runs with the reset domain write lock held, so remove_queue_mes() fails with -EIO and the cleanup loops bail out early.

When the process later exits, process_termination_cpsch() sends REMOVE_QUEUE for doorbells MES no longer knows about. MES rejects them, remove_queue_mes_on_reset_option() mistakes the rejection for a hung queue and ends up in kfd_hws_hang(), requesting another GPU reset. On SR-IOV that resets the whole card, so one injected hang costs two resets and disturbs the other VFs.

Observed on Navi32 SR-IOV with a compute workload running:

ring sdma1 timeout, signaled seq=239, emitted seq=240 GPU reset begin!. Source: 1
Failed to evict queue 2
GPU reset(1) succeeded!
[ ~34s later, when the killed process is reaped ] failed to remove queue from MES, doorbell=0x1002 MES might be in unrecoverable state, issue a GPU reset GPU reset begin!. Source: 3

remove_queue_mes_on_reset_option() already skips queues with is_reset set, but only the per-queue reset paths ever set it. Set it in kgd2kfd_post_reset() as well. Suspend/resume is unaffected:
it goes through kgd2kfd_resume(), where queues are re-added to MES.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +0 -0
index 586e640f13dc..d326e41a8656 100644

drivers/gpu/drm/amd/amdkfd/kfd_device.c int kgd2kfd_post_reset(struct kfd_dev *kfd) · line 1040

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_device.c +5 -0
@@ -1033,6 +1033,27 @@ int kgd2kfd_post_reset(struct kfd_dev *kfd)
        if (!kfd->init_complete)
                return 0;
 
+       /*
+        * The reset wiped the MES queue table. Mark the queues as reset so
+        * that teardown does not try to remove them from MES again.
+        */
+       if (kfd->shared_resources.enable_mes) {

Why is this MES specific? Shouldn't this be true for KIQ as well?

Alex

Quoted 22 lines
drivers/gpu/drm/amd/amdkfd/kfd_device.c +16 -1
+               for (i = 0; i < kfd->num_nodes; i++) {
+                       struct device_queue_manager *dqm = kfd->nodes[i]->dqm;
+                       struct device_process_node *cur;
+                       struct qcm_process_device *qpd;
+                       struct queue *q;
+
+                       dqm_lock(dqm);
+                       list_for_each_entry(cur, &dqm->queues, list) {
+                               qpd = cur->qpd;
+                               list_for_each_entry(q, &qpd->queues_list, list)
+                                       q->properties.is_reset = true;
+                       }
+                       dqm_unlock(dqm);
+               }
+       }
+
        for (i = 0; i < kfd->num_nodes; i++) {
                ret = kfd_resume(kfd->nodes[i]);
                if (ret)
--

2.25.1

author
#5 lore raw

PATCH v2 1/1 drm/amdkfd: mark queues as reset after a full GPU reset

In reply to YuanShang Mao

During a GPU reset, evict_process_queues_cpsch() calls remove_queue_mes() per queue, which fails with -EIO because the recovery path already holds the reset domain write lock. The loop aborts on the first queue, leaving the rest with is_active still set while the reset wipes the MES queue table.

When the process later exits, process_termination_cpsch() sends REMOVE_QUEUE for doorbells MES no longer knows about. MES rejects them, the driver reports it as a timeout and concludes MES is unrecoverable, so it requests another GPU reset.

Failed to evict queue 2
GPU reset(1) succeeded!
failed to remove queue from MES, doorbell=0x1002 MES might be in unrecoverable state, issue a GPU reset GPU reset begin!. Source: 3

Mark every queue as reset in kgd2kfd_post_reset(). This clears is_active, corrects the queue counts and sets is_reset so the queue is skipped later.

Add a verbose argument to set_queue_as_reset() so the full reset path does not log a message for every queue.

---
v2:
- drop the enable_mes check and mark queues on KIQ as well (Suggested-by: Alex Deucher <[email protected]>)
- add a verbose argument to set_queue_as_reset() so the full reset path does not log a message for every queue

KIQ does not hit this bug. Its evict loop has no fallible call in it, so the loop always runs to completion and every queue ends up with is_active clear, leaving nothing for process teardown to send. Marking on KIQ is still worth doing: after a reset the queues are gone on both schedulers, and is_reset states that, while is_active == false only means "do not schedule it now" and is cleared again on restore.

 drivers/gpu/drm/amd/amdkfd/kfd_device.c       |  3 ++
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 36 +++++++++++++++----
 .../drm/amd/amdkfd/kfd_device_queue_manager.h |  1 +
 3 files changed, 33 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +3 -0
index 586e640f13dc..84bc04c4a55c 100644
@@ -1033,6 +1033,9 @@ int kgd2kfd_post_reset(struct kfd_dev *kfd)
 	if (!kfd->init_complete)
 		return 0;
 
+	for (i = 0; i < kfd->num_nodes; i++)
+		kfd_dqm_set_queues_as_reset(kfd->nodes[i]->dqm);
+
 	for (i = 0; i < kfd->num_nodes; i++) {
 		ret = kfd_resume(kfd->nodes[i]);
 		if (ret)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +29 -7
index a23384571193..350dcb8c21cb 100644
@@ -75,7 +75,7 @@ static int reset_queues_on_hws_hang(struct device_queue_manager *dqm, bool is_sd
 static struct queue *find_queue_by_doorbell_offset(struct device_queue_manager *dqm,
 						   u32 doorbell_offset);
 static void set_queue_as_reset(struct device_queue_manager *dqm, struct queue *q,
-			       struct qcm_process_device *qpd);
+			       struct qcm_process_device *qpd, bool verbose);
 static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q);
 
 static inline
@@ -433,7 +433,7 @@ static int reset_queue_mes(struct device_queue_manager *dqm, struct queue *q,
 		return r;
 	/* Proceed remove_queue with reset=true */
 	remove_queue_mes_on_reset_option(dqm, q, &pdd->qpd, true, true);
-	set_queue_as_reset(dqm, q, &pdd->qpd);
+	set_queue_as_reset(dqm, q, &pdd->qpd, true);
 	return 0;
 }
 
@@ -2369,12 +2369,14 @@ static int map_queues_cpsch(struct device_queue_manager *dqm)
 }
 
 static void set_queue_as_reset(struct device_queue_manager *dqm, struct queue *q,
-			       struct qcm_process_device *qpd)
+			       struct qcm_process_device *qpd, bool verbose)
 {
 	struct kfd_process_device *pdd = qpd_to_pdd(qpd);
 
-	dev_err(dqm->dev->adev->dev, "queue id 0x%0x at pasid %d is reset\n",
-		q->properties.queue_id, pdd->process->lead_thread->pid);
+	if (verbose)
+		dev_err(dqm->dev->adev->dev,
+			"queue id 0x%0x at pasid %d is reset\n",
+			q->properties.queue_id, pdd->process->lead_thread->pid);
 
 	pdd->has_reset_queue = true;
 	q->properties.is_reset = true;
@@ -2384,6 +2386,26 @@ static void set_queue_as_reset(struct device_queue_manager *dqm, struct queue *q
 	}
 }
 
+void kfd_dqm_set_queues_as_reset(struct device_queue_manager *dqm)
+{
+	struct device_process_node *cur;
+	struct qcm_process_device *qpd;
+	struct queue *q;
+
+	dqm_lock(dqm);
+	if (dqm->processes_count)
+		dev_warn(dqm->dev->adev->dev,
+			 "GPU reset: queues of %d process(es) are no longer usable\n",
+			 dqm->processes_count);
+
+	list_for_each_entry(cur, &dqm->queues, list) {
+		qpd = cur->qpd;
+		list_for_each_entry(q, &qpd->queues_list, list)
+			set_queue_as_reset(dqm, q, qpd, false);
+	}
+	dqm_unlock(dqm);
+}
+
 static int detect_queue_hang(struct device_queue_manager *dqm)
 {
 	int i;
@@ -2499,7 +2521,7 @@ static int reset_hung_queues(struct device_queue_manager *dqm)
 			goto reset_fail;
 		}
 
-		set_queue_as_reset(dqm, q, &pdd->qpd);
+		set_queue_as_reset(dqm, q, &pdd->qpd, true);
 		reset_count++;
 	}
 
@@ -2546,7 +2568,7 @@ static bool set_sdma_queue_as_reset(struct device_queue_manager *dqm,
 			if ((q->properties.type == KFD_QUEUE_TYPE_SDMA ||
 			     q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) &&
 			     q->properties.doorbell_off == doorbell_off) {
-				set_queue_as_reset(dqm, q, qpd);
+				set_queue_as_reset(dqm, q, qpd, true);
 				return true;
 			}
 		}
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +1 -0
index c9f9f7a87111..8ddde9f75541 100644
@@ -333,6 +333,7 @@ int debug_refresh_runlist(struct device_queue_manager *dqm);
 bool kfd_dqm_is_queue_in_process(struct device_queue_manager *dqm,
 				 struct qcm_process_device *qpd,
 				 int doorbell_off, u32 *queue_format);
+void kfd_dqm_set_queues_as_reset(struct device_queue_manager *dqm);
 int kfd_reset_queue_mes(struct device_queue_manager *dqm, int queue_type,
 			int pipe, int queue, unsigned int db);
 size_t mqd_size_from_queue_type(struct device_queue_manager *dqm,
Signature · 1 line
2.25.1
author
#6 lore raw

Hi Alex,

I agree with your suggestion - v2 drops the enable_mes check and marks the queues on KIQ as well.

To be clear, KIQ itself does not hit this bug. Its evict loop has no call that can fail, so the loop always finishes and every queue ends up with is_active clear. Nothing is left for process teardown to send. Marking on KIQ is just to keep the state honest: after a reset the queues are gone on both, and is_reset says that.

v2 is out, please take a look when you have time.

Thanks,
YuanShang

author
#7 lore raw
In reply to YuanShang

Hi Alex,

I agree with your suggestion - v2 drops the enable_mes check and marks the queues on KIQ as well.

To be clear, KIQ itself does not hit this bug. On reset, kgd2kfd_pre_reset() calls kgd2kfd_suspend(), which ends up in evict_process_queues_cpsch(). On the KIQ path that loop has no fallible call in it - remove_queue_mes() is behind enable_mes, and execute_queues_cpsch() is outside the loop - so the loop always runs to the end and every queue is left with is_evicted set and is_active clear. Process teardown then has nothing to send.

Marking on KIQ is just to keep the state honest: after a reset the queues are gone on both, and is_reset says that, while is_active == false only means "do not schedule it now".

v2 is out, please take a look when you have time.

Thanks,
YuanShang

maintainer Acked-by on v2 1/1
#8 lore raw
In reply to YuanShang

Public

Quoted 25 lines

-----Original Message-----
From: YuanShang Mao (River) <[email protected]>
Sent: Friday, August 28, 2026 3:42 AM
To: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Koenig, Christian <[email protected]>; amd- [email protected]
Subject: [PATCH v2] drm/amdkfd: mark queues as reset after a full GPU reset

During a GPU reset, evict_process_queues_cpsch() calls remove_queue_mes() per queue, which fails with -EIO because the recovery path already holds the reset domain write lock. The loop aborts on the first queue, leaving the rest with is_active still set while the reset wipes the MES queue table.

When the process later exits, process_termination_cpsch() sends REMOVE_QUEUE for doorbells MES no longer knows about. MES rejects them, the driver reports it as a timeout and concludes MES is unrecoverable, so it requests another GPU reset.

Failed to evict queue 2
GPU reset(1) succeeded!
failed to remove queue from MES, doorbell=0x1002 MES might be in unrecoverable state, issue a GPU reset GPU reset begin!. Source: 3

Quoted 7 lines

Mark every queue as reset in kgd2kfd_post_reset(). This clears is_active, corrects the queue counts and sets is_reset so the queue is skipped later.

Add a verbose argument to set_queue_as_reset() so the full reset path does not log a message for every queue.

Quoted 149 lines

---
v2:
- drop the enable_mes check and mark queues on KIQ as well (Suggested-by: Alex Deucher <[email protected]>)
- add a verbose argument to set_queue_as_reset() so the full reset path does not log a message for every queue

KIQ does not hit this bug. Its evict loop has no fallible call in it, so the loop always runs to completion and every queue ends up with is_active clear, leaving nothing for process teardown to send. Marking on KIQ is still worth
doing: after a reset the queues are gone on both schedulers, and is_reset states that, while is_active == false only means "do not schedule it now" and is cleared again on restore.

 drivers/gpu/drm/amd/amdkfd/kfd_device.c       |  3 ++
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 36
+++++++++++++++----  .../drm/amd/amdkfd/kfd_device_queue_manager.h |
1 +
 3 files changed, 33 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +3 -0
index 586e640f13dc..84bc04c4a55c 100644
@@ -1033,6 +1033,9 @@ int kgd2kfd_post_reset(struct kfd_dev *kfd)
      if (!kfd->init_complete)
              return 0;
 
+     for (i = 0; i < kfd->num_nodes; i++)
+             kfd_dqm_set_queues_as_reset(kfd->nodes[i]->dqm);
+
      for (i = 0; i < kfd->num_nodes; i++) {
              ret = kfd_resume(kfd->nodes[i]);
              if (ret)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -0
index a23384571193..350dcb8c21cb 100644
@@ -75,7 +75,7 @@ static int reset_queues_on_hws_hang(struct

device_queue_manager *dqm, bool is_sd static struct queue *find_queue_by_doorbell_offset(struct device_queue_manager *dqm,

                                                 u32 doorbell_offset);

static void set_queue_as_reset(struct device_queue_manager *dqm, struct
queue *q,

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
-                            struct qcm_process_device *qpd);
+                            struct qcm_process_device *qpd, bool verbose);
 static int reset_queues_mes(struct device_queue_manager *dqm, struct

queue *q);

static inline

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
@@ -433,7 +433,7 @@ static int reset_queue_mes(struct
 device_queue_manager *dqm, struct queue *q,
              return r;
      /* Proceed remove_queue with reset=true */
      remove_queue_mes_on_reset_option(dqm, q, &pdd->qpd, true,
 true);
-     set_queue_as_reset(dqm, q, &pdd->qpd);
+     set_queue_as_reset(dqm, q, &pdd->qpd, true);
      return 0;

}

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +5 -3
@@ -2369,12 +2369,14 @@ static int map_queues_cpsch(struct
 device_queue_manager *dqm)  }
 
 static void set_queue_as_reset(struct device_queue_manager *dqm, struct
 queue *q,
-                            struct qcm_process_device *qpd)
+                            struct qcm_process_device *qpd, bool verbose)
 {
      struct kfd_process_device *pdd = qpd_to_pdd(qpd);
 
-     dev_err(dqm->dev->adev->dev, "queue id 0x%0x at pasid %d is
 reset\n",
-             q->properties.queue_id, pdd->process->lead_thread->pid);
+     if (verbose)
+             dev_err(dqm->dev->adev->dev,
+                     "queue id 0x%0x at pasid %d is reset\n",
+                     q->properties.queue_id, pdd->process->lead_thread-
 >pid);
      pdd->has_reset_queue = true;
      q->properties.is_reset = true;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -0
@@ -2384,6 +2386,26 @@ static void set_queue_as_reset(struct

device_queue_manager *dqm, struct queue *q

      }

}

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +9 -0
+void kfd_dqm_set_queues_as_reset(struct device_queue_manager *dqm) {
+     struct device_process_node *cur;
+     struct qcm_process_device *qpd;
+     struct queue *q;
+
+     dqm_lock(dqm);
+     if (dqm->processes_count)
+             dev_warn(dqm->dev->adev->dev,
+                      "GPU reset: queues of %d process(es) are no longer

usable\n",

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +11 -1
+                      dqm->processes_count);
+
+     list_for_each_entry(cur, &dqm->queues, list) {
+             qpd = cur->qpd;
+             list_for_each_entry(q, &qpd->queues_list, list)
+                     set_queue_as_reset(dqm, q, qpd, false);
+     }
+     dqm_unlock(dqm);
+}
+
 static int detect_queue_hang(struct device_queue_manager *dqm)  {
      int i;
@@ -2499,7 +2521,7 @@ static int reset_hung_queues(struct
 device_queue_manager *dqm)
                      goto reset_fail;
              }
 
-             set_queue_as_reset(dqm, q, &pdd->qpd);
+             set_queue_as_reset(dqm, q, &pdd->qpd, true);
              reset_count++;
      }
@@ -2546,7 +2568,7 @@ static bool set_sdma_queue_as_reset(struct
 device_queue_manager *dqm,
                      if ((q->properties.type == KFD_QUEUE_TYPE_SDMA ||
                           q->properties.type ==

KFD_QUEUE_TYPE_SDMA_XGMI) &&

                           q->properties.doorbell_off == doorbell_off) {
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
-                             set_queue_as_reset(dqm, q, qpd);
+                             set_queue_as_reset(dqm, q, qpd, true);
                              return true;
                      }
              }
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +0 -0
index c9f9f7a87111..8ddde9f75541 100644
@@ -333,6 +333,7 @@ int debug_refresh_runlist(struct

device_queue_manager *dqm); bool kfd_dqm_is_queue_in_process(struct device_queue_manager *dqm,
struct qcm_process_device *qpd, int doorbell_off, u32 *queue_format);
+void kfd_dqm_set_queues_as_reset(struct device_queue_manager *dqm);
int kfd_reset_queue_mes(struct device_queue_manager *dqm, int
queue_type,
int pipe, int queue, unsigned int db); size_t
mqd_size_from_queue_type(struct device_queue_manager *dqm, --
2.25.1