All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Armas Spann" <zappel@simple-co.de>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v1 2/9] drm/amdkfd: factor out freeing of per-queue MES resources
Date: Tue, 24 Nov 2026 16:09:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-231532@kernel.org> (raw)
In-Reply-To: <20261124143433.49736-3-zappel@simple-co.de>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] drm/amdkfd: memory leak in pqm_create_queue() [1]
--

commit 287e7ae4498cc9b3a4da82d8515d5e0f04fa7f42
Author: Armas Spann <zappel@simple-co.de>

drm/amdkfd: factor out freeing of per-queue MES resources

This commit factors out the cleanup of per-queue MES resources
(gang_ctx_array_index, gang_ctx_bo, and wptr_bo_gart) from
pqm_clean_queue_resource() into a new kfd_queue_free_mes_resources()
helper.

> 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 b68e884b1c37a..89e95b70e2763 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> @@ -186,6 +186,21 @@ int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p)
>  	return 0;
>  }
>  
> +/*
> + * Free the storage that only exists so MES can run the queue: the gang
> + * context and the GART mapping of the write pointer. MES addresses both
> + * directly, so the queue must be out of MES before this is called.
> + */
> +void kfd_queue_free_mes_resources(struct kfd_node *dev, struct queue *q)
> +{
> +	if (!dev->kfd->shared_resources.enable_mes)
> +		return;
> +
> +	amdgpu_mes_free_gang_ctx_index(&dev->adev->mes, q->gang_ctx_array_index);
> +	amdgpu_amdkfd_free_kernel_mem(dev->adev, &q->gang_ctx_bo);
> +	amdgpu_amdkfd_free_kernel_mem(dev->adev, (void **)&q->wptr_bo_gart);
> +}
> +
>  static void pqm_clean_queue_resource(struct process_queue_manager *pqm,
>  				     struct process_queue_node *pqn)
>  {
> @@ -210,11 +225,7 @@ static void pqm_clean_queue_resource(struct process_queue_manager *pqm,
>  		pdd->qpd.num_gws = 0;
>  	}
>  
> -	if (dev->kfd->shared_resources.enable_mes) {
> -		amdgpu_mes_free_gang_ctx_index(&dev->adev->mes, pqn->q->gang_ctx_array_index);
> -		amdgpu_amdkfd_free_kernel_mem(dev->adev, &pqn->q->gang_ctx_bo);
> -		amdgpu_amdkfd_free_kernel_mem(dev->adev, (void **)&pqn->q->wptr_bo_gart);
> -	}
> +	kfd_queue_free_mes_resources(dev, pqn->q);
>  }
>  
>  void pqm_uninit(struct process_queue_manager *pqm)

[Severity: High]
This problem wasn't introduced by this patch, but should pqm_create_queue()
also call kfd_queue_free_mes_resources() on the err_create_queue error path
when q is non-NULL [1]?

init_user_queue() allocates gang_ctx_bo, gang_ctx_array_index, and
wptr_bo_gart before pqm_create_queue() calls dev->dqm->ops.create_queue():

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c:pqm_create_queue() {
    ...
		retval = init_user_queue(pqm, dev, &q, properties, *qid);
		if (retval != 0)
			goto err_create_queue;
		pqn->q = q;
		pqn->kq = NULL;
		retval = dev->dqm->ops.create_queue(dev->dqm, q, &pdd->qpd, q_data,
						    restore_mqd, restore_ctl_stack);
    ...
	if (retval != 0) {
    ...
		goto err_create_queue;
	}
    ...
err_create_queue:
	uninit_queue(q);
	if (kq)
		kernel_queue_uninit(kq);
	kfree(pqn);
    ...
}

If dev->dqm->ops.create_queue() fails, err_create_queue only calls
uninit_queue(q), leaking those MES resources and allowing a local user to
exhaust kernel memory and MES gang context slots.

[1] https://sashiko.dev/#/bug/linux-0b93a0b0-d6d5-41d7-ac1d-c1955556cf28

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124143433.49736-1-zappel@simple-co.de?part=2

  reply	other threads:[~2026-11-24 16:09 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 [this message]
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
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-231532@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.