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 7/9] drm/amdgpu/userq: add handling for set_gang
Date: Tue, 17 Nov 2026 19:46:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-219523@kernel.org> (raw)
In-Reply-To: <20261117192415.810117-7-alexander.deucher@amd.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/amdgpu/userq: standalone secondary queue ops skip
  set_gang() and VA checks
- [High] drm/amdgpu/userq: out-of-bounds gang context GPU address in
  mes_set_gang()
- [Medium] drm/amdgpu/userq: missing error return in
  amdgpu_userq_restore_helper()
- [Medium] drm/amdgpu/userq: missing set_gang() call in
  amdgpu_userq_post_reset()
--

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

drm/amdgpu/userq: add handling for set_gang

This commit updates the usermode queue preempt, restore, unmap, and map
helpers to operate on a ganged secondary queue and invoke the set_gang
callback when mapping or restoring a gang.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index ed6f3b67e8720..e41f0e10c8a36 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
[ ... ]
> @@ -348,11 +371,27 @@ static int amdgpu_userq_restore_helper(struct amdgpu_usermode_queue *queue)
>  		}
>  	}
>  
> +	if (secondary_queue &&
> +	    secondary_queue->state == AMDGPU_USERQ_STATE_PREEMPTED) {
> +		trace_amdgpu_userq_state_start(secondary_queue);
> +
> +		r = userq_funcs->restore(secondary_queue);
> +		if (r) {
> +			trace_amdgpu_userq_state_changed(secondary_queue, AMDGPU_USERQ_STATE_HUNG);
> +			secondary_queue->state = AMDGPU_USERQ_STATE_HUNG;
> +		} else {
> +			trace_amdgpu_userq_state_changed(secondary_queue, AMDGPU_USERQ_STATE_MAPPED);
> +			secondary_queue->state = AMDGPU_USERQ_STATE_MAPPED;
> +			r = userq_funcs->set_gang(queue, secondary_queue);
> +		}
> +	}
> +
>  	return r;
>  }

[Severity: Medium]
Should amdgpu_userq_restore_helper() return immediately when restoring the
primary queue fails, as the other helpers do?

Without an early return in the primary queue error branch, a failed
userq_funcs->restore(queue) sets queue->state to AMDGPU_USERQ_STATE_HUNG
and falls through to the secondary_queue block.  Restoring secondary_queue
then overwrites r, calls userq_funcs->set_gang() with a hung primary queue,
and returns 0 to the caller if set_gang() succeeds.

[ ... ]

> @@ -403,7 +466,23 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue)
>  		}
>  	}
>  
> -	return 0;
> +	if (secondary_queue &&
> +	    secondary_queue->state == AMDGPU_USERQ_STATE_UNMAPPED) {
> +		trace_amdgpu_userq_state_start(secondary_queue);
> +
> +		r = userq_funcs->map(secondary_queue);
> +		if (r) {
> +			trace_amdgpu_userq_state_changed(secondary_queue, AMDGPU_USERQ_STATE_HUNG);
> +			secondary_queue->state = AMDGPU_USERQ_STATE_HUNG;
> +			return r;
> +		} else {
> +			trace_amdgpu_userq_state_changed(secondary_queue, AMDGPU_USERQ_STATE_MAPPED);
> +			secondary_queue->state = AMDGPU_USERQ_STATE_MAPPED;
> +			r = userq_funcs->set_gang(queue, secondary_queue);
> +		}
> +	}
> +
> +	return r;
>  }

[Severity: High]
Does calling userq_funcs->set_gang() here pass out-of-bounds gang context
GPU addresses to MES?

mes_userq_create_ctx_space() allocates queue->fw_obj with only one page
(AMDGPU_USERQ_GANG_CTX_SZ), and mes_userq_map() registers ctx->gpu_addr at
offset 0 as gang_context_addr.  However, mes_set_gang() adds
AMDGPU_USERQ_PROC_CTX_SZ (PAGE_SIZE) to both GPU addresses:

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c:mes_set_gang() {
    ...
	input.primary_gang_context_addr =
		primary_ctx->gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
	input.secondary_gang_context_addr =
		secondary_ctx->gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
    ...
}

