All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mukul Joshi" <mukul.joshi@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCHv2 2/2] drm/amdkfd: remove all queues of a process with a single MES call
Date: Fri, 04 Dec 2026 03:57:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-249073@kernel.org> (raw)
In-Reply-To: <20261204033433.939162-2-mukul.joshi@amd.com>

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 <mukul.joshi@amd.com>

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/drivers/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;
>  
>  	memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
> -	queue_input.doorbell_offset = q->properties.doorbell_off;
> -	queue_input.gang_context_addr = q->gang_ctx_gpu_addr;
> -	queue_input.queue_type = convert_to_amdgpu_ring_type(q->properties.type);
> -	queue_input.remove_queue_after_reset = flush_mes_queue;
> +	if (q) {
> +		queue_input.doorbell_offset = q->properties.doorbell_off;
> +		queue_input.gang_context_addr = q->gang_ctx_gpu_addr;
> +		queue_input.queue_type = convert_to_amdgpu_ring_type(q->properties.type);
> +		queue_input.remove_queue_after_reset = flush_mes_queue;
> +		queue_input.gang_context_array_index = q->gang_ctx_array_index;
> +	} else {
> +		queue_input.remove_all_process_queues = true;
> +		queue_input.pasid = qpd_to_pdd(qpd)->pasid;
> +	}
>  	queue_input.xcc_id = ffs(dqm->dev->xcc_mask) - 1;
> -	queue_input.gang_context_array_index = 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 = 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 device_queue_manager *dqm,
>  	if (dqm->dev->kfd->shared_resources.enable_mes)
>  		pdd->last_evict_timestamp = get_jiffies_64();
>  
> +	remove_all = dqm->dev->kfd->shared_resources.enable_mes &&
> +		     amdgpu_mes_remove_all_process_queues_supported(dqm->dev->adev);
> +	if (remove_all) {
> +		retval = 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 = false;
>  		decrement_queue_count(dqm, qpd, q);
>  
> -		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 = KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES;
>  	}
>  
> +	remove_all = dqm->dev->kfd->shared_resources.enable_mes &&
> +		     amdgpu_mes_remove_all_process_queues_supported(dqm->dev->adev);
> +	if (remove_all) {
> +		retval = 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 == 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);
>  
> -			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 <= 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204033433.939162-2-mukul.joshi@amd.com?part=1

  reply	other threads:[~2026-12-04  3:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  3:33 [PATCHv2 1/2] drm/amdgpu: add remove all process queues support for MES v12.1 Mukul Joshi
2026-12-04  3:33 ` [PATCHv2 2/2] drm/amdkfd: remove all queues of a process with a single MES call Mukul Joshi
2026-12-04  3:57   ` sashiko-bot [this message]
2026-12-04  9:12   ` Lin, Amber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-249073@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=mukul.joshi@amd.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.