* [PATCH v2] drm/amdgpu/gfx9: deactivate all compute HQDs before MODE2 on APUs
@ 2026-11-21 6:46 Christoph Berliner
2026-11-23 15:38 ` Alex Deucher
0 siblings, 1 reply; 2+ messages in thread
From: Christoph Berliner @ 2026-11-21 6:46 UTC (permalink / raw)
To: amd-gfx
Cc: alexander.deucher, christian.koenig, Jiqian.Chen,
Christoph Berliner
MODE2 does not reset the CP HQD registers on gfx9 APUs. Commit
c3988a7ad479 ("drm/amdgpu/gfx9: Fix Ring and IB test fail after mode2")
deactivates the HQDs of the kernel compute queues before MODE2, but the
HQDs owned by KFD stay active as well:
- the HIQ is never destroyed during a GPU reset, because
kq_uninitialize() skips destroy_mqd() when it cannot take the reset
domain semaphore, which amdgpu_device_gpu_recover() holds for write
before calling amdgpu_amdkfd_pre_reset(), and kgd_gfx_v9_hqd_destroy()
bails out with -EIO while amdgpu_in_reset() anyway;
- user queues mapped by the HWS stay active when the preceding unmap
failed (which is the usual reason for the reset).
After MODE2 the MEC is unhalted with the stale HIQ. The reset reports
success and graphics/KCQs work again, but the HWS no longer answers:
the next KFD queue creation runs into
amdgpu: qcm fence wait loop timeout expired
amdgpu: The cp might be in an unrecoverable state due to an unsuccessful queues preemption
amdgpu: process pid ... DQM create queue type 0 failed. ret -62
which triggers another reset, and KFD stays unusable until reboot.
Deactivate every active HQD of all MECs before MODE2 instead of only
the KCQs, except the KIQ, which gfx_v9_0_kiq_init_register()
reprograms on resume. The KIQ is also identified by its MQD address,
because at least on Renoir the HQD registers of MEC2 pipes 2/3 read back as
those of pipes 0/1 and the KIQ would otherwise get a dequeue request
through the alias. amdgpu_gfx_kiq_acquire() already avoids MEC2 pipes
2/3 for the KIQ, so this is likely not Renoir specific.
While at it, fix the timeout check of the dequeue loop: it polled for
adev->usec_timeout iterations but compared the counter against
AMDGPU_MAX_USEC_TIMEOUT. Both are equal by default, but with
amdgpu_emu_mode usec_timeout is 10x larger and the manual
CP_HQD_ACTIVE=0 fallback was never reached.
Tested on Ryzen 5 5600G (Cezanne, gfx90c, GC 9.3.0), MEC firmware
0x1e3, HWS enabled, amdgpu.noretry=1. An instrumented build used the
old path for the first MODE2 and the new one afterwards (same boot):
with the old path the HIQ was still ACTIVE with its old MQD/PQ after
the reset and the next HIP program hung the GPU; with the new path
only the KIQ was active at resume and HIP/rocBLAS tests passed. Loaded
at boot, a requested reset deactivated 9 HQDs (8 KCQs + HIQ), skipped
the KIQ seen through the pipe alias, and HIP/rocBLAS tests passed
before and after the reset. Not tested on other gfx9 APUs.
Fixes: c3988a7ad479 ("drm/amdgpu/gfx9: Fix Ring and IB test fail after mode2")
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6177
Assisted-by: Claude Code
Signed-off-by: Christoph Berliner <caberliner@gmail.com>
---
Notes:
v2:
- squash the two patches into one (Alex)
- deactivate the HQDs on all gfx9 APUs instead of only Renoir, replacing
gfx_v9_0_deactivate_kcq_hqd() (Alex)
- v1: https://lore.kernel.org/amd-gfx/CADnq5_OsKujx3VgWDNDYF_ANocTs0aswFaC3uGwZhp7fE+SBCQ@mail.gmail.com/
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 98 +++++++++++++++++++--------
1 file changed, 69 insertions(+), 29 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 9d87ebbc4..2d8ab438c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -4076,39 +4076,79 @@ static int gfx_v9_0_hw_init(struct amdgpu_ip_block *ip_block)
return r;
}
-static void gfx_v9_0_deactivate_kcq_hqd(struct amdgpu_device *adev)
+/* caller must hold srbm_mutex and have selected me/pipe/queue */
+static bool gfx_v9_0_deactivate_hqd(struct amdgpu_device *adev,
+ u32 me, u32 pipe, u32 queue)
{
- amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
- for (int i = 0; i < adev->gfx.num_compute_rings; i++) {
- u32 tmp;
- struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
+ int j;
- mutex_lock(&adev->srbm_mutex);
- soc15_grbm_select(adev, ring->me, ring->pipe, ring->queue, 0, 0);
- tmp = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
- /* disable the queue if it's active */
- if (tmp & CP_HQD_ACTIVE__ACTIVE_MASK) {
- int j;
-
- WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 1);
- for (j = 0; j < adev->usec_timeout; j++) {
- tmp = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
- if (!(tmp & CP_HQD_ACTIVE__ACTIVE_MASK))
- break;
- udelay(1);
- }
- if (j == AMDGPU_MAX_USEC_TIMEOUT) {
- DRM_DEBUG("comp_%u_%u_%u dequeue request failed.\n",
- ring->me, ring->pipe, ring->queue);
- /* Manual disable if dequeue request times out */
- WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
+ /* disable the queue if it's active */
+ if (!(RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK))
+ return false;
+
+ WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 1);
+ for (j = 0; j < adev->usec_timeout; j++) {
+ if (!(RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE) &
+ CP_HQD_ACTIVE__ACTIVE_MASK))
+ break;
+ udelay(1);
+ }
+ if (j == adev->usec_timeout) {
+ dev_dbg(adev->dev, "comp_%u_%u_%u dequeue request failed.\n",
+ me, pipe, queue);
+ /* Manual disable if dequeue request times out */
+ WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
+ }
+ WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 0);
+
+ return true;
+}
+
+/*
+ * MODE2 does not reset the CP HQD registers on gfx9 APUs. Besides the KCQs,
+ * the HQDs owned by KFD (HIQ and the user queues mapped by the HWS) also stay
+ * active, because KFD cannot unmap/destroy them while the reset domain is
+ * locked. After MODE2 the MEC then resumes with stale HQDs and the HWS no
+ * longer answers (qcm fence timeout on the next KFD queue). Deactivate every
+ * active HQD of all MECs except the KIQ, which is reprogrammed on resume.
+ */
+static void gfx_v9_0_deactivate_all_hqd(struct amdgpu_device *adev)
+{
+ struct amdgpu_ring *kiq_ring = &adev->gfx.kiq[0].ring;
+ u64 kiq_mqd_addr = kiq_ring->mqd_gpu_addr & ~0x3ULL;
+ u32 me, pipe, queue, n = 0;
+ u64 mqd_addr;
+
+ amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
+ mutex_lock(&adev->srbm_mutex);
+ for (me = 1; me <= adev->gfx.mec.num_mec; me++) {
+ for (pipe = 0; pipe < adev->gfx.mec.num_pipe_per_mec; pipe++) {
+ for (queue = 0; queue < adev->gfx.mec.num_queue_per_pipe;
+ queue++) {
+ if (me == kiq_ring->me && pipe == kiq_ring->pipe &&
+ queue == kiq_ring->queue)
+ continue;
+ soc15_grbm_select(adev, me, pipe, queue, 0, 0);
+ /*
+ * At least on Renoir the HQD registers of MEC2
+ * pipes 2/3 read back as those of pipes 0/1, so
+ * the KIQ shows up a second time. Skip it by its
+ * MQD address instead of sending it a dequeue.
+ */
+ mqd_addr = ((u64)RREG32_SOC15(GC, 0, mmCP_MQD_BASE_ADDR_HI) << 32) |
+ RREG32_SOC15(GC, 0, mmCP_MQD_BASE_ADDR);
+ if (mqd_addr == kiq_mqd_addr)
+ continue;
+ if (gfx_v9_0_deactivate_hqd(adev, me, pipe, queue))
+ n++;
}
- WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 0);
}
- soc15_grbm_select(adev, 0, 0, 0, 0, 0);
- mutex_unlock(&adev->srbm_mutex);
}
+ soc15_grbm_select(adev, 0, 0, 0, 0, 0);
+ mutex_unlock(&adev->srbm_mutex);
amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
+
+ dev_dbg(adev->dev, "deactivated %u active compute HQDs before MODE2\n", n);
}
static int gfx_v9_0_hw_fini(struct amdgpu_ip_block *ip_block)
@@ -4136,8 +4176,8 @@ static int gfx_v9_0_hw_fini(struct amdgpu_ip_block *ip_block)
}
if ((adev->flags & AMD_IS_APU) && amdgpu_in_reset(adev) &&
- amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_MODE2)
- gfx_v9_0_deactivate_kcq_hqd(adev);
+ amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_MODE2)
+ gfx_v9_0_deactivate_all_hqd(adev);
/* Use deinitialize sequence from CAIL when unbinding device from driver,
* otherwise KIQ is hanging when binding back
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] drm/amdgpu/gfx9: deactivate all compute HQDs before MODE2 on APUs
2026-11-21 6:46 [PATCH v2] drm/amdgpu/gfx9: deactivate all compute HQDs before MODE2 on APUs Christoph Berliner
@ 2026-11-23 15:38 ` Alex Deucher
0 siblings, 0 replies; 2+ messages in thread
From: Alex Deucher @ 2026-11-23 15:38 UTC (permalink / raw)
To: Christoph Berliner
Cc: amd-gfx, alexander.deucher, christian.koenig, Jiqian.Chen
Reviewed and applied.
Thanks!
On Mon, Nov 23, 2026 at 3:30 AM Christoph Berliner <caberliner@gmail.com> wrote:
>
> MODE2 does not reset the CP HQD registers on gfx9 APUs. Commit
> c3988a7ad479 ("drm/amdgpu/gfx9: Fix Ring and IB test fail after mode2")
> deactivates the HQDs of the kernel compute queues before MODE2, but the
> HQDs owned by KFD stay active as well:
>
> - the HIQ is never destroyed during a GPU reset, because
> kq_uninitialize() skips destroy_mqd() when it cannot take the reset
> domain semaphore, which amdgpu_device_gpu_recover() holds for write
> before calling amdgpu_amdkfd_pre_reset(), and kgd_gfx_v9_hqd_destroy()
> bails out with -EIO while amdgpu_in_reset() anyway;
> - user queues mapped by the HWS stay active when the preceding unmap
> failed (which is the usual reason for the reset).
>
> After MODE2 the MEC is unhalted with the stale HIQ. The reset reports
> success and graphics/KCQs work again, but the HWS no longer answers:
> the next KFD queue creation runs into
>
> amdgpu: qcm fence wait loop timeout expired
> amdgpu: The cp might be in an unrecoverable state due to an unsuccessful queues preemption
> amdgpu: process pid ... DQM create queue type 0 failed. ret -62
>
> which triggers another reset, and KFD stays unusable until reboot.
>
> Deactivate every active HQD of all MECs before MODE2 instead of only
> the KCQs, except the KIQ, which gfx_v9_0_kiq_init_register()
> reprograms on resume. The KIQ is also identified by its MQD address,
> because at least on Renoir the HQD registers of MEC2 pipes 2/3 read back as
> those of pipes 0/1 and the KIQ would otherwise get a dequeue request
> through the alias. amdgpu_gfx_kiq_acquire() already avoids MEC2 pipes
> 2/3 for the KIQ, so this is likely not Renoir specific.
>
> While at it, fix the timeout check of the dequeue loop: it polled for
> adev->usec_timeout iterations but compared the counter against
> AMDGPU_MAX_USEC_TIMEOUT. Both are equal by default, but with
> amdgpu_emu_mode usec_timeout is 10x larger and the manual
> CP_HQD_ACTIVE=0 fallback was never reached.
>
> Tested on Ryzen 5 5600G (Cezanne, gfx90c, GC 9.3.0), MEC firmware
> 0x1e3, HWS enabled, amdgpu.noretry=1. An instrumented build used the
> old path for the first MODE2 and the new one afterwards (same boot):
> with the old path the HIQ was still ACTIVE with its old MQD/PQ after
> the reset and the next HIP program hung the GPU; with the new path
> only the KIQ was active at resume and HIP/rocBLAS tests passed. Loaded
> at boot, a requested reset deactivated 9 HQDs (8 KCQs + HIQ), skipped
> the KIQ seen through the pipe alias, and HIP/rocBLAS tests passed
> before and after the reset. Not tested on other gfx9 APUs.
>
> Fixes: c3988a7ad479 ("drm/amdgpu/gfx9: Fix Ring and IB test fail after mode2")
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6177
> Assisted-by: Claude Code
> Signed-off-by: Christoph Berliner <caberliner@gmail.com>
> ---
>
> Notes:
> v2:
> - squash the two patches into one (Alex)
> - deactivate the HQDs on all gfx9 APUs instead of only Renoir, replacing
> gfx_v9_0_deactivate_kcq_hqd() (Alex)
> - v1: https://lore.kernel.org/amd-gfx/CADnq5_OsKujx3VgWDNDYF_ANocTs0aswFaC3uGwZhp7fE+SBCQ@mail.gmail.com/
>
> drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 98 +++++++++++++++++++--------
> 1 file changed, 69 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> index 9d87ebbc4..2d8ab438c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> @@ -4076,39 +4076,79 @@ static int gfx_v9_0_hw_init(struct amdgpu_ip_block *ip_block)
> return r;
> }
>
> -static void gfx_v9_0_deactivate_kcq_hqd(struct amdgpu_device *adev)
> +/* caller must hold srbm_mutex and have selected me/pipe/queue */
> +static bool gfx_v9_0_deactivate_hqd(struct amdgpu_device *adev,
> + u32 me, u32 pipe, u32 queue)
> {
> - amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
> - for (int i = 0; i < adev->gfx.num_compute_rings; i++) {
> - u32 tmp;
> - struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
> + int j;
>
> - mutex_lock(&adev->srbm_mutex);
> - soc15_grbm_select(adev, ring->me, ring->pipe, ring->queue, 0, 0);
> - tmp = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
> - /* disable the queue if it's active */
> - if (tmp & CP_HQD_ACTIVE__ACTIVE_MASK) {
> - int j;
> -
> - WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 1);
> - for (j = 0; j < adev->usec_timeout; j++) {
> - tmp = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
> - if (!(tmp & CP_HQD_ACTIVE__ACTIVE_MASK))
> - break;
> - udelay(1);
> - }
> - if (j == AMDGPU_MAX_USEC_TIMEOUT) {
> - DRM_DEBUG("comp_%u_%u_%u dequeue request failed.\n",
> - ring->me, ring->pipe, ring->queue);
> - /* Manual disable if dequeue request times out */
> - WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
> + /* disable the queue if it's active */
> + if (!(RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK))
> + return false;
> +
> + WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 1);
> + for (j = 0; j < adev->usec_timeout; j++) {
> + if (!(RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE) &
> + CP_HQD_ACTIVE__ACTIVE_MASK))
> + break;
> + udelay(1);
> + }
> + if (j == adev->usec_timeout) {
> + dev_dbg(adev->dev, "comp_%u_%u_%u dequeue request failed.\n",
> + me, pipe, queue);
> + /* Manual disable if dequeue request times out */
> + WREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE, 0);
> + }
> + WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 0);
> +
> + return true;
> +}
> +
> +/*
> + * MODE2 does not reset the CP HQD registers on gfx9 APUs. Besides the KCQs,
> + * the HQDs owned by KFD (HIQ and the user queues mapped by the HWS) also stay
> + * active, because KFD cannot unmap/destroy them while the reset domain is
> + * locked. After MODE2 the MEC then resumes with stale HQDs and the HWS no
> + * longer answers (qcm fence timeout on the next KFD queue). Deactivate every
> + * active HQD of all MECs except the KIQ, which is reprogrammed on resume.
> + */
> +static void gfx_v9_0_deactivate_all_hqd(struct amdgpu_device *adev)
> +{
> + struct amdgpu_ring *kiq_ring = &adev->gfx.kiq[0].ring;
> + u64 kiq_mqd_addr = kiq_ring->mqd_gpu_addr & ~0x3ULL;
> + u32 me, pipe, queue, n = 0;
> + u64 mqd_addr;
> +
> + amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
> + mutex_lock(&adev->srbm_mutex);
> + for (me = 1; me <= adev->gfx.mec.num_mec; me++) {
> + for (pipe = 0; pipe < adev->gfx.mec.num_pipe_per_mec; pipe++) {
> + for (queue = 0; queue < adev->gfx.mec.num_queue_per_pipe;
> + queue++) {
> + if (me == kiq_ring->me && pipe == kiq_ring->pipe &&
> + queue == kiq_ring->queue)
> + continue;
> + soc15_grbm_select(adev, me, pipe, queue, 0, 0);
> + /*
> + * At least on Renoir the HQD registers of MEC2
> + * pipes 2/3 read back as those of pipes 0/1, so
> + * the KIQ shows up a second time. Skip it by its
> + * MQD address instead of sending it a dequeue.
> + */
> + mqd_addr = ((u64)RREG32_SOC15(GC, 0, mmCP_MQD_BASE_ADDR_HI) << 32) |
> + RREG32_SOC15(GC, 0, mmCP_MQD_BASE_ADDR);
> + if (mqd_addr == kiq_mqd_addr)
> + continue;
> + if (gfx_v9_0_deactivate_hqd(adev, me, pipe, queue))
> + n++;
> }
> - WREG32_SOC15(GC, 0, mmCP_HQD_DEQUEUE_REQUEST, 0);
> }
> - soc15_grbm_select(adev, 0, 0, 0, 0, 0);
> - mutex_unlock(&adev->srbm_mutex);
> }
> + soc15_grbm_select(adev, 0, 0, 0, 0, 0);
> + mutex_unlock(&adev->srbm_mutex);
> amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
> +
> + dev_dbg(adev->dev, "deactivated %u active compute HQDs before MODE2\n", n);
> }
>
> static int gfx_v9_0_hw_fini(struct amdgpu_ip_block *ip_block)
> @@ -4136,8 +4176,8 @@ static int gfx_v9_0_hw_fini(struct amdgpu_ip_block *ip_block)
> }
>
> if ((adev->flags & AMD_IS_APU) && amdgpu_in_reset(adev) &&
> - amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_MODE2)
> - gfx_v9_0_deactivate_kcq_hqd(adev);
> + amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_MODE2)
> + gfx_v9_0_deactivate_all_hqd(adev);
>
> /* Use deinitialize sequence from CAIL when unbinding device from driver,
> * otherwise KIQ is hanging when binding back
> --
> 2.56.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 15:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 6:46 [PATCH v2] drm/amdgpu/gfx9: deactivate all compute HQDs before MODE2 on APUs Christoph Berliner
2026-11-23 15:38 ` Alex Deucher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.