All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 10/11] drm/amdgpu/userq: enable support for creating gangs
  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 ` Alex Deucher
  2026-11-18 22:58   ` sashiko-bot
  0 siblings, 1 reply; 16+ messages in thread
From: Alex Deucher @ 2026-11-18 22:37 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Gangs are sets of userqs that schedule together.  You
specify the primary and secondary queues and the scheduler
will make sure they always run at the same time.

v2: handle setting up the gang again after unmaps
v3: split the UAPI part from the internal tracking
v4: rework

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 122 +++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 3afd17af28548..388385380d8bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -566,6 +566,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
 {
 	struct amdgpu_device *adev = uq_mgr->adev;
 	const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
+	struct amdgpu_usermode_queue *other_gang_queue;
 	int r = 0;
 
 	trace_amdgpu_userq_destroy_start(queue);
@@ -585,6 +586,17 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
 	debugfs_remove_recursive(queue->debugfs_queue);
 #endif
 	r = amdgpu_userq_unmap_helper(queue);
+	/* clean up gangs */
+	if (queue->gang_primary) {
+		other_gang_queue = queue->gang_primary;
+		other_gang_queue->gang_secondary = NULL;
+		queue->gang_primary = NULL;
+	}
+	if (queue->gang_secondary) {
+		other_gang_queue = queue->gang_secondary;
+		other_gang_queue->gang_primary = NULL;
+		queue->gang_secondary = NULL;
+	}
 	atomic_dec(&uq_mgr->userq_count[queue->queue_type]);
 	amdgpu_userq_fence_driver_free(queue);
 	queue->fence_drv = NULL;
@@ -838,6 +850,106 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	return r;
 }
 
