From: "Lin, Amber" <amber.lin@amd.com>
To: Mukul Joshi <mukul.joshi@amd.com>, amd-gfx@lists.freedesktop.org
Cc: Felix.Kuehling@amd.com, Harish.Kasiviswanathan@amd.com
Subject: Re: [PATCHv2 2/2] drm/amdkfd: remove all queues of a process with a single MES call
Date: Fri, 4 Dec 2026 17:12:37 +0800 [thread overview]
Message-ID: <6bf24fcf-8235-4cef-87f2-d0d3545bc4b2@amd.com> (raw)
In-Reply-To: <20261204033433.939162-2-mukul.joshi@amd.com>
Series is
Reviewed-by: Amber Lin <amber.lin@amd.com>
On 12/4/2026 11:33 AM, Mukul Joshi wrote:
> On process eviction, termination and scheduler halt/stop, KFD sends one
> MES REMOVE_QUEUE per active queue. If MES supports it, remove all queues
> of a process, by PASID, with a single request instead.
>
> remove_queue_mes() sends this request when called with a NULL queue. On
> failure, the same request is passed to the MES queue reset path, which
> sends it again if no hung queue is found. If hung queues were reset
> instead, the other queues of the process are resumed, so send the
> request once more.
>
> Signed-off-by: Mukul Joshi <mukul.joshi@amd.com>
> ---
> .../drm/amd/amdkfd/kfd_device_queue_manager.c | 139 ++++++++++++++----
> 1 file changed, 113 insertions(+), 26 deletions(-)
>
> 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 58c7da599752..35d7aef68f62 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> @@ -79,7 +79,10 @@ static struct queue *find_queue_by_doorbell_offset(struct device_queue_manager *
> u32 doorbell_offset);
> static void set_queue_as_reset(struct device_queue_manager *dqm, struct queue *q,
> struct qcm_process_device *qpd, bool verbose);
> -static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q);
> +static int reset_queues_mes(struct device_queue_manager *dqm,
> + struct kfd_process_device *pdd,
> + struct mes_remove_queue_input *queue_input,
> + unsigned int *hung_queue_count);
>
> static inline
> enum KFD_MQD_TYPE get_mqd_type_from_queue_type(enum kfd_queue_type type)
> @@ -299,17 +302,35 @@ static int add_queue_mes(struct device_queue_manager *dqm, struct queue *q,
> return r;
> }
>
> +/* A queue that is active and not reset is still in MES */
> +static bool qpd_has_mes_queue(struct qcm_process_device *qpd)
> +{
> + struct queue *q;
> +
> + list_for_each_entry(q, &qpd->queues_list, list)
> + if (q->properties.is_active && !q->properties.is_reset)
> + return true;
> +
> + return false;
> +}
> +
> +/*
> + * Remove queue q from MES. If q is NULL, remove all queues of the process
> + * with a single request, see amdgpu_mes_remove_all_process_queues_supported().
> + * This must be done while the queues are still marked active.
> + */
> static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, struct queue *q,
> struct qcm_process_device *qpd,
> bool is_for_reset,
> bool flush_mes_queue)
> {
> struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
> + unsigned int num_hung = 0;
> int r;
> struct mes_remove_queue_input queue_input;
>
> - /* queue was already removed during reset */
> - if (q->properties.is_reset)
> + /* queue(s) already removed during reset */
> + if (q ? q->properties.is_reset : !qpd_has_mes_queue(qpd))
> return 0;
>
> if (!dqm->sched_running || dqm->sched_halt)
> @@ -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;
>
> amdgpu_mes_lock(&adev->mes);
> r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
> @@ -335,10 +361,26 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, st
> return r;
>
> /* remove_hw_queue failure indicates a queue hang. reset the queue */
> - r = reset_queues_mes(dqm, q);
> + queue_input.remove_queue_after_reset = false;
> + r = reset_queues_mes(dqm, qpd_to_pdd(qpd), &queue_input, &num_hung);
> +
> + /* hung queues were reset and removed; remove the rest of the process */
> + if (!r && !q && num_hung && qpd_has_mes_queue(qpd)) {
> + if (!down_read_trylock(&adev->reset_domain->sem))
> + return -EIO;
> + amdgpu_mes_lock(&adev->mes);
> + r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
> + amdgpu_mes_unlock(&adev->mes);
> + up_read(&adev->reset_domain->sem);
> + }
> +
> if (r && amdgpu_gpu_recovery) {
> - dev_err(adev->dev, "failed to remove queue from MES, doorbell=0x%x\n",
> - q->properties.doorbell_off);
> + if (q)
> + dev_err(adev->dev, "failed to remove queue from MES, doorbell=0x%x\n",
> + q->properties.doorbell_off);
> + else
> + dev_err(adev->dev, "failed to remove queues of pasid 0x%x from MES\n",
> + queue_input.pasid);
> dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n");
> kfd_hws_hang(dqm);
> }
> @@ -363,6 +405,8 @@ static int remove_queue_mes(struct device_queue_manager *dqm, struct queue *q,
>
> static int remove_all_kfd_queues_mes(struct device_queue_manager *dqm)
> {
> + struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
> + bool remove_all = amdgpu_mes_remove_all_process_queues_supported(adev);
> struct device_process_node *cur;
> struct device *dev = dqm->dev->adev->dev;
> struct qcm_process_device *qpd;
> @@ -371,6 +415,16 @@ static int remove_all_kfd_queues_mes(struct device_queue_manager *dqm)
>
> list_for_each_entry(cur, &dqm->queues, list) {
> qpd = cur->qpd;
> + if (remove_all) {
> + retval = remove_queue_mes(dqm, NULL, qpd);
> + if (retval) {
> + dev_err(dev, "%s: Failed to remove queues of pasid 0x%x for dev %d",
> + __func__, qpd_to_pdd(qpd)->pasid, dqm->dev->id);
> + return retval;
> + }
> + continue;
> + }
> +
> list_for_each_entry(q, &qpd->queues_list, list) {
> if (q->properties.is_active) {
> retval = remove_queue_mes(dqm, q, qpd);
> @@ -452,15 +506,21 @@ int kfd_reset_queue_mes(struct device_queue_manager *dqm, int queue_type,
> return reset_queue_mes(dqm, q, queue_type, pipe, queue, db);
> }
>
> -static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)
> +/*
> + * queue_input is the remove request for the bad queue(s). If MES doesn't
> + * detect a hung queue, it is sent again before the queues are resumed.
> + * hung_queue_count (optional) returns the number of hung queues.
> + */
> +static int reset_queues_mes(struct device_queue_manager *dqm,
> + struct kfd_process_device *pdd,
> + struct mes_remove_queue_input *queue_input,
> + unsigned int *hung_queue_count)
> {
> struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
> struct drm_wedge_task_info *info = NULL;
> struct amdgpu_task_info *ti = NULL;
> - struct kfd_process_device *pdd;
> unsigned int num_hung = 0;
> int r = 0;
> - struct mes_remove_queue_input queue_input;
>
> if (!amdgpu_mes_queue_reset_by_mes_supported(adev)) {
> r = -ENOTRECOVERABLE;
> @@ -471,18 +531,13 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)
> if (WARN_ON(dqm->detect_hang_count > 0))
> return 0;
>
> - 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.gang_context_array_index = q->gang_ctx_array_index;
> - queue_input.queue_type = convert_to_amdgpu_ring_type(q->properties.type);
> - queue_input.remove_queue_after_reset = false;
> - queue_input.xcc_id = ffs(dqm->dev->xcc_mask) - 1;
> /* pass the known bad queue info to the reset function */
> - r = amdgpu_gfx_reset_mes_compute(adev, dqm->dev->xcp, NULL, NULL, NULL, &num_hung, &queue_input);
> + r = amdgpu_gfx_reset_mes_compute(adev, dqm->dev->xcp, NULL, NULL, NULL, &num_hung,
> + queue_input);
> if (r)
> goto fail;
> - pdd = kfd_get_process_device_data(q->device, q->process);
> + if (hung_queue_count)
> + *hung_queue_count = num_hung;
> if (pdd) {
> ti = amdgpu_vm_get_task_info_pasid(adev, pdd->pasid);
> if (ti) {
> @@ -1493,6 +1548,7 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm,
> struct queue *q;
> struct device *dev = dqm->dev->adev->dev;
> struct kfd_process_device *pdd;
> + bool remove_all;
> int retval = 0;
>
> dqm_lock(dqm);
> @@ -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) {
> retval = remove_queue_mes(dqm, q, qpd);
> if (retval) {
> dev_err(dev, "Failed to evict queue %d\n",
> @@ -3286,6 +3353,7 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,
> enum kfd_unmap_queues_filter filter =
> KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES;
> bool found = false;
> + bool remove_all;
>
> dqm_lock(dqm);
>
> @@ -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) {
> retval = remove_queue_mes(dqm, q, qpd);
> if (retval)
> dev_err(dev, "Failed to remove queue %d\n",
> @@ -3610,7 +3687,17 @@ int kfd_dqm_suspend_bad_queue_mes(struct kfd_node *knode, u32 pasid, u32 doorbel
>
> list_for_each_entry(q, &qpd->queues_list, list) {
> if (q->doorbell_id == doorbell_id && q->properties.is_active) {
> - if (reset_queues_mes(dqm, q))
> + struct mes_remove_queue_input queue_input;
> +
> + 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.gang_context_array_index = q->gang_ctx_array_index;
> + queue_input.queue_type =
> + convert_to_amdgpu_ring_type(q->properties.type);
> + queue_input.xcc_id = ffs(dqm->dev->xcc_mask) - 1;
> +
> + if (reset_queues_mes(dqm, pdd, &queue_input, NULL))
> dev_dbg(knode->adev->dev,
> "Fail to remove bad queue. doorbell_id 0x%x\n", q->doorbell_id);
> q->properties.is_evicted = true;
prev parent reply other threads:[~2026-12-04 9:13 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
2026-12-04 9:12 ` Lin, Amber [this message]
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=6bf24fcf-8235-4cef-87f2-d0d3545bc4b2@amd.com \
--to=amber.lin@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=Harish.Kasiviswanathan@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=mukul.joshi@amd.com \
/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.