All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Prike Liang" <Prike.Liang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH RESEND 2/4] drm/amdgpu/userq: implement support for query status
Date: Tue, 17 Nov 2026 07:41:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-218372@kernel.org> (raw)
In-Reply-To: <20261117072353.537506-2-Prike.Liang@amd.com>

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/amdgpu/userq: unlocked queue state and unmap/map in
  mes_userq_reset() [1]
--

commit 8f1348ec761b7ada9e6ca46fe71c338002a3662a
Author: Alex Deucher <alexander.deucher@amd.com>

drm/amdgpu/userq: implement support for query status

This commit implements the AMDGPU_USERQ_OP_QUERY_STATUS operation to report
when a usermode queue is hung or its VM generation has changed due to lost
VRAM.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index ed6f3b67e8720..496137fca1f0c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
[ ... ]
> @@ -817,6 +818,33 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
>  	return r;
>  }
>  
> +static int
> +amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args)
> +{
> +	struct amdgpu_fpriv *fpriv = filp->driver_priv;
> +	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
> +	struct amdgpu_device *adev = uq_mgr->adev;
> +	struct amdgpu_usermode_queue *queue;
> +	int queue_id = args->in.queue_id;
> +
> +	mutex_lock(&uq_mgr->userq_mutex);
> +
> +	queue = amdgpu_userq_get(uq_mgr, queue_id);
> +	if (!queue) {
> +		mutex_unlock(&uq_mgr->userq_mutex);
> +		return -EINVAL;
> +	}
> +
> +	args->out_qs.flags = 0;
> +	if (queue->state == AMDGPU_USERQ_STATE_HUNG ||
> +	    queue->generation != amdgpu_vm_generation(adev, &fpriv->vm))
> +		args->out_qs.flags |= AMDGPU_USERQ_QUERY_STATUS_FLAGS_BROKEN;

[Severity: High]
This problem wasn't introduced by this patch, but can a concurrent eviction
in amdgpu_userq_unmap_helper() race with mes_userq_reset_hw() [1] and
overwrite AMDGPU_USERQ_STATE_HUNG?

amdgpu_userq_query_status() and amdgpu_userq_unmap_helper() serialize
queue->state under uq_mgr->userq_mutex, whereas mes_userq_reset_hw() unmaps
the queue and sets queue->state = AMDGPU_USERQ_STATE_HUNG without holding
userq_mutex:

CPU0                                  CPU1
amdgpu_userq_hang_detect_work()       amdgpu_eviction_fence_suspend_worker()
  mes_userq_reset()                     mutex_lock(&uq_mgr->userq_mutex)
    mes_userq_reset_hw()                amdgpu_userq_evict_all()
      mes_userq_unmap(queue)              amdgpu_userq_unmap_helper(queue)
                                            // sees AMDGPU_USERQ_STATE_MAPPED
                                            mes_userq_unmap(queue)
      queue->state =
        AMDGPU_USERQ_STATE_HUNG
                                            queue->state =
                                              AMDGPU_USERQ_STATE_UNMAPPED
                                              <-- clobbers HUNG state
                                        mutex_unlock(&uq_mgr->userq_mutex)

Both paths call mes_userq_unmap() concurrently, issuing duplicate
remove_hw_queue MES packets and double-freeing queue->gang_ctx_array_index.
Overwriting AMDGPU_USERQ_STATE_HUNG with AMDGPU_USERQ_STATE_UNMAPPED also
hides the broken status from amdgpu_userq_query_status() and allows
amdgpu_userq_restore_worker() to remap and re-execute the hung queue.

[1] https://sashiko.dev/#/bug/linux-ea51473b-6c36-421a-880f-c4fff09847a7

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117072353.537506-1-Prike.Liang@amd.com?part=2

  reply	other threads:[~2026-11-17  7:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  7:23 [PATCH RESEND 1/4] drm/amdgpu: add UAPI for user queue query status Prike Liang
2026-11-17  7:23 ` [PATCH RESEND 2/4] drm/amdgpu/userq: implement support for " Prike Liang
2026-11-17  7:41   ` sashiko-bot [this message]
2026-11-17  7:23 ` [PATCH RESEND 3/4] drm/amdgpu/userq: report invalid VA through the broken status flag Prike Liang
2026-11-17  7:42   ` sashiko-bot
2026-11-17  7:23 ` [PATCH RESEND 4/4] drm/amdgpu/userq: report GPU reset in progress Prike Liang

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-218372@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Prike.Liang@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.