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 A1180606A685 for ; Fri, 4 Dec 2026 13:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=simple-co.de header.i=@simple-co.de header.a=rsa-sha256 header.s=201801 header.b=NFCm/nu7; dkim=pass (2048-bit key) header.d=simple-co.de header.i=@simple-co.de header.a=rsa-sha256 header.s=201801 header.b=JiNsjUTa Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45DAA112F7A; Fri, 4 Dec 2026 13:56:33 +0000 (UTC) Received: from mail.bin-co.de (mail.bin-co.de [37.120.183.211]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3C7010EB21 for ; Fri, 4 Dec 2026 12:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simple-co.de; s=201801; t=1796388784; bh=aGJTFbSPcEspYw1oTLI+PsdR0IQ5I3XJAfEvxVQ6weI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NFCm/nu7gNMv+r95wsB3W7pZ+Tc3dmfcuYQ2cKP4g1oS4iNsNzmte1HG4+JK0WwLT TWz9guTMomD+usfic6uzq2los5rvMhd28coMLMIsZtyg9G2+aeJ4dxZXpwVdJzG8dC 2qVyZ0IItI46ikWAsCwdxI/DyFhME2dGeaLVPIUK3/a0eA2/bhU2P4hAJdxhCczgxi Y5wTgmHqAqObdO6pkDV/Xkd6KSZM7M6xhg8iStBN3X/Nt/az1etuSfFn+ksljK8aT9 ixVIjxqKNU62g0AhSOjD6PIkSEYBtXcZR9T/rpOImm1gGsTdS9uQzarReE7MJX2a4l HjJ1d10UtZGUg== Received: from localhost (localhost [127.0.0.1]) by mail.bin-co.de (Postfix) with ESMTP id 6879117F36A; Fri, 04 Dec 2026 13:53:04 +0100 (CET) X-Virus-Scanned: Debian amavis at v2202603343726440230.luckysrv.de Received: from mail.bin-co.de ([127.0.0.1]) by localhost (mail.bin-co.de [127.0.0.1]) (amavis, port 10024) with ESMTP id MJhzP7hy66MO; Fri, 4 Dec 2026 13:53:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simple-co.de; s=201801; t=1796388783; bh=aGJTFbSPcEspYw1oTLI+PsdR0IQ5I3XJAfEvxVQ6weI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JiNsjUTac7hUeMcoUVMbtb1KYeDXjEu/Uf1cCQLydfCPsizB7Ecg6l7JmTGDvvrkg eZeUwDjzWjoSMthQWUARKRmwgATJC/xHlx1Qfh71rKTZFBdqlBxaj/QQuz6Co2iztj zh4mgjxZ1JeJ76fvMYbPIB81G56upmMtW1l06kbe2TwC7XfB8Vbjadvr1b2J+7YoAl ENIJSlfELIcQJhact6UXz8xK7+CpYHq+IxUUHbQ1lhZzTXTOLe5gHB4q2T7ZHM7vXP HkPeLHe/UX3gsR5w5Q2TrT4C5IZuQj7HFHinNSII73pv6wKOboimDH3qguXU2XqZXn qalOks9q1XTDg== Received: from deepblue.zlan.intra (wan.zappel.net [IPv6:2a02:8106:4:c300::1]) (Authenticated sender: zappel@simple-co.de) by mail.bin-co.de (Postfix) with ESMTPSA id EDE5F17F62B; Fri, 04 Dec 2026 13:53:02 +0100 (CET) From: Armas Spann To: amd-gfx@lists.freedesktop.org Cc: alexander.deucher@amd.com, christian.koenig@amd.com, Felix.Kuehling@amd.com, Armas Spann Subject: [PATCH 8/8] drm/amdkfd: reconcile queue state with MES after a restart Date: Fri, 4 Dec 2026 13:52:50 +0100 Message-ID: <20261204125251.10703-9-zappel@simple-co.de> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204125251.10703-1-zappel@simple-co.de> References: <20261204125251.10703-1-zappel@simple-co.de> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 04 Dec 2026 13:56:23 +0000 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=-19.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 A GPU reset or a resume sets the MES firmware up from scratch, and the new instance knows no user queues. KFD keeps the processes that lived through a reset, evicted, until they exit. Their queues cannot be removed cleanly on the way into the reset, because every REMOVE_QUEUE fails with -EIO at that point, so they can still be recorded as mapped or as unconfirmed when the scheduler starts again. A REMOVE_QUEUE that was left unanswered before the restart still owns its status slot, and the fence that such a command raised is still in place. kfd_mes_queue_retired() and kfd_mes_fenced() put each of these right when they are next asked, which for a queue of a process that just sits there until it exits can be a long time. Do it in one place instead, when the scheduler starts: walk the queues of every process, drop the MES state that belongs to an earlier firmware instance, release the status slots of commands that were lost with it, and lift the fence that was raised for such a command. Say how many queues the firmware forgot, so that a log shows the restart from the KFD side. The queues are inactive by then. Every path that restarts the firmware with live processes evicts them first, through kgd2kfd_pre_reset() or kgd2kfd_suspend(), and kgd2kfd_post_reset() marks them as reset before the scheduler starts. The reconcile does not deactivate queues itself; a queue it finds still marked active is reported, because a restart path has then forgotten to evict. Signed-off-by: Armas Spann Co-Authored-By: Claude Fable 5.2 --- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c index c31844cf5..11a7c637a 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -2883,6 +2883,66 @@ static int init_dequeue_wait_counts_mes(struct device_queue_manager *dqm) return 0; } +/* + * Bring the queue bookkeeping in line with MES when the scheduler starts. + * + * If the MES firmware was set up from scratch since a queue was added (GPU + * reset, resume), it has no record of that queue. A GPU reset cannot evict + * cleanly: the REMOVE_QUEUE commands fail with -EIO while the reset is + * running, so a queue can still be recorded as mapped or unconfirmed here. + * kfd_mes_queue_retired() would put that right when the queue is next + * looked at, which can be as late as the exit of its process. + * + * So drop the stale MES state here, return the status slots of commands + * that were lost with the old firmware, and lift the fence raised for one + * of them. The queues themselves are inactive at this point: every path + * that restarts the firmware with live processes evicts them first, and an + * eviction marks every queue inactive whether MES confirmed its removal or + * not. A queue that is still marked active means a restart path forgot to + * evict; say so, but leave the counters to the paths that own them. + * + * dqm lock held. + */ +static void kfd_dqm_reconcile_mes_queues(struct device_queue_manager *dqm) +{ + struct device *dev = dqm->dev->adev->dev; + struct device_process_node *cur; + struct qcm_process_device *qpd; + unsigned int stale = 0, active = 0; + struct queue *q; + + if (!dqm->dev->kfd->shared_resources.enable_mes) + return; + + /* A command that got no answer died with the old firmware */ + kfd_mes_fenced(dqm); + + list_for_each_entry(cur, &dqm->queues, list) { + qpd = cur->qpd; + list_for_each_entry(q, &qpd->queues_list, list) { + /* Not in MES, or added to the instance now running */ + if (q->mes_state == KFD_MES_QUEUE_UNMAPPED || + q->mes_fw_gen == kfd_mes_gen(dqm)) + continue; + + /* Also returns the status slot of a lost command */ + kfd_mes_queue_retired(dqm, q); + stale++; + + if (q->properties.is_active) + active++; + } + } + + if (active) + dev_warn(dev, + "MES was restarted with %u queue(s) still marked active, they were not evicted\n", + active); + if (stale) + dev_info(dev, "MES was restarted, forgot %u user queue(s)\n", + stale); +} + static int start_cpsch(struct device_queue_manager *dqm) { struct device *dev = dqm->dev->adev->dev; @@ -2947,6 +3007,8 @@ static int start_cpsch(struct device_queue_manager *dqm) hqd_info_size * sizeof(struct amdgpu_mes_hung_queue_hqd_info), GFP_KERNEL); + kfd_dqm_reconcile_mes_queues(dqm); + /* A restart of the MES firmware retires every quarantined queue */ if (!list_empty(&dqm->zombie_queues)) mod_delayed_work(system_dfl_wq, &dqm->zombie_work, 0); -- 2.47.3