This points one page past the end of each 1-page fw_obj BO and does not
match the gang_context_addr registered with MES.

[Severity: Medium]
Should amdgpu_userq_post_reset() also call userq_funcs->set_gang() when
remapping ganged queues after a GPU reset?

When VRAM is not lost, amdgpu_userq_post_reset() remaps hung queues
directly via userq_funcs->map(queue) without using
amdgpu_userq_map_helper() or calling userq_funcs->set_gang(), leaving
ganged queues unlinked in MES after recovery.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
> index efaa658a26a9a..3dd63d6b9c445 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
> @@ -102,6 +102,9 @@ struct amdgpu_usermode_queue {
>  	} userq_vas;
>  
>  	uint32_t	gang_ctx_array_index;
> +	bool			in_gang;
> +	bool			gang_primary;
> +	struct amdgpu_usermode_queue *gang_secondary;
>  };

[Severity: High]
What prevents callers iterating uq_mgr->userq_xa or
adev->userq_doorbell_xa from operating on a secondary gang queue directly?

Both queues remain in the XArrays, and neither the helpers nor the
xa_for_each() loops check queue->in_gang && !queue->gang_primary.

If xa_for_each() in amdgpu_userq_restore_all(), amdgpu_userq_resume(), or
amdgpu_userq_start_sched_for_enforce_isolation() visits secondary_queue
before primary_queue, secondary_queue is mapped or restored to
AMDGPU_USERQ_STATE_MAPPED on its own.  When primary_queue is visited next,
secondary_queue->state is no longer UNMAPPED or PREEMPTED, so
userq_funcs->set_gang() is skipped.

Conversely, if primary_queue is visited first in
amdgpu_userq_restore_all(), amdgpu_userq_map_helper(primary_queue) maps
secondary_queue in MES before amdgpu_userq_buffer_vas_mapped() is checked
on secondary_queue:

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:amdgpu_userq_restore_all() {
    ...
	xa_for_each(&uq_mgr->userq_xa, queue_id, queue) {
		if (!amdgpu_userq_buffer_vas_mapped(queue)) {
			drm_file_err(uq_mgr->file,
				     "trying restore queue without va mapping\n");
			trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_INVALID_VA);
			queue->state = AMDGPU_USERQ_STATE_INVALID_VA;
			continue;
		}

		r = amdgpu_userq_map_helper(queue);
    ...
}

If secondary_queue has unmapped VAs, the later loop iteration sets
secondary_queue->state to AMDGPU_USERQ_STATE_INVALID_VA while it remains
mapped in MES, so subsequent unmap and queue destruction skip unmapping it
from hardware before freeing its MQD and context BOs.

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

  reply	other threads:[~2026-11-17 19:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 19:24 [PATCH 1/9] drm/amdgpu/mes11: add API for gang submit Alex Deucher
2026-11-17 19:24 ` [PATCH 2/9] drm/amdgpu/mes: add callback " Alex Deucher
2026-11-17 19:24 ` [PATCH 3/9] drm/amdgpu/mes11: add support for setting " Alex Deucher
2026-11-17 19:37   ` sashiko-bot
2026-11-17 19:24 ` [PATCH 4/9] drm/amdgpu/mes12: " Alex Deucher
2026-11-17 19:24 ` [PATCH 5/9] drm/amdgpu/userq: add callback for gang setup Alex Deucher
2026-11-17 19:24 ` [PATCH 6/9] drm/amdgpu/userq/mes: implement set gang submit Alex Deucher
2026-11-17 19:35   ` sashiko-bot
2026-11-17 19:24 ` [PATCH 7/9] drm/amdgpu/userq: add handling for set_gang Alex Deucher
2026-11-17 19:46   ` sashiko-bot [this message]
2026-11-17 19:24 ` [PATCH 8/9] drm/amdgpu: add UAPI to create user queue gangs Alex Deucher
2026-11-17 19:24 ` [PATCH 9/9] drm/amdgpu/userq: enable support for creating gangs Alex Deucher
2026-11-17 19:44   ` 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-219523@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.