All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jesse Zhang" <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v5 03/15] drm/amdgpu: add an engine scope to the IP block soft reset
Date: Thu, 26 Nov 2026 10:00:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-235216@kernel.org> (raw)
In-Reply-To: <20261126093417.192538-3-Jesse.Zhang@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: race with user queues in
  amdgpu_device_ip_soft_reset()
--

commit 2c34e267b776523348afd4f14e7ef41c33d20c0a
Author: Jesse Zhang <Jesse.Zhang@amd.com>

drm/amdgpu: add an engine scope to the IP block soft reset

This commit adds an optional soft_reset_engine() callback to amd_ip_funcs
and updates amdgpu_device_ip_soft_reset() to reset only the hung engine
and recover its user queues while holding reset_domain->sem for read.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c
> index d0b0d3eaffc56..79bc275e3e0fa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c
[ ... ]
> @@ -430,55 +434,71 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type)
[ ... ]
> -	amdgpu_device_lock_reset_domain(adev->reset_domain);
> +	/* An engine reset leaves the others running: let KFD add/remove queues. */
> +	if (engine) {
> +		ring_type_mask = BIT(ring_type);
> +		down_read(&adev->reset_domain->sem);
> +	} else {
> +		ring_type_mask = amdgpu_ring_mask_from_ip(ip_type);
> +		amdgpu_device_lock_reset_domain(adev->reset_domain);
> +	}
>  	amdgpu_multi_ring_reset_helper_begin(adev, ring_type_mask, guilty_ring, guilty_fence);
>  
> -	r = ip_block->version->funcs->soft_reset(ip_block);
> +	r = engine ? funcs->soft_reset_engine(ip_block, ring_type, inst, guilty_queue) :
> +		     funcs->soft_reset(ip_block);

[Severity: High]
Can holding adev->reset_domain->sem only for read during an engine reset
race with concurrent user queue operations and cause a use-after-free on
struct amdgpu_usermode_queue?

The user queue helpers in drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
(amdgpu_userq_unmap_helper(), amdgpu_userq_map_helper(), and
amdgpu_userq_detach_doorbell()) also take adev->reset_domain->sem for read
to serialize against GPU resets:

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:amdgpu_userq_detach_doorbell() {
    ...
	down_read(&adev->reset_domain->sem);
	xa_erase_irq(&adev->userq_doorbell_xa, queue->doorbell_index);
	up_read(&adev->reset_domain->sem);
}

Because two readers do not exclude each other, user queue teardown,
eviction, or restore can run concurrently while soft_reset_engine() is
suspending MES and iterating adev->userq_doorbell_xa (via
amdgpu_userq_save_hqds() and amdgpu_userq_restore_hqds() in commit
"drm/amdgpu/userq: add helpers to keep the user queues of one engine
across a reset") without holding uq_mgr->userq_mutex:

CPU0                                    CPU1
amdgpu_device_ip_soft_reset()
  down_read(&adev->reset_domain->sem)
  funcs->soft_reset_engine()
    amdgpu_userq_save_hqds()
      xa_for_each(&adev->userq_doorbell_xa, ..., queue)
                                        amdgpu_userq_destroy()
                                          amdgpu_userq_detach_doorbell()
                                            down_read(&adev->reset_domain->sem)
                                            xa_erase_irq(&adev->userq_doorbell_xa, ...)
                                            up_read(&adev->reset_domain->sem)
                                          kfree(queue)
        queue->state = ...;  <-- use-after-free

Concurrent eviction or restore paths can likewise call into MES while it
is suspended and race on queue->state.  Note that soft_reset_engine()
cannot simply acquire uq_mgr->userq_mutex either, because
amdgpu_lockdep_init() defines userq_mutex as outer to reset_domain->sem.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126093417.192538-1-Jesse.Zhang@amd.com?part=3

  reply	other threads:[~2026-11-26 10:00 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 [this message]
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
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-235216@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 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.