From: sashiko-bot@kernel.org
To: "Armas Spann" <zappel@simple-co.de>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 5/9] drm/amdkfd: keep queue storage until MES confirmed retirement
Date: Thu, 26 Nov 2026 08:39:42 +0000 [thread overview]
Message-ID: <sashiko-outbox-235045@kernel.org> (raw)
In-Reply-To: <20261125141933.154222-6-zappel@simple-co.de>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amdkfd: unretired queue visibility gap in
process_termination_cpsch()
- [Medium] drm/amdkfd: unbalanced SVM queue_refcount put when
kfd_queue_hold_buffers() fails
--
commit 1de59d68e639f24ab5a36271e17baa8bd9d8fd34
Author: Armas Spann <zappel@simple-co.de>
drm/amdkfd: keep queue storage until MES confirmed retirement
This commit quarantines queues whose retirement MES has not confirmed during
queue creation error cleanup, queue destruction, and process termination,
keeping their MQDs, IDs, and user buffer references until MES releases them.
> 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 0c72cf55224cc..eabb9a6953451 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
[ ... ]
> @@ -3813,7 +3846,22 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,
> mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
> q->properties.type)];
> list_del(&q->list);
> + q->dqm_dequeued = true;
> qpd->queue_count--;
> +
> + /*
> + * Decide once whether MES has let go. A late completion can
> + * change the answer at any time, and the SDMA id has to
> + * follow the same decision as the MQD.
> + */
> + if (!kfd_mes_queue_retired(dqm, q)) {
> + dqm_quarantine_queue(dqm, qpd, q);
> + continue;
> + }
> + if (q->properties.type == KFD_QUEUE_TYPE_SDMA ||
> + q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI)
> + deallocate_sdma_queue(dqm, q);
> +
> dqm_unlock(dqm);
> /* Repin the MQD BO if still evicted for hibernation, before free. */
> dqm_repin_mqd_bo(dqm, q);
[Severity: Medium]
Can an unretired queue in qpd->queues_list be missed by a concurrent MES
per-queue reset while dqm_lock(dqm) is dropped to free an earlier retired
queue's MQD?
process_termination_cpsch() unlinks qpd from dqm->queues before running this
drain loop, and find_queue_by_doorbell_offset() only searches dqm->queues and
dqm->zombie_queues:
CPU0 CPU1
process_termination_cpsch()
/* unlink qpd from dqm->queues */
/* q1 is retired, q2 is not */
list_del(&q1->list)
dqm_unlock(dqm)
kfd_reset_queue_mes()
dqm_lock(dqm)
find_queue_by_doorbell_offset(..., q2)
/* not in dqm->queues or
* dqm->zombie_queues -> NULL
*/
dqm_unlock(dqm)
mqd_mgr->free_mqd(..., q1->mqd, ...)
dqm_lock(dqm)
list_del(&q2->list)
dqm_quarantine_queue(dqm, qpd, q2)
If MES reports q2 as hung during that window, kfd_reset_queue_mes() fails to
find q2 and skips resetting and removing it in MES. Moving unretired queues
to dqm->zombie_queues before dropping dqm_lock(dqm), or unlinking qpd from
dqm->queues after qpd->queues_list is drained, would keep q2 visible.
> 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 ef9ad6dc874dc..e44ccc803024c 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
[ ... ]
> @@ -518,7 +530,23 @@ int pqm_create_queue(struct process_queue_manager *pqm,
> return retval;
>
> err_create_queue:
> - uninit_queue(q);
> + if (q && q->is_zombie) {
> + /*
> + * The dqm still needs the MQD, the ids and what MES uses. The
> + * user buffers are part of that: MES may yet execute the
> + * ADD_QUEUE and run the queue from them. The ioctl drops its
> + * references on them when this returns, so take our own. The
> + * reaper drops them once MES has let go of the queue.
> + */
> + if (kfd_queue_hold_buffers(pdd, &q->properties))
> + pr_warn("process pid %d: quarantined queue holds no reference on its CWSR area\n",
> + pqm->process->lead_thread->pid);
> + kfd_dqm_zombie_ready(dev->dqm, q);
[Severity: Medium]
If kfd_queue_hold_buffers() fails in kfd_queue_buffer_svm_get(), will the
zombie reaper later underflow prange->queue_refcount?
When kfd_queue_hold_buffers() returns an error, no extra SVM reference is
taken for the quarantined queue, and kfd_ioctl_create_queue() drops the
initial reference taken by kfd_queue_acquire_buffers(). Because
q->properties.ctx_save_restore_area_address and ctx_save_restore_area_size
remain set, kfd_dqm_release_zombie() -> kfd_queue_release_buffers() ->
kfd_queue_buffer_svm_put() still decrements prange->queue_refcount when the
zombie queue is reaped:
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c:kfd_dqm_release_zombie() {
...
mutex_lock(&p->mutex);
deallocate_doorbell(&pdd->qpd, q);
kfd_queue_unref_bo_vas(pdd, &q->properties);
kfd_queue_release_buffers(pdd, &q->properties, false);
mutex_unlock(&p->mutex);
...
}
If another queue of the process shares or reuses that SVM range for its CWSR
area before the zombie is reaped, its prange->queue_refcount is decremented
early, allowing the range to be unmapped without evicting the active queue.
Clearing q->properties.ctx_save_restore_area_address (or zeroing
ctx_save_restore_area_size) when kfd_queue_buffer_svm_get() fails would avoid
the unmatched put.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125141933.154222-1-zappel@simple-co.de?part=5
next prev parent reply other threads:[~2026-11-26 8:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 14:19 [PATCH v2 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU Armas Spann
2026-11-25 14:19 ` [PATCH v2 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
2026-11-26 8:36 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 2/9] drm/amdkfd: factor out freeing of per-queue MES resources Armas Spann
2026-11-25 14:19 ` [PATCH v2 3/9] drm/amdkfd: track whether MES knows each queue Armas Spann
2026-11-26 8:46 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 4/9] drm/amdkfd: add a quarantine for queues MES has not retired Armas Spann
2026-11-26 8:49 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 5/9] drm/amdkfd: keep queue storage until MES confirmed retirement Armas Spann
2026-11-26 8:39 ` sashiko-bot [this message]
2026-11-25 14:19 ` [PATCH v2 6/9] drm/amdkfd: keep eviction and restore consistent when MES fails Armas Spann
2026-11-26 8:36 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 7/9] drm/amdkfd: apply queue property updates only after unmap Armas Spann
2026-11-25 14:19 ` [PATCH v2 8/9] drm/amdkfd: reconcile queue state with MES after a restart Armas Spann
2026-11-25 14:19 ` [PATCH v2 9/9] drm/amdkfd: force CWSR on with more than one MES GPU Armas Spann
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-235045@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zappel@simple-co.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox