From: sashiko-bot@kernel.org
To: "Armas Spann" <zappel@simple-co.de>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v1 8/9] drm/amdkfd: reconcile queue state with MES after a restart
Date: Tue, 24 Nov 2026 16:53:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-231614@kernel.org> (raw)
In-Reply-To: <20261124143433.49736-9-zappel@simple-co.de>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/amdkfd: set_queue_as_reset() clears is_active before MES
reconciliation
- [Medium] drm/amdkfd: kfd_dqm_reconcile_mes_queues() skips active
unmapped queues
- [Medium] drm/amdkfd: incomplete process eviction in
kfd_dqm_reconcile_mes_queues()
--
commit 57ed11ff8b41067e05295c9b1d33b02e617c5472
Author: Armas Spann <zappel@simple-co.de>
drm/amdkfd: reconcile queue state with MES after a restart
This commit adds kfd_dqm_reconcile_mes_queues() to start_cpsch() to drop
stale MES queue state, release lost command tickets, and mark active queues
and their processes evicted after an MES firmware restart.
> 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 1c348f36cd3c3..f008b05e95993 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> @@ -2649,6 +2649,74 @@ 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, and whatever was not marked inactive at that point stays active
> + * in the driver. The next REMOVE_QUEUE for such a queue, typically when its
> + * process exits, is rejected by the new firmware instance and that failure
> + * is escalated to another GPU reset.
> + *
> + * So drop the stale MES state here, and deactivate every queue that the
> + * driver still counts as running although MES has lost it. KFD does not
> + * resume processes after a GPU reset. Such a queue is marked evicted, and
> + * its process with it, which is the state kgd2kfd_pre_reset() leaves all
> + * the queues in that it did manage to evict. After a system resume
> + * kfd_resume_all_processes() maps the queues again from that state.
> + *
> + * 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;
[Severity: Medium]
Can skipping queues with q->mes_state == KFD_MES_QUEUE_UNMAPPED leave an
unmapped queue marked q->properties.is_active == true across stop_cpsch() and
start_cpsch()?
When stop_cpsch() calls remove_all_kfd_queues_mes(), remove_queue_mes() transitions
any still-active queue to KFD_MES_QUEUE_UNMAPPED without clearing
q->properties.is_active (and add_queue_mes() similarly returns 0 without mapping
into MES while !dqm->sched_running). Because start_cpsch() does not re-add active
queues when MES is enabled and restore_process_queues_cpsch() skips queues whose
q->properties.is_active is true, such a queue is never re-added to MES on resume.
> +
> + /* Also returns the status slot of a lost command */
> + kfd_mes_queue_retired(dqm, q);
> + stale++;
> +
> + if (!q->properties.is_active)
> + continue;
[Severity: High]
Does set_queue_as_reset() clear q->properties.is_active before
kfd_dqm_reconcile_mes_queues() runs on a GPU reset, preventing queues and
their qpd from being marked evicted here?
In kgd2kfd_post_reset(), kfd_dqm_set_queues_as_reset() runs before
kfd_resume() -> start_cpsch():
drivers/gpu/drm/amd/amdkfd/kfd_device.c:kgd2kfd_post_reset() {
...
for (i = 0; i < kfd->num_nodes; i++)
kfd_dqm_set_queues_as_reset(kfd->nodes[i]->dqm);
for (i = 0; i < kfd->num_nodes; i++) {
ret = kfd_resume(kfd->nodes[i]);
...
}
set_queue_as_reset() clears q->properties.is_active to false without setting
q->properties.is_evicted = true or qpd->evicted = 1. When
kfd_dqm_reconcile_mes_queues() then runs, it retires q->mes_state to
KFD_MES_QUEUE_UNMAPPED and hits this !q->properties.is_active check, leaving
any queue or process that kgd2kfd_pre_reset() did not evict (for example,
after an earlier partial restore_process_queues_cpsch() failure left
qpd->evicted == 1 with active queues) un-evicted and eligible to be re-added
to MES.
> +
> + q->properties.is_active = false;
> + q->properties.is_evicted = true;
> + decrement_queue_count(dqm, qpd, q);
> + /* The process stays evicted from here on */
> + if (!qpd->evicted)
> + qpd->evicted = 1;
> + active++;
> + }
> + }
[Severity: Medium]
When this transitions qpd->evicted from 0 to 1, does it leave inactive
sibling queues on qpd->queues_list with q->properties.is_evicted == false
and leave pdd->last_evict_timestamp unset?
If a process has both a stale active queue and an inactive or suspended
queue (whose mes_state is KFD_MES_QUEUE_UNMAPPED or is_active is false),
only the active queue gets q->properties.is_evicted = true while
qpd->evicted becomes 1. Because QUEUE_IS_ACTIVE(q->properties) checks
!q->properties.is_evicted rather than qpd->evicted, a subsequent
update_queue() or resume_single_queue() on the sibling queue will call
add_queue_mes() while the process is evicted, and a later
restore_process_queues_cpsch() will compute eviction duration from a zero or
stale pdd->last_evict_timestamp.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124143433.49736-1-zappel@simple-co.de?part=8
next prev parent reply other threads:[~2026-11-24 16:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 14:34 [PATCH v1 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU Armas Spann
2026-11-24 14:34 ` [PATCH v1 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
2026-11-24 16:19 ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 2/9] drm/amdkfd: factor out freeing of per-queue MES resources Armas Spann
2026-11-24 16:09 ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 3/9] drm/amdkfd: track whether MES knows each queue Armas Spann
2026-11-24 16:30 ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 4/9] drm/amdkfd: add a quarantine for queues MES has not retired Armas Spann
2026-11-24 16:29 ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 5/9] drm/amdkfd: keep queue storage until MES confirmed retirement Armas Spann
2026-11-24 16:29 ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 6/9] drm/amdkfd: keep eviction and restore consistent when MES fails Armas Spann
2026-11-24 16:30 ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 7/9] drm/amdkfd: apply queue property updates only after unmap Armas Spann
2026-11-24 16:42 ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 8/9] drm/amdkfd: reconcile queue state with MES after a restart Armas Spann
2026-11-24 16:53 ` sashiko-bot [this message]
2026-11-24 14:34 ` [PATCH v1 9/9] drm/amdkfd: force CWSR on with more than one MES GPU Armas Spann
2026-11-25 14:15 ` [PATCH v1 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-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-231614@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 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.