From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88A05606A320 for ; Mon, 30 Nov 2026 21:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hFtpCRYS Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27A5E10F4C6; Mon, 30 Nov 2026 21:40:55 +0000 (UTC) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id C9DC610E0C7 for ; Mon, 30 Nov 2026 21:40:48 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-4ad6219f7d8so10032424f8f.0 for ; Mon, 30 Nov 2026 13:40:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796074847; x=1796679647; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=eCMuyYIDEhs2DCjClUaNPozar6Xr9K0vVc7ZFwOeJF0=; b=hFtpCRYSfM2GKB60yd7sj4OHph+jjEsz3tDFrxOJlfqCNjRCSGiysvBYjKPxsHJIvw /qkGZZm+PKO5qDKAOlL6uKuw/GVNjBEpiDGoxbgXGJ6YO683zyYZdO0pL4QRTpK9nxG6 rU1l2slfd8hxbHGAF3DWSXyjoIkbPnK2SZ7TbPgBvnvvEScfKCMGVUnDuzPyOsEtKesf JJPB5SavXY9TzAh0OPNifgwMuOpu1YoymsYE1RYzx4EhAmABastmeeJQaOOHibvRbpK3 HkUAhfP0OE4SYf/cgq69suSJkJNX+XwnIBBGRlxA+YFEF4qcR2VU2mmxo8bHBjl6DGNo GKxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796074847; x=1796679647; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eCMuyYIDEhs2DCjClUaNPozar6Xr9K0vVc7ZFwOeJF0=; b=Q81PqAEa5XVaTFkIIpPktsWBLfBUcQqSPLRITtq8eVhH7G9CzHgwfLmNjlT3PqsmNE /V4jrSegVuJR/Mg0/a4+Hr5ZSuXoxOv3drg3YBwPPxzxkKphQjHhR1+EkzkrUlY5lWU9 2ZnWxXhoKldEe99KmpwTRGQ6a/He5ISj/3+AM/mZsZbkK/vM18yOMvbL4K9nE3/nPY/Z LL8eX7s/3abJq/z9KbvOdRvLwcZ3EGk0HP5+Z4r336hPP4/vSSoTxPrpnlOq+jznp7pf F3Pa8cqI90HoLIPWxF1OxAH3K/A9+Nse7hCl0xe7EkYgZj9PAaf/OxS7h2bSplhv2qjE wWYA== X-Gm-Message-State: APuU4Z+rYyEED2qMDYzQKD/6IILDE22nQMacaz1QJ6X2GcX0VhEcQkiz qihbZmMUTBlFU1H6dswIxOHDk8iZ2+5Pk/SY/JoLFTUUodXjz9w+zCXsOt2Dag== X-Gm-Gg: AZFdTZcNHpJx7bhTtqEHO6MTpc8mQ1yZ/nYr7mTKZdOBECYYseI/LumOZX0GtkHUQFI L/joxiVy0ny5+hfm1LkDMxhlu2mo11ZEnxSQ+QnTgcQTL6d6z9oYr2HFluNruCd73Ss47SLxrjE ESo2c+B/7VQB0UMdwsy23NPiCGJG7c4hAq1sGzJFvH3wQcS6QojNY6kyrys4swAAMV35kbLNwJI jSeeRuunF3BUu85V79qdhy4pmc89TVPt9rkEqX/KVHdLCSzvE3/FisI4JVGtjPBdwBo93MtS2np WOjtjJK0dpCKwYEotGpQYrY0M9fxgGTbuZN9pKL7fDEoh9XrzX7wuUf7xya2KwhRvDmXtSUHmOQ igbasb+UzfkyxRw6glfWBChUJNyMxMoS+iLaBYkAN3L2m6EgNzP1zgoLZtQ2EgCaBxtiyi9Yr5B 873+/OHdVTxH3RZGYpG/nsqTs2naGphymYw5fkHRB98qFAHGFppjjZglHapjTpqZBjPb0rQJ8pM jWjTes3VjqPQ6DH77JZ10cnsbxTEBYA3nlbYJwRhH0rjPpKlL8BP4vtrf/wllXg8H+wJaRZqUZh MWqk0eT+5a8OW7CksA/rL0XTT41V7oLhZQMU58KhMS/y9msXtnt3HmAYcLmotxQizddLwKqE5Yi MlY0bdS8ADrVPiN4aaZlD X-Received: by 2002:a05:6000:188b:b0:4af:e519:cce8 with SMTP id ffacd0b85a97d-4afe519cf4fmr59980302f8f.34.1796074847004; Mon, 30 Nov 2026 13:40:47 -0800 (PST) Received: from Arbeitszimmer ([2001:9e8:db35:a900:494b:f241:7ea9:4bb5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b110c50sm65875558f8f.37.2026.11.30.13.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:40:46 -0800 (PST) From: Christoph Berliner To: amd-gfx@lists.freedesktop.org Cc: alexander.deucher@amd.com, christian.koenig@amd.com, Jiqian.Chen@amd.com, Christoph Berliner Subject: [PATCH] drm/amdgpu/gfx9: deactivate the KIQ before MODE2 on APUs Date: Mon, 30 Nov 2026 22:40:40 +0100 Message-ID: <20261130214040.61052-1-caberliner@gmail.com> X-Mailer: git-send-email 2.56.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 MODE2 does not reset the CP HQD registers on gfx9 APUs. "drm/amdgpu/gfx9: deactivate all compute HQDs before MODE2 on APUs" deactivates all compute HQDs before MODE2 except the KIQ, on the assumption that gfx_v9_0_kiq_init_register() reprograms it on resume. It does, but the KIQ HQD is then still active, so kiq_init_register() takes its "disable the queue if it's active" branch and issues CP_HQD_DEQUEUE_REQUEST right after gfx_v9_0_cp_resume() has halted the MEC and put its pipes into reset. Recovery itself succeeds, but the CP fetcher never becomes idle again. Right after the KIQ setup CP_CPF_BUSY_STAT shows a pending HQD message (HQD_MESSAGE_BUSY, HQD_ROQ_ALIGN_BUSY, HQD_ROQ_PQ_BUSY, HQD_FETCHER_ARB_BUSY). From then on CP_CPF_STATUS keeps HQD_BUSY, CP_CPF_BUSY_STAT keeps HQD_ROQ_PQ_BUSY/HQD_FETCHER_ARB_BUSY and GRBM reports CP_BUSY, while CP_STAT and CP_CPC_BUSY_STAT are 0 and no HQD has pending work. The RLC therefore never sees the GFX block idle: clock gating and light sleep stay off (RLC_GPM_STAT), gpu_busy_percent reads 99 and the sclk stays at the top DPM level until the next reboot. On a fresh boot the KIQ HQD starts inactive and the CPF stays idle after the KIQ setup. Run the CAIL deinitialize sequence that is already used when unbinding the driver (gfx_v9_0_kiq_fini_register()) before MODE2 on APUs as well. The dequeue is then handled while the MEC is still running, exactly like on unbind, and the KIQ is set up after the reset the same way as on boot. Nothing uses the KIQ after this point of gfx hw_fini during a reset: KCQ unmapping and the GMC TLB flushes are skipped while the reset domain is locked, and KFD only uses the KIQ again in post-reset, after it has been set up again. Tested on Ryzen 5 5600G (Cezanne, gfx90c, GC 9.3.0), MEC firmware 0x1e3, HWS enabled, amdgpu.noretry=1, with forced MODE2 resets on an idle GPU via amdgpu_gpu_recover. Without this change the GPU stayed at 99 % / max sclk after every reset (5 forced resets, each from a fresh boot; one run instrumented: CPF idle at the start of gfx_v9_0_hw_init() and busy right after gfx_v9_0_kiq_resume()). With it (3 forced resets, two of them in the same boot without a reboot in between): the KIQ HQD is inactive at hw_init, the CPF is idle after the KIQ setup, and after the resets the GPU idles at 0 % / 400 MHz as after boot, with RLC_GPM_STAT back to its pre-reset value. HIP/rocBLAS and Vulkan work afterwards. Not tested on other gfx9 APUs, and not tested with a reset after a real hang. Fixes: c3988a7ad479 ("drm/amdgpu/gfx9: Fix Ring and IB test fail after mode2") Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6206 Assisted-by: Claude:Opus 5.5 Signed-off-by: Christoph Berliner --- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c index 2d8ab438c..c34322442 100644 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c @@ -4110,7 +4110,8 @@ static bool gfx_v9_0_deactivate_hqd(struct amdgpu_device *adev, * 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. + * active HQD of all MECs except the KIQ, which gfx_v9_0_hw_fini() deactivates + * separately with the CAIL deinitialize sequence. */ static void gfx_v9_0_deactivate_all_hqd(struct amdgpu_device *adev) { @@ -4180,9 +4181,15 @@ static int gfx_v9_0_hw_fini(struct amdgpu_ip_block *ip_block) gfx_v9_0_deactivate_all_hqd(adev); /* Use deinitialize sequence from CAIL when unbinding device from driver, - * otherwise KIQ is hanging when binding back + * otherwise KIQ is hanging when binding back. MODE2 does not reset the + * HQD registers on APUs either, so do the same before MODE2: otherwise + * the KIQ HQD is still active after the reset, kiq_init_register() + * dequeues it while the MEC is halted, and the CPF stays busy, so GFX + * never goes idle again until reboot. */ - if (!amdgpu_in_reset(adev) && !adev->in_suspend) { + if ((!amdgpu_in_reset(adev) && !adev->in_suspend) || + ((adev->flags & AMD_IS_APU) && amdgpu_in_reset(adev) && + amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_MODE2)) { mutex_lock(&adev->srbm_mutex); soc15_grbm_select(adev, adev->gfx.kiq[0].ring.me, adev->gfx.kiq[0].ring.pipe, -- 2.56.1