From: Junrui Luo <moonafterrain@outlook.com>
To: "Liang, Prike" <Prike.Liang@amd.com>,
"Markus.Elfring@web.de" <Markus.Elfring@web.de>
Cc: "Deucher, Alexander" <Alexander.Deucher@amd.com>,
"Koenig, Christian" <Christian.Koenig@amd.com>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Yuhao Jiang <danisjiang@gmail.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH] drm/amdgpu/userq: fix memory leak in MQD creation error paths
Date: Mon, 16 Mar 2026 10:10:29 +0000 [thread overview]
Message-ID: <F21AC290-0B53-40AF-A0A0-0647B86AD2C3@outlook.com> (raw)
In-Reply-To: <PH7PR12MB6000A8C0694949AA83702AE2FB40A@PH7PR12MB6000.namprd12.prod.outlook.com>
On Sun, Mar 15, 2026 at 10:50:44AM +0100, Markus Elfring wrote:
> If you would like to stick to the usage of goto labels so far,
> I see further possibilities to avoid also duplicate source code for
> the affected implementation of the function “mes_userq_mqd_create”.
> https://elixir.bootlin.com/linux/v7.0-rc3/source/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c#L275-L434
On Mon, Mar 16, 2026 at 03:32:34AM +0000, Liang, Prike wrote:
> Thanks for the fix. We could further refine this by wrapping a unified helper for fetching and validating the userq MQD raw data.
Thanks for the review and suggestions.
I'm thinking of a follow-up patch that splits the branches into separate
helper functions. Each function would use __free(kfree) to manage the
memdup lifetime internally. The main function would only dispatch and
forward errors to the existing goto chain.
For instance:
static void *mes_userq_mqd_read(struct drm_amdgpu_userq_in *mqd_user,
size_t size, const char *ip_name)
{
void *mqd;
if (mqd_user->mqd_size != size || !mqd_user->mqd) {
DRM_ERROR("Invalid %s MQD\n", ip_name);
return ERR_PTR(-EINVAL);
}
mqd = memdup_user(u64_to_user_ptr(mqd_user->mqd), size);
if (IS_ERR(mqd)) {
DRM_ERROR("Failed to read %s user MQD\n", ip_name);
return ERR_PTR(-ENOMEM);
}
return mqd;
}
static int mes_userq_mqd_init_compute(struct amdgpu_device *adev,
struct amdgpu_usermode_queue *queue,
struct drm_amdgpu_userq_in *mqd_user,
struct amdgpu_mqd_prop *userq_props)
{
struct drm_amdgpu_userq_mqd_compute_gfx11 *mqd __free(kfree) = NULL;
int r;
mqd = mes_userq_mqd_read(mqd_user, sizeof(*mqd), "compute");
if (IS_ERR(mqd))
return PTR_ERR(mqd);
r = amdgpu_userq_input_va_validate(adev, queue, mqd->eop_va, 2048);
if (r)
return r;
userq_props->eop_gpu_addr = mqd->eop_va;
userq_props->hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_NORMAL;
userq_props->hqd_queue_priority = AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM;
userq_props->hqd_active = false;
userq_props->tmz_queue =
mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
return 0;
}
/* similarly for mes_userq_mqd_init_gfx/sdma */
Then in mes_userq_mqd_create():
if (queue->queue_type == AMDGPU_HW_IP_COMPUTE)
r = mes_userq_mqd_init_compute(adev, queue, mqd_user,
userq_props);
else if (queue->queue_type == AMDGPU_HW_IP_GFX)
r = mes_userq_mqd_init_gfx(adev, queue, mqd_user, userq_props);
else if (queue->queue_type == AMDGPU_HW_IP_DMA)
r = mes_userq_mqd_init_sdma(adev, queue, mqd_user, userq_props);
if (r)
goto free_mqd;
Would this direction be acceptable as a follow-up?
Thanks,
Junrui Luo
next prev parent reply other threads:[~2026-03-16 10:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 15:33 Junrui Luo
2026-03-14 20:04 ` Markus Elfring
2026-03-15 5:25 ` Junrui Luo
2026-03-15 9:50 ` Markus Elfring
2026-03-16 3:32 ` [PATCH] " Liang, Prike
2026-03-16 10:10 ` Junrui Luo [this message]
2026-03-16 11:00 ` Markus Elfring
2026-03-16 12:21 ` Liang, Prike
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=F21AC290-0B53-40AF-A0A0-0647B86AD2C3@outlook.com \
--to=moonafterrain@outlook.com \
--cc=Alexander.Deucher@amd.com \
--cc=Christian.Koenig@amd.com \
--cc=Markus.Elfring@web.de \
--cc=Prike.Liang@amd.com \
--cc=airlied@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=danisjiang@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®