+static int
+amdgpu_userq_create_gang(struct drm_file *filp, union drm_amdgpu_userq *args)
+{
+	struct amdgpu_usermode_queue *primary_queue, *secondary_queue;
+	struct amdgpu_fpriv *fpriv = filp->driver_priv;
+	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+	const struct amdgpu_userq_funcs *userq_funcs;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	int primary_queue_id = args->in_cg.primary_queue_id;
+	int secondary_queue_id = args->in_cg.secondary_queue_id;
+	int r;
+
+	/* The reset changes the queue state and the MES is unusable meanwhile */
+	guard(rwsem_read)(&adev->reset_domain->sem);
+
+	mutex_lock(&uq_mgr->userq_mutex);
+	primary_queue = amdgpu_userq_get(uq_mgr, primary_queue_id);
+	secondary_queue = amdgpu_userq_get(uq_mgr, secondary_queue_id);
+
+	if (!primary_queue) {
+		drm_file_err(uq_mgr->file, "Invalid gang primary queue id\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (!secondary_queue) {
+		drm_file_err(uq_mgr->file, "Invalid gang secondary queue id\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (primary_queue == secondary_queue) {
+		drm_file_err(uq_mgr->file, "Trying to gang the same queue\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if ((primary_queue->queue_type != AMDGPU_HW_IP_GFX) &&
+	    (primary_queue->queue_type != AMDGPU_HW_IP_COMPUTE) &&
+	    (primary_queue->queue_type != AMDGPU_HW_IP_DMA)) {
+		drm_file_err(uq_mgr->file, "Invalid gang primary queue type\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (primary_queue->gang_primary || primary_queue->gang_secondary) {
+		drm_file_err(uq_mgr->file, "Primary queue already in a gang\n");
+		r = -EINVAL;
+		goto out;
+	}
+	if (primary_queue->state == AMDGPU_USERQ_STATE_HUNG) {
+		drm_file_err(uq_mgr->file, "Primary queue is hung\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if ((secondary_queue->queue_type != AMDGPU_HW_IP_GFX) &&
+	    (secondary_queue->queue_type != AMDGPU_HW_IP_COMPUTE) &&
+	    (secondary_queue->queue_type != AMDGPU_HW_IP_DMA)) {
+		drm_file_err(uq_mgr->file, "Invalid gang secondary queue type\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (secondary_queue->gang_primary || secondary_queue->gang_secondary) {
+		drm_file_err(uq_mgr->file, "Secondary queue already in a gang\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (secondary_queue->state == AMDGPU_USERQ_STATE_HUNG) {
+		drm_file_err(uq_mgr->file, "Secondary queue is hung\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	userq_funcs = adev->userq_funcs[primary_queue->queue_type];
+	if ((primary_queue->state == AMDGPU_USERQ_STATE_MAPPED ||
+	     primary_queue->state == AMDGPU_USERQ_STATE_PREEMPTED) &&
+	    (secondary_queue->state == AMDGPU_USERQ_STATE_MAPPED ||
+	     secondary_queue->state == AMDGPU_USERQ_STATE_PREEMPTED))
+		r = userq_funcs->set_gang(primary_queue, secondary_queue);
+	else
+		/* if the queues are currently unmapped, the gang state will get
+		 * updated when they get mapped.
+		 */
+		r = 0;
+	if (!r) {
+		primary_queue->gang_secondary = secondary_queue;
+		secondary_queue->gang_primary = primary_queue;
+	}
+
+out:
+	mutex_unlock(&uq_mgr->userq_mutex);
+	amdgpu_userq_put(primary_queue);
+	amdgpu_userq_put(secondary_queue);
+
+	return r;
+}
+
 static int amdgpu_userq_input_args_validate(struct drm_device *dev,
 					union drm_amdgpu_userq *args,
 					struct drm_file *filp)
@@ -907,6 +1019,10 @@ static int amdgpu_userq_input_args_validate(struct drm_device *dev,
 		    args->in.mqd_size)
 			return -EINVAL;
 		break;
+	case AMDGPU_USERQ_OP_CREATE_GANG:
+		if (args->in_cg.pad)
+			return -EINVAL;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -958,7 +1074,11 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 		amdgpu_userq_put(queue);
 		break;
 	}
-
+	case AMDGPU_USERQ_OP_CREATE_GANG:
+		r = amdgpu_userq_create_gang(filp, args);
+		if (r)
+			drm_file_err(filp, "Failed to create usermode queue gang\n");
+		break;
 	default:
 		drm_dbg_driver(dev, "Invalid user queue op specified: %d\n", args->in.op);
 		return -EINVAL;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 10/11] drm/amdgpu/userq: enable support for creating gangs
  2026-11-18 22:37 ` [PATCH 10/11] drm/amdgpu/userq: enable support for creating gangs Alex Deucher
@ 2026-11-18 22:58   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-18 22:58 UTC (permalink / raw)
  To: Alex Deucher, amd-gfx

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/amdgpu/userq: lock order inversion in
  amdgpu_userq_create_gang()
- [High] drm/amdgpu/userq: race between amdgpu_userq_destroy() and
  post_reset()
- [Medium] drm/amdgpu/userq: missing INVALID_VA check in
  amdgpu_userq_create_gang()
--

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

drm/amdgpu/userq: enable support for creating gangs

This commit adds the AMDGPU_USERQ_OP_CREATE_GANG ioctl operation to link
primary and secondary usermode queues into a gang and cleans up the gang
links when a queue is destroyed.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index 3afd17af28548..388385380d8bc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -566,6 +566,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
>  {
>  	struct amdgpu_device *adev = uq_mgr->adev;
>  	const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
> +	struct amdgpu_usermode_queue *other_gang_queue;
>  	int r = 0;
>  
>  	trace_amdgpu_userq_destroy_start(queue);
> @@ -585,6 +586,17 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
>  	debugfs_remove_recursive(queue->debugfs_queue);
>  #endif
>  	r = amdgpu_userq_unmap_helper(queue);
> +	/* clean up gangs */
> +	if (queue->gang_primary) {
> +		other_gang_queue = queue->gang_primary;
> +		other_gang_queue->gang_secondary = NULL;
> +		queue->gang_primary = NULL;
> +	}
> +	if (queue->gang_secondary) {
> +		other_gang_queue = queue->gang_secondary;
> +		other_gang_queue->gang_primary = NULL;
> +		queue->gang_secondary = NULL;
> +	}
>  	atomic_dec(&uq_mgr->userq_count[queue->queue_type]);
>  	amdgpu_userq_fence_driver_free(queue);
>  	queue->fence_drv = NULL;

[Severity: High]
Can amdgpu_userq_destroy() race with amdgpu_userq_post_reset() on the
partner queue's gang_secondary pointer and cause a use-after-free?

amdgpu_userq_destroy() holds uq_mgr->userq_mutex, while
amdgpu_userq_detach_doorbell() and amdgpu_userq_unmap_helper() each take
and release adev->reset_domain->sem individually.  During a GPU reset,
amdgpu_userq_post_reset() iterates adev->userq_doorbell_xa under
down_write(&adev->reset_domain->sem) without taking uq_mgr->userq_mutex:

CPU0                                  CPU1 (GPU reset)
amdgpu_userq_destroy(secondary)
  mutex_lock(&uq_mgr->userq_mutex)
  amdgpu_userq_detach_doorbell()
  amdgpu_userq_unmap_helper()
    /* releases reset_domain->sem */
                                      down_write(&adev->reset_domain->sem)
                                      amdgpu_userq_post_reset()
                                        amdgpu_userq_set_gang_helper(primary)
                                          sec = primary->gang_secondary
  primary->gang_secondary = NULL
  mutex_unlock(&uq_mgr->userq_mutex)
  uq_funcs->mqd_destroy(secondary)
  kfree(secondary)
                                          if (sec->state == ...)
                                            <-- use-after-free

In addition, if the reset begins between amdgpu_userq_detach_doorbell()
and amdgpu_userq_unmap_helper(), secondary is already erased from
adev->userq_doorbell_xa while still in AMDGPU_USERQ_STATE_MAPPED, and
amdgpu_userq_destroy() blocks on reset_domain->sem inside
amdgpu_userq_unmap_helper() before clearing primary->gang_secondary.
amdgpu_userq_post_reset() then remaps primary and calls
userq_funcs->set_gang(primary, secondary) on a secondary queue that was
never remapped after the reset and is about to be destroyed.

> @@ -838,6 +850,106 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
>  	return r;
>  }
>  
> +static int
> +amdgpu_userq_create_gang(struct drm_file *filp, union drm_amdgpu_userq *args)
> +{
> +	struct amdgpu_usermode_queue *primary_queue, *secondary_queue;
> +	struct amdgpu_fpriv *fpriv = filp->driver_priv;
> +	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
> +	const struct amdgpu_userq_funcs *userq_funcs;
> +	struct amdgpu_device *adev = uq_mgr->adev;
> +	int primary_queue_id = args->in_cg.primary_queue_id;
> +	int secondary_queue_id = args->in_cg.secondary_queue_id;
> +	int r;
> +
> +	/* The reset changes the queue state and the MES is unusable meanwhile */
> +	guard(rwsem_read)(&adev->reset_domain->sem);
> +
> +	mutex_lock(&uq_mgr->userq_mutex);

[Severity: High]
Does taking adev->reset_domain->sem before uq_mgr->userq_mutex invert the
lock hierarchy and risk an ABBA deadlock?

amdgpu_lockdep_init() and the rest of amdgpu_userq.c establish
uq_mgr->userq_mutex outer to adev->reset_domain->sem:

CPU0                              CPU1
----                              ----
lock(&uq_mgr->userq_mutex)
                                  down_read(&adev->reset_domain->sem)
down_read(&adev->reset_domain->sem)
                                  lock(&uq_mgr->userq_mutex)

 *** DEADLOCK ***

CPU0: amdgpu_userq_destroy() -> amdgpu_userq_unmap_helper()
CPU1: amdgpu_userq_create_gang()
(when a GPU reset writer is queued on adev->reset_domain->sem)

Also, because guard(rwsem_read)(&adev->reset_domain->sem) has function
scope, it is still held at the out label when amdgpu_userq_put() runs.
If a concurrent AMDGPU_USERQ_OP_FREE dropped the queue's base reference,
amdgpu_userq_put() enters amdgpu_userq_destroy() while holding
reset_domain->sem, waiting on cancel_delayed_work_sync() under the reset
semaphore and taking reset_domain->sem recursively in
amdgpu_userq_detach_doorbell() and amdgpu_userq_unmap_helper().

[ ... ]

> +	if (primary_queue->state == AMDGPU_USERQ_STATE_HUNG) {
> +		drm_file_err(uq_mgr->file, "Primary queue is hung\n");
> +		r = -EINVAL;
> +		goto out;
> +	}
> +
> +	if ((secondary_queue->queue_type != AMDGPU_HW_IP_GFX) &&
> +	    (secondary_queue->queue_type != AMDGPU_HW_IP_COMPUTE) &&
> +	    (secondary_queue->queue_type != AMDGPU_HW_IP_DMA)) {
> +		drm_file_err(uq_mgr->file, "Invalid gang secondary queue type\n");
> +		r = -EINVAL;
> +		goto out;
> +	}
> +
> +	if (secondary_queue->gang_primary || secondary_queue->gang_secondary) {
> +		drm_file_err(uq_mgr->file, "Secondary queue already in a gang\n");
> +		r = -EINVAL;
> +		goto out;
> +	}
> +
> +	if (secondary_queue->state == AMDGPU_USERQ_STATE_HUNG) {
> +		drm_file_err(uq_mgr->file, "Secondary queue is hung\n");
> +		r = -EINVAL;
> +		goto out;
> +	}
> +
> +	userq_funcs = adev->userq_funcs[primary_queue->queue_type];
> +	if ((primary_queue->state == AMDGPU_USERQ_STATE_MAPPED ||
> +	     primary_queue->state == AMDGPU_USERQ_STATE_PREEMPTED) &&
> +	    (secondary_queue->state == AMDGPU_USERQ_STATE_MAPPED ||
> +	     secondary_queue->state == AMDGPU_USERQ_STATE_PREEMPTED))
> +		r = userq_funcs->set_gang(primary_queue, secondary_queue);
> +	else
> +		/* if the queues are currently unmapped, the gang state will get
> +		 * updated when they get mapped.
> +		 */
> +		r = 0;

[Severity: Medium]
Should amdgpu_userq_create_gang() also reject queues in
AMDGPU_USERQ_STATE_INVALID_VA?

If a queue was marked AMDGPU_USERQ_STATE_INVALID_VA in
amdgpu_userq_restore_all(), amdgpu_userq_map_helper() will never remap it
(it only maps queues in AMDGPU_USERQ_STATE_UNMAPPED).  Here it passes the
HUNG checks and falls into the else branch with r = 0, linking a dead
queue into the partner queue's gang pointer without ever programming the
gang in MES.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges
@ 2026-12-02 15:51 Alex Deucher
  2026-12-02 15:51 ` [PATCH 02/11] drm/amdgpu/mes11: add API for gang submit Alex Deucher
                   ` (9 more replies)
  0 siblings, 10 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Each IP gets a subset of each doorbell page.  Add a query
so userspace can query the ranges.

v2: fix unit conversion

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 20 ++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h           |  6 ++++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index d7872acb4d790..0d157c18b7aaa 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -1453,6 +1453,26 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 			return -EINVAL;
 		}
 	}
+	case AMDGPU_INFO_UQ_DOORBELL_RANGE: {
+		struct drm_amdgpu_info_doorbell_range db_range = {};
+
+		switch (info->query_hw_ip.type) {
+		case AMDGPU_HW_IP_GFX:
+		case AMDGPU_HW_IP_COMPUTE:
+			db_range.offset_bytes = adev->doorbell_index.kiq << 3;
+			db_range.size_bytes = (adev->doorbell_index.sdma_engine[0] -
+					       adev->doorbell_index.kiq) << 3;
+			return copy_to_user(out, &db_range,
+					    min((size_t)size, sizeof(db_range))) ? -EFAULT : 0;
+		case AMDGPU_HW_IP_DMA:
+			db_range.offset_bytes = adev->doorbell_index.sdma_engine[0] << 3;
+			db_range.size_bytes = adev->doorbell_index.sdma_doorbell_range * adev->sdma.num_instances * 4;
+			return copy_to_user(out, &db_range,
+					    min((size_t)size, sizeof(db_range))) ? -EFAULT : 0;
+		default:
+			return -EINVAL;
+		}
+	}
 	default:
 		DRM_DEBUG_KMS("Invalid request %d\n", info->query);
 		return -EINVAL;
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 894fca0a79cc9..2379618f5df1f 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -1289,6 +1289,7 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {
 #define AMDGPU_INFO_GPUVM_FAULT			0x23
 /* query FW object size and alignment */
 #define AMDGPU_INFO_UQ_FW_AREAS			0x24
+#define AMDGPU_INFO_UQ_DOORBELL_RANGE		0x25
 
 #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT	0
 #define AMDGPU_INFO_MMR_SE_INDEX_MASK	0xff
@@ -1668,6 +1669,11 @@ struct drm_amdgpu_info_uq_metadata {
 	};
 };
 
+struct drm_amdgpu_info_doorbell_range {
+	__u32 offset_bytes;
+	__u32 size_bytes;
+};
+
 /*
  * Supported GPU families
  */
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 02/11] drm/amdgpu/mes11: add API for gang submit
  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 ` Alex Deucher
  2026-12-02 15:51 ` [PATCH 03/11] drm/amdgpu/mes: add callback " Alex Deucher
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Add API for setting up a gang.  Gangs schedule together.

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  2 +-
 drivers/gpu/drm/amd/include/mes_v11_api_def.h | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
index 7d8a56859fce5..b9a3652496a5e 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
@@ -147,7 +147,7 @@ static const char *mes_v11_0_opcodes[] = {
 	"UPDATE_ROOT_PAGE_TABLE",
 	"AMD_LOG",
 	"unused",
-	"unused",
+	"SET_GANG_SUBMIT",
 	"SET_HW_RSRC_1",
 };
 
diff --git a/drivers/gpu/drm/amd/include/mes_v11_api_def.h b/drivers/gpu/drm/amd/include/mes_v11_api_def.h
index 6d67d015a74fb..bf2161b2328ad 100644
--- a/drivers/gpu/drm/amd/include/mes_v11_api_def.h
+++ b/drivers/gpu/drm/amd/include/mes_v11_api_def.h
@@ -64,6 +64,7 @@ enum MES_SCH_API_OPCODE {
 	MES_SCH_API_MISC			= 14,
 	MES_SCH_API_UPDATE_ROOT_PAGE_TABLE      = 15,
 	MES_SCH_API_AMD_LOG                     = 16,
+	MES_SCH_API_SET_GANG_SUBMIT             = 18,
 	MES_SCH_API_SET_HW_RSRC_1               = 19,
 	MES_SCH_API_MAX				= 0xFF
 };
@@ -688,6 +689,13 @@ struct SET_SHADER_DEBUGGER {
 	uint32_t process_context_array_index;
 };
 
+struct SET_GANG_SUBMIT {
+	uint64_t gang_context_addr;
+	uint64_t slave_gang_context_addr;
+	uint32_t gang_context_array_index;
+	uint32_t slave_gang_context_array_index;
+};
+
 enum MESAPI_MISC__CHANGE_CONFIG_OPTION {
 	MESAPI_MISC__CHANGE_CONFIG_OPTION_LIMIT_SINGLE_PROCESS = 0,
 	MESAPI_MISC__CHANGE_CONFIG_OPTION_ENABLE_HWS_LOGGING_BUFFER = 1,
@@ -775,5 +783,15 @@ union MESAPI_AMD_LOG {
 	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
 };
 
+union MESAPI__SET_GANG_SUBMIT {
+	struct {
+		union MES_API_HEADER    header;
+		struct MES_API_STATUS   api_status;
+		struct SET_GANG_SUBMIT  set_gang_submit;
+	};
+
+	uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS];
+};
+
 #pragma pack(pop)
 #endif
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 03/11] drm/amdgpu/mes: add callback for gang submit
  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 ` Alex Deucher
  2026-12-02 15:51 ` [PATCH 04/11] drm/amdgpu/mes11: add support for setting " Alex Deucher
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Add function pointer for gang submit setup.

v2: handle array indices
v3: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h
index 3ee84b2ff12bf..762211ca70ef9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h
@@ -401,6 +401,13 @@ struct mes_inv_tlbs_pasid_input {
 	uint8_t         flush_type;
 };
 
+struct mes_set_gang_submit_input {
+	uint64_t	leader_gang_context_addr;
+	uint64_t	follower_gang_context_addr;
+	uint32_t	leader_gang_context_array_idx;
+	uint32_t	follower_gang_context_array_idx;
+};
+
 enum mes_misc_opcode {
 	MES_MISC_OP_WRITE_REG,
 	MES_MISC_OP_READ_REG,
@@ -521,6 +528,9 @@ struct amdgpu_mes_funcs {
 
 	int (*invalidate_tlbs_pasid)(struct amdgpu_mes *mes,
 			      struct mes_inv_tlbs_pasid_input *input);
+
+	int (*set_gang_submit)(struct amdgpu_mes *mes,
+			       struct mes_set_gang_submit_input *input);
 };
 
 enum amdgpu_mqd_update_flag {
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 04/11] drm/amdgpu/mes11: add support for setting gang submit
  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 ` Alex Deucher
  2026-12-02 15:51 ` [PATCH 05/11] drm/amdgpu/mes12: " Alex Deucher
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Enable a primary and secondary queue that schedule together.

v2: fix offset of api_status (Prike)
v3: handle array indices
v3: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
index b9a3652496a5e..8540d3409589a 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
@@ -1285,6 +1285,31 @@ static int mes_v11_0_enable_dbgext_irq(struct amdgpu_mes *mes, bool enable)
 	return 0;
 }
 
+static int mes_v11_0_set_gang_submit(struct amdgpu_mes *mes,
+				     struct mes_set_gang_submit_input *input)
+{
+	union MESAPI__SET_GANG_SUBMIT mes_gang_submit_pkt;
+
+	memset(&mes_gang_submit_pkt, 0, sizeof(mes_gang_submit_pkt));
+
+	mes_gang_submit_pkt.header.type = MES_API_TYPE_SCHEDULER;
+	mes_gang_submit_pkt.header.opcode = MES_SCH_API_SET_GANG_SUBMIT;
+	mes_gang_submit_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+	mes_gang_submit_pkt.set_gang_submit.gang_context_addr =
+		input->leader_gang_context_addr;
+	mes_gang_submit_pkt.set_gang_submit.slave_gang_context_addr =
+		input->follower_gang_context_addr;
+	mes_gang_submit_pkt.set_gang_submit.gang_context_array_index =
+		input->leader_gang_context_array_idx;
+	mes_gang_submit_pkt.set_gang_submit.slave_gang_context_array_index =
+		input->follower_gang_context_array_idx;
+
+	return mes_v11_0_submit_pkt_and_poll_completion(mes,
+			&mes_gang_submit_pkt, sizeof(mes_gang_submit_pkt),
+			offsetof(union MESAPI__SET_GANG_SUBMIT, api_status));
+}
+
 static const struct amdgpu_mes_funcs mes_v11_0_funcs = {
 	.add_hw_queue = mes_v11_0_add_hw_queue,
 	.remove_hw_queue = mes_v11_0_remove_hw_queue,
@@ -1296,6 +1321,7 @@ static const struct amdgpu_mes_funcs mes_v11_0_funcs = {
 	.enable_dbgext_irq = mes_v11_0_enable_dbgext_irq,
 	.reset_hw_queue = mes_v11_0_reset_hw_queue,
 	.detect_and_reset_hung_queues = mes_v11_0_detect_and_reset_hung_queues,
+	.set_gang_submit = mes_v11_0_set_gang_submit,
 };
 
 static int mes_v11_0_allocate_ucode_buffer(struct amdgpu_device *adev,
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 05/11] drm/amdgpu/mes12: add support for setting gang submit
  2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
                   ` (2 preceding siblings ...)
  2026-12-02 15:51 ` [PATCH 04/11] drm/amdgpu/mes11: add support for setting " Alex Deucher
@ 2026-12-02 15:51 ` Alex Deucher
  2026-12-02 15:51 ` [PATCH 06/11] drm/amdgpu/userq: add callback for gang setup Alex Deucher
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Enable a primary and secondary queue that schedule together.

v2: fix offset of api_status (Prike)
v3: use AMDGPU_MES_SCHED_PIPE (Michael)
v4: handle array indices
v5: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c b/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c
index 988e05823d2d7..64604efe7ce97 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c
@@ -1313,7 +1313,31 @@ static int mes_v12_0_inv_tlbs_pasid(struct amdgpu_mes *mes,
 	return mes_v12_0_submit_pkt_and_poll_completion(mes, AMDGPU_MES_KIQ_PIPE,
 			&mes_inv_tlbs, sizeof(mes_inv_tlbs),
 			offsetof(union MESAPI__INV_TLBS, api_status));
+}
+
+static int mes_v12_0_set_gang_submit(struct amdgpu_mes *mes,
+				     struct mes_set_gang_submit_input *input)
+{
+	union MESAPI__SET_GANG_SUBMIT mes_gang_submit_pkt;
+
+	memset(&mes_gang_submit_pkt, 0, sizeof(mes_gang_submit_pkt));
 
+	mes_gang_submit_pkt.header.type = MES_API_TYPE_SCHEDULER;
+	mes_gang_submit_pkt.header.opcode = MES_SCH_API_SET_GANG_SUBMIT;
+	mes_gang_submit_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+	mes_gang_submit_pkt.set_gang_submit.gang_context_addr =
+		input->leader_gang_context_addr;
+	mes_gang_submit_pkt.set_gang_submit.slave_gang_context_addr =
+		input->follower_gang_context_addr;
+	mes_gang_submit_pkt.set_gang_submit.gang_context_array_index =
+		input->leader_gang_context_array_idx;
+	mes_gang_submit_pkt.set_gang_submit.slave_gang_context_array_index =
+		input->follower_gang_context_array_idx;
+
+	return mes_v12_0_submit_pkt_and_poll_completion(mes, AMDGPU_MES_SCHED_PIPE,
+			&mes_gang_submit_pkt, sizeof(mes_gang_submit_pkt),
+			offsetof(union MESAPI__SET_GANG_SUBMIT, api_status));
 }
 
 /*
@@ -1367,6 +1391,7 @@ static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
 	.invalidate_tlbs_pasid = mes_v12_0_inv_tlbs_pasid,
 	.detect_and_reset_hung_queues = mes_v12_0_detect_and_reset_hung_queues,
 	.enable_dbgext_irq = mes_v12_0_enable_dbgext_irq,
+	.set_gang_submit = mes_v12_0_set_gang_submit,
 };
 
 static int mes_v12_0_allocate_ucode_buffer(struct amdgpu_device *adev,
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 06/11] drm/amdgpu/userq: add callback for gang setup
  2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
                   ` (3 preceding siblings ...)
  2026-12-02 15:51 ` [PATCH 05/11] drm/amdgpu/mes12: " Alex Deucher
@ 2026-12-02 15:51 ` Alex Deucher
  2026-12-02 15:51 ` [PATCH 07/11] drm/amdgpu/userq/mes: implement set gang submit Alex Deucher
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Two queues can be ganged and will schedule together.

v2: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index 488dc21d7c81b..a58f0c0a671c6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
@@ -115,6 +115,8 @@ struct amdgpu_userq_funcs {
 	int (*preempt)(struct amdgpu_usermode_queue *queue);
 	int (*restore)(struct amdgpu_usermode_queue *queue);
 	int (*reset)(struct amdgpu_usermode_queue *queue);
+	int (*set_gang)(struct amdgpu_usermode_queue *leader_queue,
+			struct amdgpu_usermode_queue *follower_queue);
 };
 
 /* Usermode queues for gfx */
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 07/11] drm/amdgpu/userq/mes: implement set gang submit
  2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
                   ` (4 preceding siblings ...)
  2026-12-02 15:51 ` [PATCH 06/11] drm/amdgpu/userq: add callback for gang setup Alex Deucher
@ 2026-12-02 15:51 ` Alex Deucher
  2026-12-02 15:51 ` [PATCH 08/11] drm/amdgpu/userq: add handling for set_gang Alex Deucher
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Enable the userq callback for setting up gang submission.

v2: fix context addr after rebase, array indices
v3: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 7abb9d95ef59a..b112b39d512b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -649,6 +649,36 @@ static int mes_userq_restore(struct amdgpu_usermode_queue *queue)
 	return r;
 }
 
+static int mes_set_gang(struct amdgpu_usermode_queue *leader_queue,
+			struct amdgpu_usermode_queue *follower_queue)
+{
+	struct amdgpu_userq_obj *leader_ctx = &leader_queue->fw_obj;
+	struct amdgpu_userq_obj *follower_ctx = &follower_queue->fw_obj;
+	struct amdgpu_userq_mgr *uq_mgr = leader_queue->userq_mgr;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	struct mes_set_gang_submit_input input;
+	struct amdgpu_mes *mes = &adev->mes;
+	int r;
+
+	memset(&input, 0x0, sizeof(struct mes_set_gang_submit_input));
+
+	input.leader_gang_context_addr = leader_ctx->gpu_addr;
+	input.follower_gang_context_addr = follower_ctx->gpu_addr;
+	if (mes->use_rs64mem) {
+		input.leader_gang_context_array_idx =
+			leader_queue->gang_ctx_array_index;
+		input.follower_gang_context_array_idx =
+			follower_queue->gang_ctx_array_index;
+	}
+
+	amdgpu_mes_lock(&adev->mes);
+	r = adev->mes.funcs->set_gang_submit(&adev->mes, &input);
+	amdgpu_mes_unlock(&adev->mes);
+	if (r)
+		dev_err(adev->dev, "Failed to set gang submit, err (%d)\n", r);
+	return r;
+}
+
 const struct amdgpu_userq_funcs userq_mes_funcs = {
 	.mqd_create = mes_userq_mqd_create,
 	.mqd_destroy = mes_userq_mqd_destroy,
@@ -657,4 +687,5 @@ const struct amdgpu_userq_funcs userq_mes_funcs = {
 	.preempt = mes_userq_preempt,
 	.restore = mes_userq_restore,
 	.reset = mes_userq_reset,
+	.set_gang = mes_set_gang,
 };
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 08/11] drm/amdgpu/userq: add handling for set_gang
  2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
                   ` (5 preceding siblings ...)
  2026-12-02 15:51 ` [PATCH 07/11] drm/amdgpu/userq/mes: implement set gang submit Alex Deucher
@ 2026-12-02 15:51 ` Alex Deucher
  2026-12-02 16:10   ` sashiko-bot
  2026-12-02 15:51 ` [PATCH 09/11] drm/amdgpu: add UAPI to create user queue gangs Alex Deucher
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Make sure the ganged queues are handled properly in
map, unmap, restore, and preempt.  Need to call
set_gang to make sure the queues are schedule together.

v2: rework all of the logic
v3: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 40 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  2 ++
 2 files changed, 42 insertions(+)

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);
 
 	if (ret)
@@ -1446,6 +1472,13 @@ int amdgpu_userq_resume(struct amdgpu_device *adev)
 		if (r)
 			return r;
 	}
+	xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
+		uqm = queue->userq_mgr;
+		guard(mutex)(&uqm->userq_mutex);
+		r = amdgpu_userq_set_gang_helper(queue);
+		if (r)
+			return r;
+	}
 
 	return 0;
 }
@@ -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;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index a58f0c0a671c6..0f64db8c1a05e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
@@ -102,6 +102,8 @@ struct amdgpu_usermode_queue {
 	} userq_vas;
 
 	uint32_t	gang_ctx_array_index;
+	struct amdgpu_usermode_queue *gang_leader;
+	struct amdgpu_usermode_queue *gang_follower;
 };
 
 struct amdgpu_userq_funcs {
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 09/11] drm/amdgpu: add UAPI to create user queue gangs
  2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
                   ` (6 preceding siblings ...)
  2026-12-02 15:51 ` [PATCH 08/11] drm/amdgpu/userq: add handling for set_gang Alex Deucher
@ 2026-12-02 15:51 ` 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 15:51 ` [PATCH 11/11] drm/amdgpu: bump driver version for userq updates Alex Deucher
  9 siblings, 1 reply; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Queues in a gang will schedule together.

v2: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 include/uapi/drm/amdgpu_drm.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 2379618f5df1f..b805b05e9e45e 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -340,6 +340,7 @@ union drm_amdgpu_ctx {
 /* user queue IOCTL operations */
 #define AMDGPU_USERQ_OP_CREATE	1
 #define AMDGPU_USERQ_OP_FREE	2
+#define AMDGPU_USERQ_OP_CREATE_GANG	3
 
 /* queue priority levels */
 /* low < normal low < normal high < high */
@@ -422,6 +423,15 @@ struct drm_amdgpu_userq_in {
 	__u64 mqd_size;
 };
 
+struct drm_amdgpu_userq_in_create_gang {
+	/** AMDGPU_USERQ_OP_* */
+	__u32	op;
+	__u32	pad;
+	/** Queue ids passed for operation USERQ_OP_CREATE_GANG */
+	__u32	leader_queue_id;
+	__u32	follower_queue_id;
+};
+
 /* The structure to carry output of userqueue ops */
 struct drm_amdgpu_userq_out {
 	/**
@@ -435,6 +445,7 @@ struct drm_amdgpu_userq_out {
 
 union drm_amdgpu_userq {
 	struct drm_amdgpu_userq_in in;
+	struct drm_amdgpu_userq_in_create_gang in_cg;
 	struct drm_amdgpu_userq_out out;
 };
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 10/11] drm/amdgpu/userq: enable support for creating gangs
  2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
                   ` (7 preceding siblings ...)
  2026-12-02 15:51 ` [PATCH 09/11] drm/amdgpu: add UAPI to create user queue gangs Alex Deucher
@ 2026-12-02 15:51 ` 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
  9 siblings, 1 reply; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu

Gangs are sets of userqs that schedule together.  You
specify the primary and secondary queues and the scheduler
will make sure they always run at the same time.

v2: handle setting up the gang again after unmaps
v3: split the UAPI part from the internal tracking
v4: rework
v5: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 122 +++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 0785759967144..6135a5c110ef4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -566,6 +566,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
 {
 	struct amdgpu_device *adev = uq_mgr->adev;
 	const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
+	struct amdgpu_usermode_queue *other_gang_queue;
 	int r = 0;
 
 	trace_amdgpu_userq_destroy_start(queue);
@@ -585,6 +586,17 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
 	debugfs_remove_recursive(queue->debugfs_queue);
 #endif
 	r = amdgpu_userq_unmap_helper(queue);
+	/* clean up gangs */
+	if (queue->gang_leader) {
+		other_gang_queue = queue->gang_leader;
+		other_gang_queue->gang_follower = NULL;
+		queue->gang_leader = NULL;
+	}
+	if (queue->gang_follower) {
+		other_gang_queue = queue->gang_follower;
+		other_gang_queue->gang_leader = NULL;
+		queue->gang_follower = NULL;
+	}
 	atomic_dec(&uq_mgr->userq_count[queue->queue_type]);
 	amdgpu_userq_fence_driver_free(queue);
 	queue->fence_drv = NULL;
@@ -838,6 +850,106 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	return r;
 }
 
+static int
+amdgpu_userq_create_gang(struct drm_file *filp, union drm_amdgpu_userq *args)
+{
+	struct amdgpu_usermode_queue *leader_queue, *follower_queue;
+	struct amdgpu_fpriv *fpriv = filp->driver_priv;
+	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+	const struct amdgpu_userq_funcs *userq_funcs;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	int leader_queue_id = args->in_cg.leader_queue_id;
+	int follower_queue_id = args->in_cg.follower_queue_id;
+	int r;
+
+	/* The reset changes the queue state and the MES is unusable meanwhile */
+	guard(rwsem_read)(&adev->reset_domain->sem);
+
+	mutex_lock(&uq_mgr->userq_mutex);
+	leader_queue = amdgpu_userq_get(uq_mgr, leader_queue_id);
+	follower_queue = amdgpu_userq_get(uq_mgr, follower_queue_id);
+
+	if (!leader_queue) {
+		drm_file_err(uq_mgr->file, "Invalid gang leader queue id\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (!follower_queue) {
+		drm_file_err(uq_mgr->file, "Invalid gang follower queue id\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (leader_queue == follower_queue) {
+		drm_file_err(uq_mgr->file, "Trying to gang the same queue\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if ((leader_queue->queue_type != AMDGPU_HW_IP_GFX) &&
+	    (leader_queue->queue_type != AMDGPU_HW_IP_COMPUTE) &&
+	    (leader_queue->queue_type != AMDGPU_HW_IP_DMA)) {
+		drm_file_err(uq_mgr->file, "Invalid gang leader queue type\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (leader_queue->gang_leader || leader_queue->gang_follower) {
+		drm_file_err(uq_mgr->file, "Leader queue already in a gang\n");
+		r = -EINVAL;
+		goto out;
+	}
+	if (leader_queue->state == AMDGPU_USERQ_STATE_HUNG) {
+		drm_file_err(uq_mgr->file, "Leader queue is hung\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if ((follower_queue->queue_type != AMDGPU_HW_IP_GFX) &&
+	    (follower_queue->queue_type != AMDGPU_HW_IP_COMPUTE) &&
+	    (follower_queue->queue_type != AMDGPU_HW_IP_DMA)) {
+		drm_file_err(uq_mgr->file, "Invalid gang follower queue type\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (follower_queue->gang_leader || follower_queue->gang_follower) {
+		drm_file_err(uq_mgr->file, "Follower queue already in a gang\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (follower_queue->state == AMDGPU_USERQ_STATE_HUNG) {
+		drm_file_err(uq_mgr->file, "Follower queue is hung\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	userq_funcs = adev->userq_funcs[leader_queue->queue_type];
+	if ((leader_queue->state == AMDGPU_USERQ_STATE_MAPPED ||
+	     leader_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(leader_queue, follower_queue);
+	else
+		/* if the queues are currently unmapped, the gang state will get
+		 * updated when they get mapped.
+		 */
+		r = 0;
+	if (!r) {
+		leader_queue->gang_follower = follower_queue;
+		follower_queue->gang_leader = leader_queue;
+	}
+
+out:
+	mutex_unlock(&uq_mgr->userq_mutex);
+	amdgpu_userq_put(leader_queue);
+	amdgpu_userq_put(follower_queue);
+
+	return r;
+}
+
 static int amdgpu_userq_input_args_validate(struct drm_device *dev,
 					union drm_amdgpu_userq *args,
 					struct drm_file *filp)
@@ -907,6 +1019,10 @@ static int amdgpu_userq_input_args_validate(struct drm_device *dev,
 		    args->in.mqd_size)
 			return -EINVAL;
 		break;
+	case AMDGPU_USERQ_OP_CREATE_GANG:
+		if (args->in_cg.pad)
+			return -EINVAL;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -958,7 +1074,11 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 		amdgpu_userq_put(queue);
 		break;
 	}
-
+	case AMDGPU_USERQ_OP_CREATE_GANG:
+		r = amdgpu_userq_create_gang(filp, args);
+		if (r)
+			drm_file_err(filp, "Failed to create usermode queue gang\n");
+		break;
 	default:
 		drm_dbg_driver(dev, "Invalid user queue op specified: %d\n", args->in.op);
 		return -EINVAL;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 11/11] drm/amdgpu: bump driver version for userq updates
  2026-12-02 15:51 [PATCH 01/11] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
                   ` (8 preceding siblings ...)
  2026-12-02 15:51 ` [PATCH 10/11] drm/amdgpu/userq: enable support for creating gangs Alex Deucher
@ 2026-12-02 15:51 ` Alex Deucher
  9 siblings, 0 replies; 16+ messages in thread
From: Alex Deucher @ 2026-12-02 15:51 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alex Deucher

Support for ganging userqs and doorbell offset queries.
Ganged userqs are guaranteed to schedule together and
the new doorbell offset query allows the UMD to query
what offsets in each dorbell page get routed to which
engine.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 2a86142699842..17d609480361f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -129,9 +129,10 @@
  * - 3.64.0 - Userq IP support query
  * - 3.65.0 - Add userq syncobj timeline signaling support
  * - 3.66.0 - Allow jpeg type 4 packets and VCE SEI command
+ * - 3.67.0 - Add userq gang support and doorbell offset query
  */
 #define KMS_DRIVER_MAJOR	3
-#define KMS_DRIVER_MINOR	66
+#define KMS_DRIVER_MINOR	67
 #define KMS_DRIVER_PATCHLEVEL	0
 
 /*
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 10/11] drm/amdgpu/userq: enable support for creating gangs
  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
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-02 16:09 UTC (permalink / raw)
  To: Alex Deucher, amd-gfx

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdgpu/userq: lock inversion in amdgpu_userq_create_gang()
- [High] drm/amdgpu/userq: race with GPU reset in amdgpu_userq_destroy()
  gang cleanup
--

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

drm/amdgpu/userq: enable support for creating gangs

This commit adds the AMDGPU_USERQ_OP_CREATE_GANG ioctl operation to pair a
leader and follower usermode queue into a gang, and cleans up the gang
links when a queue is destroyed.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index 0785759967144..6135a5c110ef4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -566,6 +566,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
>  {
>  	struct amdgpu_device *adev = uq_mgr->adev;
>  	const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
> +	struct amdgpu_usermode_queue *other_gang_queue;
>  	int r = 0;
>  
>  	trace_amdgpu_userq_destroy_start(queue);
> @@ -585,6 +586,17 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
>  	debugfs_remove_recursive(queue->debugfs_queue);
>  #endif
>  	r = amdgpu_userq_unmap_helper(queue);
> +	/* clean up gangs */
> +	if (queue->gang_leader) {
> +		other_gang_queue = queue->gang_leader;
> +		other_gang_queue->gang_follower = NULL;
> +		queue->gang_leader = NULL;
> +	}
> +	if (queue->gang_follower) {
> +		other_gang_queue = queue->gang_follower;
> +		other_gang_queue->gang_leader = NULL;
> +		queue->gang_follower = NULL;
> +	}
>  	atomic_dec(&uq_mgr->userq_count[queue->queue_type]);
>  	amdgpu_userq_fence_driver_free(queue);
>  	queue->fence_drv = NULL;

[Severity: High]
Can amdgpu_userq_post_reset() access a follower queue while or after
amdgpu_userq_destroy() frees it?

amdgpu_userq_pre_reset() and amdgpu_userq_post_reset() walk
adev->userq_doorbell_xa under down_write(&adev->reset_domain->sem) without
taking uq_mgr->userq_mutex.  In amdgpu_userq_destroy(),
amdgpu_userq_detach_doorbell() and amdgpu_userq_unmap_helper() each take
and release down_read(&adev->reset_domain->sem) before gang_follower is
cleared here, and kfree(queue) runs without reset_domain->sem:

CPU0                                  CPU1
amdgpu_userq_destroy(follower)
  amdgpu_userq_detach_doorbell()
  amdgpu_userq_unmap_helper()
    /* releases reset_domain->sem */
                                      amdgpu_userq_post_reset()
                                        /* holds reset_domain->sem */
                                        amdgpu_userq_set_gang_helper(leader)
                                          follower = leader->gang_follower
  leader->gang_follower = NULL
  mutex_unlock(&uq_mgr->userq_mutex)
  uq_funcs->mqd_destroy(follower)
  kfree(follower)
                                          follower->state
                                          userq_funcs->set_gang(leader,
                                            follower)  <-- use-after-free

Even if the reset runs earlier, between amdgpu_userq_detach_doorbell() and
amdgpu_userq_unmap_helper(), follower has already been erased from
userq_doorbell_xa while follower->state is still AMDGPU_USERQ_STATE_MAPPED,
so amdgpu_userq_post_reset() skips remapping follower after the reset but
still calls set_gang(leader, follower) on it.

> @@ -838,6 +850,106 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
>  	return r;
>  }
>  
> +static int
> +amdgpu_userq_create_gang(struct drm_file *filp, union drm_amdgpu_userq *args)
> +{
> +	struct amdgpu_usermode_queue *leader_queue, *follower_queue;
> +	struct amdgpu_fpriv *fpriv = filp->driver_priv;
> +	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
> +	const struct amdgpu_userq_funcs *userq_funcs;
> +	struct amdgpu_device *adev = uq_mgr->adev;
> +	int leader_queue_id = args->in_cg.leader_queue_id;
> +	int follower_queue_id = args->in_cg.follower_queue_id;
> +	int r;
> +
> +	/* The reset changes the queue state and the MES is unusable meanwhile */
> +	guard(rwsem_read)(&adev->reset_domain->sem);
> +
> +	mutex_lock(&uq_mgr->userq_mutex);
> +	leader_queue = amdgpu_userq_get(uq_mgr, leader_queue_id);
> +	follower_queue = amdgpu_userq_get(uq_mgr, follower_queue_id);

[ ... ]

> +out:
> +	mutex_unlock(&uq_mgr->userq_mutex);
> +	amdgpu_userq_put(leader_queue);
> +	amdgpu_userq_put(follower_queue);
> +
> +	return r;
> +}

[Severity: High]
Does taking adev->reset_domain->sem before uq_mgr->userq_mutex invert the
lock hierarchy?

All other userq paths and amdgpu_lockdep_init() take uq_mgr->userq_mutex
outer to adev->reset_domain->sem (which is acquired inside
amdgpu_userq_map_helper(), amdgpu_userq_unmap_helper(), and
amdgpu_userq_detach_doorbell()):

CPU0                              CPU1
----                              ----
lock(&uq_mgr->userq_mutex)
                                  down_read(&adev->reset_domain->sem)
down_read(&adev->reset_domain->sem)
                                  lock(&uq_mgr->userq_mutex)

 *** DEADLOCK ***

CPU0: amdgpu_userq_destroy() -> amdgpu_userq_unmap_helper()
CPU1: amdgpu_userq_create_gang()

When a GPU reset writer is queued on adev->reset_domain->sem, CPU0's
down_read() blocks behind it while CPU1 blocks on uq_mgr->userq_mutex.

In addition, because guard(rwsem_read)(&adev->reset_domain->sem) is scoped
to the whole function, amdgpu_userq_put() at out: runs with
reset_domain->sem still read-locked.  If a concurrent AMDGPU_USERQ_OP_FREE
drops its reference first, amdgpu_userq_put() here enters
amdgpu_userq_destroy() under reset_domain->sem, where
cancel_delayed_work_sync(&queue->hang_detect_work) and the inner
down_read(&adev->reset_domain->sem) calls can also deadlock against a reset.

Acquiring reset_domain->sem only around userq_funcs->set_gang() (or inside
amdgpu_userq_set_gang_helper() while holding uq_mgr->userq_mutex) would
preserve the lock order and release the semaphore before amdgpu_userq_put().

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 08/11] drm/amdgpu/userq: add handling for set_gang
  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
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-02 16:10 UTC (permalink / raw)
  To: Alex Deucher, amd-gfx

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 09/11] drm/amdgpu: add UAPI to create user queue gangs
  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
  0 siblings, 0 replies; 16+ messages in thread
From: Mohan Marimuthu, Yogesh @ 2026-12-02 16:16 UTC (permalink / raw)
  To: Deucher, Alexander, amd-gfx@lists.freedesktop.org

[-- Attachment #1: Type: text/plain, Size: 1908 bytes --]

Public


This patch is Acked-by: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>

________________________________
From: Alex Deucher <alexander.deucher@amd.com>
Sent: Wednesday, December 2, 2026 9:21 PM
To: amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Mohan Marimuthu, Yogesh <Yogesh.Mohanmarimuthu@amd.com>
Subject: [PATCH 09/11] drm/amdgpu: add UAPI to create user queue gangs

Queues in a gang will schedule together.

v2: leader/follower rename

Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 include/uapi/drm/amdgpu_drm.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 2379618f5df1f..b805b05e9e45e 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -340,6 +340,7 @@ union drm_amdgpu_ctx {
 /* user queue IOCTL operations */
 #define AMDGPU_USERQ_OP_CREATE  1
 #define AMDGPU_USERQ_OP_FREE    2
+#define AMDGPU_USERQ_OP_CREATE_GANG    3

 /* queue priority levels */
 /* low < normal low < normal high < high */
@@ -422,6 +423,15 @@ struct drm_amdgpu_userq_in {
         __u64 mqd_size;
 };

+struct drm_amdgpu_userq_in_create_gang {
+       /** AMDGPU_USERQ_OP_* */
+       __u32   op;
+       __u32   pad;
+       /** Queue ids passed for operation USERQ_OP_CREATE_GANG */
+       __u32   leader_queue_id;
+       __u32   follower_queue_id;
+};
+
 /* The structure to carry output of userqueue ops */
 struct drm_amdgpu_userq_out {
         /**
@@ -435,6 +445,7 @@ struct drm_amdgpu_userq_out {

 union drm_amdgpu_userq {
         struct drm_amdgpu_userq_in in;
+       struct drm_amdgpu_userq_in_create_gang in_cg;
         struct drm_amdgpu_userq_out out;
 };

--
2.56.1


[-- Attachment #2: Type: text/html, Size: 3884 bytes --]

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-12-02 16:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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 10/11] drm/amdgpu/userq: enable support for creating gangs Alex Deucher
2026-11-18 22:58   ` sashiko-bot

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.