From: sashiko-bot@kernel.org
To: "Jesse Zhang" <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v5 09/15] drm/amdgpu/gfx12: add a gfx engine soft reset
Date: Thu, 26 Nov 2026 09:57:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-235201@kernel.org> (raw)
In-Reply-To: <20261126093417.192538-9-Jesse.Zhang@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu/gfx12: race and UAF on user queues in
gfx_v12_0_soft_reset_engine()
--
commit 1eb59ae54b68b8bc41a2294b6011763c46222bdb
Author: Jesse Zhang <Jesse.Zhang@amd.com>
drm/amdgpu/gfx12: add a gfx engine soft reset
This commit implements soft_reset_engine() for the GFX12 graphics engine
to reset CPF/CPG, PFP/ME, and the GFX HQDs while saving and restoring
user queues around the reset.
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
> index 8ca8e3f8392d3..69bdae805597c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
> @@ -3868,6 +3868,137 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
[ ... ]
> +static int gfx_v12_0_soft_reset_engine(struct amdgpu_ip_block *ip_block,
> + enum amdgpu_ring_type ring_type, u32 inst,
> + struct amdgpu_usermode_queue *guilty_queue)
> +{
> + struct amdgpu_device *adev = ip_block->adev;
> + int i, r;
> +
> + if (ring_type != AMDGPU_RING_TYPE_GFX || inst)
> + return -EOPNOTSUPP;
> +
> + mutex_lock(&adev->gfx.mec.reset_mutex);
> + amdgpu_gfx_off_ctrl(adev, false);
> +
> + /* A hung gfx stream can keep MES from suspending: reset anyway. */
> + amdgpu_mes_suspend(adev, 0);
> + amdgpu_userq_save_hqds(adev, AMDGPU_HW_IP_GFX);
> +
> + r = gfx_v12_0_soft_reset_gfx_cp(adev);
> + if (r) {
> + dev_err(adev->dev, "gfx CP still busy after reset, CP_STAT 0x%08x\n",
> + RREG32_SOC15(GC, 0, regCP_STAT));
> + goto fail;
> + }
> +
> + /* The reset cleared the HQD of the kernel gfx queue: map it again. */
> + r = amdgpu_gfx_disable_kgq(adev, 0);
> + if (r)
> + goto fail;
> + for (i = 0; i < adev->gfx.num_gfx_rings; i++)
> + amdgpu_gfx_mqd_reset_restore(&adev->gfx.gfx_ring[i]);
> + r = amdgpu_gfx_enable_kgq(adev, 0);
> + if (!r)
> + r = gfx_v12_0_cp_gfx_start(adev);
> + if (r)
> + goto fail;
> +
> + amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX, guilty_queue);
> + r = amdgpu_mes_resume(adev, 0);
[Severity: High]
Can amdgpu_userq_save_hqds() and amdgpu_userq_restore_hqds() race with
concurrent user queue destruction and trigger a use-after-free on queue?
When .soft_reset_engine is set, amdgpu_device_ip_soft_reset() only takes
down_read(&adev->reset_domain->sem) rather than the exclusive write lock,
and gfx_v12_0_soft_reset_engine() only holds adev->gfx.mec.reset_mutex.
Meanwhile, amdgpu_userq_destroy() and amdgpu_userq_detach_doorbell() also
use down_read(&adev->reset_domain->sem) to serialize against resets and
do not take adev->gfx.mec.reset_mutex. Because xa_for_each() in
amdgpu_userq_save_hqds() and amdgpu_userq_restore_hqds() iterates
adev->userq_doorbell_xa without holding userq_mutex or a queue reference:
CPU0 CPU1
amdgpu_device_ip_soft_reset()
down_read(&reset_domain->sem)
gfx_v12_0_soft_reset_engine()
amdgpu_userq_restore_hqds()
xa_for_each(..., queue)
amdgpu_userq_destroy()
amdgpu_userq_detach_doorbell()
down_read(&reset_domain->sem)
xa_erase_irq(...)
up_read(&reset_domain->sem)
uq_funcs->mqd_destroy(queue)
kfree(queue)
restore_hqd(...,
queue->mqd.cpu_ptr, ...) <-- use-after-free
For the same reason, amdgpu_userq_map_helper() and
amdgpu_userq_unmap_helper() only take down_read(&adev->reset_domain->sem),
so they can run concurrently with gfx_v12_0_soft_reset_engine(), racing
on queue->state and issuing MES map/unmap commands while MES gangs are
suspended.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126093417.192538-1-Jesse.Zhang@amd.com?part=9
next prev parent reply other threads:[~2026-11-26 9:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 9:33 [PATCH v5 01/15] drm/amdgpu: pass the device to the multi ring reset helpers Jesse Zhang
2026-11-26 9:33 ` [PATCH v5 02/15] drm/amdgpu/ring: During multi-queue reset, only call begin helper if needed Jesse Zhang
2026-11-26 9:52 ` sashiko-bot
2026-11-26 9:33 ` [PATCH v5 03/15] drm/amdgpu: add an engine scope to the IP block soft reset Jesse Zhang
2026-11-26 10:00 ` sashiko-bot
2026-11-26 9:33 ` [PATCH v5 04/15] drm/amdgpu/gfx: add callbacks to save and restore a gfx HQD Jesse Zhang
2026-11-26 9:33 ` [PATCH v5 05/15] drm/amdgpu/gfx12: " Jesse Zhang
2026-11-26 9:33 ` [PATCH v5 06/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-26 9:33 ` [PATCH v5 07/15] drm/amdgpu/userq: add a helper to signal the fences of a queue up to a point Jesse Zhang
2026-11-26 9:33 ` [PATCH v5 08/15] drm/amdgpu/userq: add helpers to keep the user queues of one engine across a reset Jesse Zhang
2026-11-26 10:03 ` sashiko-bot
2026-11-26 9:33 ` [PATCH v5 09/15] drm/amdgpu/gfx12: add a gfx engine soft reset Jesse Zhang
2026-11-26 9:57 ` sashiko-bot [this message]
2026-11-26 9:33 ` [PATCH v5 10/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-26 9:59 ` sashiko-bot
2026-11-26 9:33 ` [PATCH v5 11/15] drm/amdgpu/gfx12: include SOFT_RESET_GFX in the " Jesse Zhang
2026-11-26 9:33 ` [PATCH v5 12/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-26 9:57 ` sashiko-bot
2026-11-26 9:33 ` [PATCH v5 13/15] drm/amdgpu/userq: reset the gfx engine when a gfx user queue reset fails Jesse Zhang
2026-11-26 10:15 ` sashiko-bot
2026-11-26 9:33 ` [PATCH v5 14/15] drm/amdgpu/gfx12: enable the gfx engine soft reset Jesse Zhang
2026-11-26 9:33 ` [PATCH v5 15/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-26 10:10 ` sashiko-bot
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-235201@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Jesse.Zhang@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/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