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 845D7606A32C for ; Fri, 4 Dec 2026 03:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KhIcofRX Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 26CC910E2C2; Fri, 4 Dec 2026 03:57:38 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id A14F710E2C2 for ; Fri, 4 Dec 2026 03:57:31 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id D979662079; Fri, 4 Dec 2026 03:57:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EE2E1F000C2; Fri, 4 Dec 2026 03:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796356650; bh=ZJNJgJ8lB7MUtzoKBzOus1hC3O+Z3vFYr2aa1a4fRaM=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=KhIcofRXPeFtwKNyBpZX0arO7M6W/oL64oa9Zo5E8TfUR3UhhdqMp05fywtbQs5kW fCoT7CYpUbF2RPPR7GKO3dJtwuY98I+sCLsreET3ezFAzx/Yqz3HxbPmQ9OrBN8iOY p9qQBAsbrj+AnJBhNnUBTZa39PSxia6QgiljRvCMNjxMr5treQj+lRG1TE6JQ9TZW2 1gKkv9Xl6MXY/VQB+oJGq1ImzdPaia4VcMGsiUsYZK3/Ni1srsqH9SBPx/MDprmNU7 9KNiOPskoXVAlBspOO/UOo72kvfuoBjgFw5zt55g4I7XB+siPKNDftn4c1dB2Ke/Lm Ty7Ov4hPtf1pg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCHv2 2/2] drm/amdkfd: remove all queues of a process with a single MES call To: "Mukul Joshi" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261204033433.939162-2-mukul.joshi@amd.com> References: <20261204033433.939162-1-mukul.joshi@amd.com> <20261204033433.939162-2-mukul.joshi@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 03:57:30 +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: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/amdkfd: missing MES remove-all helper and struct fields break build - [High] drm/amdkfd: evict_process_queues_cpsch() skips deactivation on MES failure - [Medium] drm/amdkfd: remove_queue_mes() checks stale CP count before decrement - [Medium] drm/amdkfd: PASID-wide MES queue removal lacks KFD-only scoping -- commit e0606d38e1af80c9aaba07fcf657c4bd8a4b5eac Author: Mukul Joshi drm/amdkfd: remove all queues of a process with a single MES call This commit updates KFD to remove all active MES queues of a process in a single request by PASID during eviction, termination, and scheduler halt/stop when MES supports it. It also adapts the MES queue reset path to retry the bulk request or remove remaining queues after resetting hung ones. > diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/driv= ers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c > index cc7a1f770408f..f8f7291e4266d 100644 > --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c [ ... ] > @@ -318,12 +339,17 @@ static int remove_queue_mes_on_reset_option(struct = device_queue_manager *dqm, st > return -EIO; > =20 > memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input)); > - queue_input.doorbell_offset =3D q->properties.doorbell_off; > - queue_input.gang_context_addr =3D q->gang_ctx_gpu_addr; > - queue_input.queue_type =3D convert_to_amdgpu_ring_type(q->properties.ty= pe); > - queue_input.remove_queue_after_reset =3D flush_mes_queue; > + if (q) { > + queue_input.doorbell_offset =3D q->properties.doorbell_off; > + queue_input.gang_context_addr =3D q->gang_ctx_gpu_addr; > + queue_input.queue_type =3D convert_to_amdgpu_ring_type(q->properties.t= ype); > + queue_input.remove_queue_after_reset =3D flush_mes_queue; > + queue_input.gang_context_array_index =3D q->gang_ctx_array_index; > + } else { > + queue_input.remove_all_process_queues =3D true; > + queue_input.pasid =3D qpd_to_pdd(qpd)->pasid; > + } > queue_input.xcc_id =3D ffs(dqm->dev->xcc_mask) - 1; > - queue_input.gang_context_array_index =3D q->gang_ctx_array_index; [Severity: High] Are prerequisite amdgpu MES patches missing from this commit? struct mes_remove_queue_input in drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h does not have remove_all_process_queues or pasid fields, and amdgpu_mes_remove_all_process_queues_supported() is neither declared nor defined anywhere in the tree. This breaks the build whenever CONFIG_HSA_AMD is enabled. [Severity: Medium] Can this PASID-wide MES removal also unmap KGD usermode queues that share the same VM? A process can acquire a DRM render file's VM in KFD via kfd_process_device_init_vm(), which sets pdd->pasid =3D avm->pasid, and also create KGD userqueues on the same fpriv->vm via amdgpu_userq_create(). mes_userq_map() registers those KGD userqueues in MES under the same PASID, and the bulk request here passes only pasid and xcc_id with no KFD-only discriminator. If MES firmware removes all queues for that PASID rather than scoping the request to KFD queues, KGD userqueues would be unmapped while amdgpu_userq still tracks them as mapped. KFD restore paths only re-add KFD queues, and a later amdgpu_userq_destroy() failure to unmap the already-removed queue schedules uq_mgr->reset_work for a full GPU reset. [ ... ] > @@ -1514,6 +1570,17 @@ static int evict_process_queues_cpsch(struct devic= e_queue_manager *dqm, > if (dqm->dev->kfd->shared_resources.enable_mes) > pdd->last_evict_timestamp =3D get_jiffies_64(); > =20 > + remove_all =3D dqm->dev->kfd->shared_resources.enable_mes && > + amdgpu_mes_remove_all_process_queues_supported(dqm->dev->adev); > + if (remove_all) { > + retval =3D remove_queue_mes(dqm, NULL, qpd); > + if (retval) { > + dev_err(dev, "Failed to evict queues of pasid 0x%x\n", > + pdd->pasid); > + goto out; > + } > + } > + > /* Mark all queues as evicted. Deactivate all active queues on > * the qpd. > */ > @@ -1525,7 +1592,7 @@ static int evict_process_queues_cpsch(struct device= _queue_manager *dqm, > q->properties.is_active =3D false; > decrement_queue_count(dqm, qpd, q); > =20 > - if (dqm->dev->kfd->shared_resources.enable_mes) { > + if (dqm->dev->kfd->shared_resources.enable_mes && !remove_all) { [Severity: High] Does bailing out to out here leave every queue marked active and unevicted while qpd->evicted has already been incremented to 1? When remove_queue_mes() returns -EIO (for instance during a concurrent GPU reset), kfd_process_evict_queues() treats -EIO as a completed eviction and expects the queues to have been marked evicted and inactive. Because the loop below is skipped, q->properties.is_active stays true and decrement_queue_count() is never called; a subsequent restore_process_queues_cpsch() then calls increment_queue_count() again, corrupting active_queue_count, active_cp_queue_count, and gws_queue_count. On a non--EIO error, kfd_process_evict_queues() does not restore this PDD, leaving qpd->evicted stuck at 1 while its queues remain active so future evictions are silently skipped. [ ... ] > @@ -3298,6 +3366,15 @@ static int process_termination_cpsch(struct device= _queue_manager *dqm, > filter =3D KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES; > } > =20 > + remove_all =3D dqm->dev->kfd->shared_resources.enable_mes && > + amdgpu_mes_remove_all_process_queues_supported(dqm->dev->adev); > + if (remove_all) { > + retval =3D remove_queue_mes(dqm, NULL, qpd); > + if (retval) > + dev_err(dev, "Failed to remove queues of pasid 0x%x\n", > + qpd_to_pdd(qpd)->pasid); > + } > + > /* Clear all user mode queues */ > list_for_each_entry(q, &qpd->queues_list, list) { > if (q->properties.type =3D=3D KFD_QUEUE_TYPE_SDMA) > @@ -3308,7 +3385,7 @@ static int process_termination_cpsch(struct device_= queue_manager *dqm, > if (q->properties.is_active) { > decrement_queue_count(dqm, qpd, q); > =20 > - if (dqm->dev->kfd->shared_resources.enable_mes) { > + if (dqm->dev->kfd->shared_resources.enable_mes && !remove_all) { [Severity: Medium] Can calling remove_queue_mes() before decrement_queue_count() here and in evict_process_queues_cpsch() leave dqm->notify_unmap_work armed on GFX11? remove_queue_mes() only cancels dqm->notify_unmap_work when dqm->active_cp_queue_count <=3D get_cp_queues_num(dqm). Because decrement_queue_count() now runs after remove_queue_mes(), the check sees the stale pre-decrement count and skips cancellation even when eviction or termination clears oversubscription, causing mes_notify_unmap_work_handler() to fire a spurious amdgpu_mes_notify_unmap_queue() RPC. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204033433.9391= 62-2-mukul.joshi@amd.com?part=3D1