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 BC9ED606A330 for ; Fri, 4 Dec 2026 13:56:38 +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=Eq7m+ki1; dkim=pass (2048-bit key) header.d=simple-co.de header.i=@simple-co.de header.a=rsa-sha256 header.s=201801 header.b=isJyJ4N/ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C584112F92; Fri, 4 Dec 2026 13:56:28 +0000 (UTC) Received: from mail.bin-co.de (mail.bin-co.de [37.120.183.211]) by gabe.freedesktop.org (Postfix) with ESMTPS id 84BA210E9EB for ; Fri, 4 Dec 2026 12:53:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simple-co.de; s=201801; t=1796388782; bh=r2EsVYcThWzG4e3pX3keAE0qLXT9GzJN+0u5jN/4PAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eq7m+ki1xiWHChEIWGxMWGcUyM084CTmanDhEqoAMrKocaqA/VqgtX5Uu+I7dtifO +rYoipA9APIjO+6amv2xllkYXx1WVfkoClWYEW0e0NbmLhEFjYL3kGideux1iq81EZ zQ0VebIWLz7JFebhFNFPxieqHOFRTkucLfGL1G5HPIT6dVlpi2bY4mjaYyYEoKlo+8 /ArLk12K4BvUQqtgsZ+VXALwg0ojfw/xsQTg6nkirCChPz4+oygAeA3iedq3oYs7vY Fk2qf28uWYutfx59Cj51tg7eQ72hG9dG3USMqklrbW7AqCJo21o7NmMfyq3cU7Nzq+ Djyuma9vMAXGA== Received: from localhost (localhost [127.0.0.1]) by mail.bin-co.de (Postfix) with ESMTP id 3D05017F370; Fri, 04 Dec 2026 13:53:02 +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 MU2OtoZb1TGw; Fri, 4 Dec 2026 13:53:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simple-co.de; s=201801; t=1796388781; bh=r2EsVYcThWzG4e3pX3keAE0qLXT9GzJN+0u5jN/4PAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=isJyJ4N/mkjFxVByCLscAMR4pRFlF2VqNwyZKW3SqapwPa1+1xhPLKOKxRBZfZJfZ lX1D/Xo+5PTHlkaSDU3hCQvRLeRU41q9VAA7glRYfp8ISdHMWFd2YjwwW/7OYEfl1Q s2hDHClBWbEeWR5aHpBzzIargC0LjGOhL4+wwPrGaZW8/DrEjHoxo82yrh7Kh6puqF Gnv/9yYD4ZgS7+BQDTItMmL0LHstP+t77uT3O8KRuLEZwbZAoJdECZwWa61OrfW1wY htuG9OBwkzFb7dTObzKMDk2wEhR75QBuycLXH05cey35uyl9uD35pCtd83OmGI7qDA B83q7laESoF9A== 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 904FB17F36C; Fri, 04 Dec 2026 13:53:01 +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 2/8] drm/amdkfd: make the per-queue MES resource cleanup usable by the dqm Date: Fri, 4 Dec 2026 13:52:44 +0100 Message-ID: <20261204125251.10703-3-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 pqm_free_mes_queue_res() frees the parts of a queue that only exist for MES: the gang context with its slot, and the GART mapping of the write pointer. It is static to the pqm, and both of its callers test for MES before they call it. The dqm is about to free these resources itself, at the point where MES is known to have let go of a queue. Rename the helper to kfd_queue_free_mes_resources(), move the test for MES into it and declare it in kfd_priv.h. No functional change. Signed-off-by: Armas Spann Co-Authored-By: Claude Fable 5.2 --- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + .../drm/amd/amdkfd/kfd_process_queue_manager.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 8eac086aa..74655b001 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1389,6 +1389,7 @@ int kfd_criu_resume_queues(struct kfd_process *p); /* Queue Context Management */ int init_queue(struct queue **q, const struct queue_properties *properties); void uninit_queue(struct queue *q); +void kfd_queue_free_mes_resources(struct kfd_node *dev, struct queue *q); void print_queue_properties(struct queue_properties *q); void print_queue(struct queue *q); int kfd_queue_buffer_get(struct amdgpu_vm *vm, void __user *addr, struct amdgpu_bo **pbo, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c index 6a9d7d31c..700155f39 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -187,8 +187,17 @@ int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p) return 0; } -static void pqm_free_mes_queue_res(struct kfd_node *dev, struct queue *q) +/* + * Free the storage that only exists so MES can run the queue: the gang + * context with its slot and the GART mapping of the write pointer. MES + * addresses them directly, so the queue must be out of MES before this is + * called. + */ +void kfd_queue_free_mes_resources(struct kfd_node *dev, struct queue *q) { + if (!dev->kfd->shared_resources.enable_mes) + return; + amdgpu_mes_free_gang_ctx_index(&dev->adev->mes, q->gang_ctx_array_index); amdgpu_amdkfd_free_kernel_mem(dev->adev, &q->gang_ctx_bo); amdgpu_amdkfd_free_kernel_mem(dev->adev, (void **)&q->wptr_bo_gart); @@ -218,8 +227,7 @@ static void pqm_clean_queue_resource(struct process_queue_manager *pqm, pdd->qpd.num_gws = 0; } - if (dev->kfd->shared_resources.enable_mes) - pqm_free_mes_queue_res(dev, pqn->q); + kfd_queue_free_mes_resources(dev, pqn->q); } void pqm_uninit(struct process_queue_manager *pqm) @@ -492,8 +500,8 @@ int pqm_create_queue(struct process_queue_manager *pqm, return retval; err_create_queue: - if (q && dev->kfd->shared_resources.enable_mes) - pqm_free_mes_queue_res(dev, q); + if (q) + kfd_queue_free_mes_resources(dev, q); uninit_queue(q); if (kq) kernel_queue_uninit(kq); -- 2.47.3