All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alex Deucher" <alexander.deucher@amd.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 08/11] drm/amdgpu/userq: add handling for set_gang
Date: Wed, 02 Dec 2026 16:10:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-246197@kernel.org> (raw)
In-Reply-To: <20261202155137.1102730-8-alexander.deucher@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdgpu/userq: missing reset_domain->sem in
  amdgpu_userq_set_gang_helper()
- [Medium] drm/amdgpu/userq: amdgpu_userq_post_reset() gangs unmapped
  queues after reset
--

commit 7c423c2420e3f6275959be31d1678b0bcfe86314
Author: Alex Deucher <alexander.deucher@amd.com>

drm/amdgpu/userq: add handling for set_gang

This commit adds gang leader/follower pointers to struct
amdgpu_usermode_queue and introduces amdgpu_userq_set_gang_helper() to
configure ganged queues during restore, resume, and post-reset paths.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index ed6f3b67e8720..0785759967144 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -303,6 +303,27 @@ static bool amdgpu_userq_buffer_vas_mapped(struct amdgpu_usermode_queue *queue)
>  	return true;
>  }
>  
> +static int amdgpu_userq_set_gang_helper(struct amdgpu_usermode_queue *queue)
> +{
> +	struct amdgpu_usermode_queue *follower_queue = queue->gang_follower;
> +	struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
> +	struct amdgpu_device *adev = uq_mgr->adev;
> +	const struct amdgpu_userq_funcs *userq_funcs =
> +		adev->userq_funcs[queue->queue_type];
> +	int r;
> +
> +	if (follower_queue &&
> +	    (queue->state == AMDGPU_USERQ_STATE_MAPPED ||
> +	     queue->state == AMDGPU_USERQ_STATE_PREEMPTED) &&
> +	    (follower_queue->state == AMDGPU_USERQ_STATE_MAPPED ||
> +	     follower_queue->state == AMDGPU_USERQ_STATE_PREEMPTED)) {
> +		r = userq_funcs->set_gang(queue, follower_queue);
> +		if (r)
> +			return r;
> +	}
> +	return 0;
> +}
> +
>  static int amdgpu_userq_preempt_helper(struct amdgpu_usermode_queue *queue)
>  {
>  	struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
> @@ -968,6 +989,11 @@ amdgpu_userq_restore_all(struct amdgpu_userq_mgr *uq_mgr)
>  		if (r)
>  			ret = r;
>  	}
> +	xa_for_each(&uq_mgr->userq_xa, queue_id, queue) {
> +		r = amdgpu_userq_set_gang_helper(queue);
> +		if (r)
> +			ret = r;
> +	}
>  	mutex_unlock(&uq_mgr->userq_mutex);

[Severity: High]
Can amdgpu_userq_restore_all() and amdgpu_userq_resume() call
amdgpu_userq_set_gang_helper() without holding adev->reset_domain->sem?

Unlike amdgpu_userq_map_helper(), which takes a read lock on
adev->reset_domain->sem per commit e6a8b8588f43 ("drm/amdgpu/userq: wait
for GPU reset before mapping or unmapping queues"), the second loop runs
after that lock has been released:

kworker (restore_work)            kworker (reset_work)
amdgpu_userq_restore_all()
  amdgpu_userq_map_helper()
    down_read(&reset_domain->sem)
    ...
    up_read(&reset_domain->sem)
                                  down_write(&reset_domain->sem)
                                  amdgpu_userq_pre_reset()
                                    queue->state = ..._HUNG
                                  ... (ASIC / MES reset)
  amdgpu_userq_set_gang_helper()
    reads queue->state
    userq_funcs->set_gang()       <-- submits to MES during reset

Besides racing on queue->state and submitting SET_GANG_SUBMIT packets while
MES is being reset, writing the MES doorbell triggers the
lockdep_assert_held(&adev->reset_domain->sem) warning in
amdgpu_device_skip_hw_access().

Because amdgpu_userq_post_reset() already holds adev->reset_domain->sem for
write, taking the read lock inside amdgpu_userq_restore_all() and
amdgpu_userq_resume() (or having amdgpu_userq_post_reset() call
userq_funcs->set_gang() directly like it does for userq_funcs->map()) would
avoid a recursive lock on the reset path.

[ ... ]

> @@ -1591,6 +1624,13 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)
>  			queue->state = AMDGPU_USERQ_STATE_MAPPED;
>  		}
>  	}
> +	xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
> +		r = amdgpu_userq_set_gang_helper(queue);
> +		if (r) {
> +			dev_err(adev->dev, "Failed to gang queue %ld\n", queue_id);
> +			ret = r;
> +		}
> +	}
>  
>  	return ret;
>  }

[Severity: Medium]
Does amdgpu_userq_post_reset() attempt to gang queues in MES that were not
remapped after the reset?

In amdgpu_userq_pre_reset(), only queues in AMDGPU_USERQ_STATE_MAPPED are
moved to AMDGPU_USERQ_STATE_HUNG; queues in AMDGPU_USERQ_STATE_PREEMPTED
keep their state even though the ASIC reset wipes MES hardware state.  In
amdgpu_userq_post_reset(), the first loop only remaps queues when
queue->state == AMDGPU_USERQ_STATE_HUNG && !vram_lost.

Because the second loop is not gated on !vram_lost and
amdgpu_userq_set_gang_helper() accepts AMDGPU_USERQ_STATE_PREEMPTED,
userq_funcs->set_gang() will be called for gang contexts that were never
re-added to MES after reset (either because vram_lost is true or because
one or both queues were preempted before the reset), causing the MES
command and amdgpu_userq_post_reset() to fail.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202155137.1102730-1-alexander.deucher@amd.com?part=8

  reply	other threads:[~2026-12-02 16:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
2026-12-02 15:51 ` [PATCH 02/11] drm/amdgpu/mes11: add API for gang submit Alex Deucher
2026-12-02 15:51 ` [PATCH 03/11] drm/amdgpu/mes: add callback " Alex Deucher
2026-12-02 15:51 ` [PATCH 04/11] drm/amdgpu/mes11: add support for setting " Alex Deucher
2026-12-02 15:51 ` [PATCH 05/11] drm/amdgpu/mes12: " Alex Deucher
2026-12-02 15:51 ` [PATCH 06/11] drm/amdgpu/userq: add callback for gang setup Alex Deucher
2026-12-02 15:51 ` [PATCH 07/11] drm/amdgpu/userq/mes: implement set gang submit Alex Deucher
2026-12-02 15:51 ` [PATCH 08/11] drm/amdgpu/userq: add handling for set_gang Alex Deucher
2026-12-02 16:10   ` sashiko-bot [this message]
2026-12-02 15:51 ` [PATCH 09/11] drm/amdgpu: add UAPI to create user queue gangs Alex Deucher
2026-12-02 16:16   ` Mohan Marimuthu, Yogesh
2026-12-02 15:51 ` [PATCH 10/11] drm/amdgpu/userq: enable support for creating gangs Alex Deucher
2026-12-02 16:09   ` sashiko-bot
2026-12-02 15:51 ` [PATCH 11/11] drm/amdgpu: bump driver version for userq updates Alex Deucher
  -- strict thread matches above, loose matches on Subject: below --
2026-11-18 22:37 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
2026-11-18 22:37 ` [PATCH 08/11] drm/amdgpu/userq: add handling for set_gang Alex Deucher
2026-11-18 22:54   ` 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-246197@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexander.deucher@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.