Skip to contentSkip to conversation

drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers

PATCH Superseded Jesse Zhang 1 participant 11 messages Aug 21 – Aug 27

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/10 drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers

Split the inlined compute path out of mes_userq_mqd_update() into mes_userq_compute_mqd_update() and turn the former into a dispatcher that switches on queue_type, giving other IPs an obvious place to hook in.

No functional change.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +15 -7
index ad72ced472dd..82bb4369451e 100644
@@ -681,7 +681,8 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 	return r;
 }
 
-static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_amdgpu_userq_in *args_in)
+static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
+					struct drm_amdgpu_userq_in *args_in)
 {
 	int retval = 0;
 	struct amdgpu_device *adev = queue->userq_mgr->adev;
@@ -689,12 +690,6 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_
 	struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue->queue_type];
 	struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd_v11;
 
-	if (!queue || !userq_props)
-		return -EINVAL;
-
-	if (queue->queue_type != AMDGPU_HW_IP_COMPUTE)
-		return -EINVAL;
-
 	if (args_in->mqd_size != sizeof(*compute_mqd_v11)) {
 		DRM_ERROR("Invalid compute IP MQD size\n");
 		return -EINVAL;
@@ -720,6 +715,19 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_
 	return retval;
 }
 
+static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_amdgpu_userq_in *args_in)
+{
+	if (!queue || !queue->userq_prop)
+		return -EINVAL;
+
+	switch (queue->queue_type) {
+	case AMDGPU_HW_IP_COMPUTE:
+		return mes_userq_compute_mqd_update(queue, args_in);
+	default:
+		return -EINVAL;
+	}
+}
+
 static void mes_userq_mqd_destroy(struct amdgpu_usermode_queue *queue)
 {
 
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/10 drm/amdgpu: add update_mqd callback for queue MODIFY

A queue MODIFY (e.g. re-enabling a queue after a queue_percentage == 0 disable) must not rebuild the MQD with init_mqd: init_mqd rebuilds the HQD from power-on defaults and zeroes the ring pointers, discarding the state firmware context-saved into the MQD on unmap. The re-mapped engine then comes up idle, drops the packet queued while disabled, and wedges into a GPU reset.

Add an optional update_mqd hook to struct amdgpu_mqd for IPs to patch the MQD in place instead - preserving the saved ring/HQD state and forwarding user_wptr into the MQD write pointer. KFD already handles the same disable/re-enable sequence by patching the MQD in place rather than re-initialising it.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +6 -0
index 63670b41c26c..2f73eceea57d 100644
@@ -500,6 +500,12 @@ struct amdgpu_mqd {
 	unsigned mqd_size;
 	int (*init_mqd)(struct amdgpu_device *adev, void *mqd,
 			struct amdgpu_mqd_prop *p);
+	/* Patch an MQD in place for a queue MODIFY: keep the ring/HQD state
+	 * firmware context-saved into it (init_mqd instead rebuilds from
+	 * defaults) and forward @user_wptr into the MQD write pointer.
+	 */
+	int (*update_mqd)(struct amdgpu_device *adev, void *mqd,
+			  struct amdgpu_mqd_prop *p, u64 user_wptr);
 };
 
 /*
Signature · 1 line
2.49.0
#2 lore raw

PATCH 3/10 drm/amdgpu/gfx11: implement compute and GFX update_mqd

In reply to Jesse Zhang

Implement the update_mqd callback for gfx11 compute and GFX user queues. It patches only the fields a MODIFY can change (compute: queue_size, CU mask, priority; GFX: queue_size, priority, shadow/CSA) and forwards the write pointer to the user wptr while keeping the firmware-saved read pointer, so a re-enabled queue resumes at the first un-consumed packet rather than replaying the ring from 0.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 69 ++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +69 -0
index a447562977ab..2e25ffdb7f12 100644
@@ -4256,6 +4256,39 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	return 0;
 }
 
+/*
+ * GFX update_mqd: patch queue_size, ring base, priority and shadow/CSA in place
+ * and forward the write pointer, keeping the firmware-saved rptr.
+ */
+static int gfx_v11_0_gfx_mqd_update(struct amdgpu_device *adev, void *m,
+				    struct amdgpu_mqd_prop *prop,
+				    u64 user_wptr)
+{
+	struct v11_gfx_mqd *mqd = m;
+	uint32_t rb_bufsz, tmp;
+
+	rb_bufsz = order_base_2(prop->queue_size / 4) - 1;
+	tmp = mqd->cp_gfx_hqd_cntl;
+	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BUFSZ, rb_bufsz);
+	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BLKSZ, rb_bufsz - 2);
+	mqd->cp_gfx_hqd_cntl = tmp;
+
+	mqd->cp_gfx_hqd_base = prop->hqd_base_gpu_addr >> 8;
+	mqd->cp_gfx_hqd_base_hi = upper_32_bits(prop->hqd_base_gpu_addr >> 8);
+
+	gfx_v11_0_gfx_mqd_set_priority(adev, mqd, prop);
+
+	mqd->shadow_base_lo = lower_32_bits(prop->shadow_addr);
+	mqd->shadow_base_hi = upper_32_bits(prop->shadow_addr);
+	mqd->fw_work_area_base_lo = lower_32_bits(prop->csa_addr);
+	mqd->fw_work_area_base_hi = upper_32_bits(prop->csa_addr);
+
+	mqd->cp_gfx_hqd_wptr = lower_32_bits(user_wptr);
+	mqd->cp_gfx_hqd_wptr_hi = upper_32_bits(user_wptr);
+
+	return 0;
+}
+
 static int gfx_v11_0_kgq_init_queue(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -4477,6 +4510,38 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 	return 0;
 }
 
+/*
+ * Compute update_mqd: patch queue_size, ring/EOP base, CU mask and priority in
+ * place and forward the write pointer, keeping the firmware-saved rptr.
+ */
+static int gfx_v11_0_compute_mqd_update(struct amdgpu_device *adev, void *m,
+					struct amdgpu_mqd_prop *prop,
+					u64 user_wptr)
+{
+	struct v11_compute_mqd *mqd = m;
+
+	mqd->cp_hqd_pq_control &= ~CP_HQD_PQ_CONTROL__QUEUE_SIZE_MASK;
+	mqd->cp_hqd_pq_control |=
+		(order_base_2(prop->queue_size / 4) - 1)
+		<< CP_HQD_PQ_CONTROL__QUEUE_SIZE__SHIFT;
+
+	mqd->cp_hqd_pq_base_lo = prop->hqd_base_gpu_addr >> 8;
+	mqd->cp_hqd_pq_base_hi = upper_32_bits(prop->hqd_base_gpu_addr >> 8);
+
+	mqd->cp_hqd_eop_base_addr_lo = prop->eop_gpu_addr >> 8;
+	mqd->cp_hqd_eop_base_addr_hi = upper_32_bits(prop->eop_gpu_addr >> 8);
+
+	mqd->cp_hqd_pipe_priority = prop->hqd_pipe_priority;
+	mqd->cp_hqd_queue_priority = prop->hqd_queue_priority;
+
+	gfx_v11_0_compute_mqd_set_cu_mask(adev, mqd, prop);
+
+	mqd->cp_hqd_pq_wptr_lo = lower_32_bits(user_wptr);
+	mqd->cp_hqd_pq_wptr_hi = upper_32_bits(user_wptr);
+
+	return 0;
+}
+
 static int gfx_v11_0_kiq_init_register(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -7271,11 +7336,15 @@ static void gfx_v11_0_set_mqd_funcs(struct amdgpu_device *adev)
 		sizeof(struct v11_gfx_mqd);
 	adev->mqds[AMDGPU_HW_IP_GFX].init_mqd =
 		gfx_v11_0_gfx_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_GFX].update_mqd =
+		gfx_v11_0_gfx_mqd_update;
 	/* set compute eng mqd */
 	adev->mqds[AMDGPU_HW_IP_COMPUTE].mqd_size =
 		sizeof(struct v11_compute_mqd);
 	adev->mqds[AMDGPU_HW_IP_COMPUTE].init_mqd =
 		gfx_v11_0_compute_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_COMPUTE].update_mqd =
+		gfx_v11_0_compute_mqd_update;
 }
 
 static void gfx_v11_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
#3 lore raw

PATCH 4/10 drm/amdgpu/gfx12: implement compute and GFX update_mqd

In reply to Jesse Zhang

Implement the update_mqd callback for gfx12 compute and GFX user queues. It patches only the fields a MODIFY can change (compute: queue_size, CU mask, priority; GFX: queue_size, priority, shadow/CSA) and forwards the write pointer to the user wptr while keeping the firmware-saved read pointer.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 74 ++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +74 -0
index a434b665d913..5e4d323a790e 100644
@@ -3096,6 +3096,44 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	return 0;
 }
 
+/*
+ * GFX update_mqd: patch queue_size, ring base, priority and shadow/CSA in place
+ * and forward the write pointer, keeping the firmware-saved rptr.
+ */
+static int gfx_v12_0_gfx_mqd_update(struct amdgpu_device *adev, void *m,
+				    struct amdgpu_mqd_prop *prop,
+				    u64 user_wptr)
+{
+	struct v12_gfx_mqd *mqd = m;
+	uint32_t rb_bufsz, tmp;
+	bool priority = 0;
+
+	rb_bufsz = order_base_2(prop->queue_size / 4) - 1;
+	tmp = mqd->cp_gfx_hqd_cntl;
+	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BUFSZ, rb_bufsz);
+	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BLKSZ, rb_bufsz - 2);
+	mqd->cp_gfx_hqd_cntl = tmp;
+
+	mqd->cp_gfx_hqd_base = prop->hqd_base_gpu_addr >> 8;
+	mqd->cp_gfx_hqd_base_hi = upper_32_bits(prop->hqd_base_gpu_addr >> 8);
+
+	if (prop->hqd_queue_priority == AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM)
+		priority = 1;
+	tmp = regCP_GFX_HQD_QUEUE_PRIORITY_DEFAULT;
+	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_QUEUE_PRIORITY, PRIORITY_LEVEL, priority);
+	mqd->cp_gfx_hqd_queue_priority = tmp;
+
+	mqd->shadow_base_lo = lower_32_bits(prop->shadow_addr);
+	mqd->shadow_base_hi = upper_32_bits(prop->shadow_addr);
+	mqd->fw_work_area_base_lo = lower_32_bits(prop->csa_addr);
+	mqd->fw_work_area_base_hi = upper_32_bits(prop->csa_addr);
+
+	mqd->cp_gfx_hqd_wptr = lower_32_bits(user_wptr);
+	mqd->cp_gfx_hqd_wptr_hi = upper_32_bits(user_wptr);
+
+	return 0;
+}
+
 static int gfx_v12_0_kgq_init_queue(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -3334,6 +3372,38 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 	return 0;
 }
 
+/*
+ * Compute update_mqd: patch queue_size, ring/EOP base, CU mask and priority in
+ * place and forward the write pointer, keeping the firmware-saved rptr.
+ */
+static int gfx_v12_0_compute_mqd_update(struct amdgpu_device *adev, void *m,
+					struct amdgpu_mqd_prop *prop,
+					u64 user_wptr)
+{
+	struct v12_compute_mqd *mqd = m;
+
+	mqd->cp_hqd_pq_control &= ~CP_HQD_PQ_CONTROL__QUEUE_SIZE_MASK;
+	mqd->cp_hqd_pq_control |=
+		(order_base_2(prop->queue_size / 4) - 1)
+		<< CP_HQD_PQ_CONTROL__QUEUE_SIZE__SHIFT;
+
+	mqd->cp_hqd_pq_base_lo = prop->hqd_base_gpu_addr >> 8;
+	mqd->cp_hqd_pq_base_hi = upper_32_bits(prop->hqd_base_gpu_addr >> 8);
+
+	mqd->cp_hqd_eop_base_addr_lo = prop->eop_gpu_addr >> 8;
+	mqd->cp_hqd_eop_base_addr_hi = upper_32_bits(prop->eop_gpu_addr >> 8);
+
+	mqd->cp_hqd_pipe_priority = prop->hqd_pipe_priority;
+	mqd->cp_hqd_queue_priority = prop->hqd_queue_priority;
+
+	gfx_v12_0_compute_mqd_set_cu_mask(adev, mqd, prop);
+
+	mqd->cp_hqd_pq_wptr_lo = lower_32_bits(user_wptr);
+	mqd->cp_hqd_pq_wptr_hi = upper_32_bits(user_wptr);
+
+	return 0;
+}
+
 static int gfx_v12_0_kiq_init_register(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -5543,11 +5613,15 @@ static void gfx_v12_0_set_mqd_funcs(struct amdgpu_device *adev)
 		sizeof(struct v12_gfx_mqd);
 	adev->mqds[AMDGPU_HW_IP_GFX].init_mqd =
 		gfx_v12_0_gfx_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_GFX].update_mqd =
+		gfx_v12_0_gfx_mqd_update;
 	/* set compute eng mqd */
 	adev->mqds[AMDGPU_HW_IP_COMPUTE].mqd_size =
 		sizeof(struct v12_compute_mqd);
 	adev->mqds[AMDGPU_HW_IP_COMPUTE].init_mqd =
 		gfx_v12_0_compute_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_COMPUTE].update_mqd =
+		gfx_v12_0_compute_mqd_update;
 }
 
 static void gfx_v12_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
#4 lore raw

PATCH 5/10 drm/amdgpu/sdma6: implement update_mqd

In reply to Jesse Zhang

Implement the update_mqd callback for sdma_v6_0 user queues. SDMA init_mqd leaves the ring rptr/wptr untouched, so re-run it to rebuild the HQD, then restore the saved read pointer and forward the user write pointer.

init_mqd also seeds ib_cntl from the live IB_CNTL register, which reads back IB_ENABLE=0 on a stopped/unmapped queue. Left as-is, the re-mapped engine drains the ring (rptr advances) but never executes the indirect buffers, silently dropping the packet queued while disabled. Force IB_ENABLE on.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 29 ++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +29 -0
index 3fd3e530c76b..cc923f8531be 100644
@@ -884,10 +884,39 @@ static int sdma_v6_0_mqd_init(struct amdgpu_device *adev, void *mqd,
 	return 0;
 }
 
+/*
+ * SDMA update_mqd: init_mqd leaves the ring rptr/wptr alone, so re-run it to
+ * rebuild the HQD, then restore the saved rptr and forward the user wptr.
+ */
+static int sdma_v6_0_mqd_update(struct amdgpu_device *adev, void *mqd,
+				struct amdgpu_mqd_prop *prop, u64 user_wptr)
+{
+	struct v11_sdma_mqd *m = mqd;
+	u32 saved_rptr = m->sdmax_rlcx_rb_rptr;
+	u32 saved_rptr_hi = m->sdmax_rlcx_rb_rptr_hi;
+
+	sdma_v6_0_mqd_init(adev, mqd, prop);
+
+	m->sdmax_rlcx_rb_rptr = saved_rptr;
+	m->sdmax_rlcx_rb_rptr_hi = saved_rptr_hi;
+	m->sdmax_rlcx_rb_wptr = lower_32_bits(user_wptr);
+	m->sdmax_rlcx_rb_wptr_hi = upper_32_bits(user_wptr);
+
+	/*
+	 * init_mqd seeds ib_cntl from the live IB_CNTL register, which reads
+	 * back IB_ENABLE=0 on a stopped queue; the re-mapped engine would then
+	 * drain the ring without executing the IBs. Force IB_ENABLE on.
+	 */
+	m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
+
+	return 0;
+}
+
 static void sdma_v6_0_set_mqd_funcs(struct amdgpu_device *adev)
 {
 	adev->mqds[AMDGPU_HW_IP_DMA].mqd_size = sizeof(struct v11_sdma_mqd);
 	adev->mqds[AMDGPU_HW_IP_DMA].init_mqd = sdma_v6_0_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_DMA].update_mqd = sdma_v6_0_mqd_update;
 }
 
 /**
Signature · 1 line
2.49.0
#5 lore raw

PATCH 6/10 drm/amdgpu/sdma7: implement update_mqd

In reply to Jesse Zhang

Implement the update_mqd callback for sdma_v7_0 user queues. SDMA init_mqd leaves the ring rptr/wptr alone, so re-run it to rebuild the HQD, then restore the saved read pointer and forward the user write pointer. Force IB_ENABLE on, since init_mqd seeds ib_cntl from the live IB_CNTL register which reads back IB_ENABLE=0 on a stopped queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 29 ++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +29 -0
index 2068e2e6e3d6..2ab24d99c5ed 100644
@@ -905,10 +905,39 @@ static int sdma_v7_0_mqd_init(struct amdgpu_device *adev, void *mqd,
 	return 0;
 }
 
+/*
+ * SDMA update_mqd: init_mqd leaves the ring rptr/wptr alone, so re-run it to
+ * rebuild the HQD, then restore the saved rptr and forward the user wptr.
+ */
+static int sdma_v7_0_mqd_update(struct amdgpu_device *adev, void *mqd,
+				struct amdgpu_mqd_prop *prop, u64 user_wptr)
+{
+	struct v12_sdma_mqd *m = mqd;
+	u32 saved_rptr = m->sdmax_rlcx_rb_rptr;
+	u32 saved_rptr_hi = m->sdmax_rlcx_rb_rptr_hi;
+
+	sdma_v7_0_mqd_init(adev, mqd, prop);
+
+	m->sdmax_rlcx_rb_rptr = saved_rptr;
+	m->sdmax_rlcx_rb_rptr_hi = saved_rptr_hi;
+	m->sdmax_rlcx_rb_wptr = lower_32_bits(user_wptr);
+	m->sdmax_rlcx_rb_wptr_hi = upper_32_bits(user_wptr);
+
+	/*
+	 * init_mqd seeds ib_cntl from the live IB_CNTL register, which reads
+	 * back IB_ENABLE=0 on a stopped queue; the re-mapped engine would then
+	 * drain the ring without executing the IBs. Force IB_ENABLE on.
+	 */
+	m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
+
+	return 0;
+}
+
 static void sdma_v7_0_set_mqd_funcs(struct amdgpu_device *adev)
 {
 	adev->mqds[AMDGPU_HW_IP_DMA].mqd_size = sizeof(struct v12_sdma_mqd);
 	adev->mqds[AMDGPU_HW_IP_DMA].init_mqd = sdma_v7_0_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_DMA].update_mqd = sdma_v7_0_mqd_update;
 }
 
 /**
Signature · 1 line
2.49.0
#6 lore raw

PATCH 7/10 drm/amdgpu/sdma7_1: implement update_mqd

In reply to Jesse Zhang

Implement the update_mqd callback for sdma_v7_1 user queues. SDMA init_mqd leaves the ring rptr/wptr alone, so re-run it to rebuild the HQD, then restore the saved read pointer and forward the user write pointer. Force IB_ENABLE on, since init_mqd seeds ib_cntl from the live IB_CNTL register which reads back IB_ENABLE=0 on a stopped queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c | 29 ++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c +29 -0
index e9a3bcfd7775..e74ab8112d50 100644
@@ -889,10 +889,39 @@ static int sdma_v7_1_mqd_init(struct amdgpu_device *adev, void *mqd,
 	return 0;
 }
 
+/*
+ * SDMA update_mqd: init_mqd leaves the ring rptr/wptr alone, so re-run it to
+ * rebuild the HQD, then restore the saved rptr and forward the user wptr.
+ */
+static int sdma_v7_1_mqd_update(struct amdgpu_device *adev, void *mqd,
+				struct amdgpu_mqd_prop *prop, u64 user_wptr)
+{
+	struct v12_sdma_mqd *m = mqd;
+	u32 saved_rptr = m->sdmax_rlcx_rb_rptr;
+	u32 saved_rptr_hi = m->sdmax_rlcx_rb_rptr_hi;
+
+	sdma_v7_1_mqd_init(adev, mqd, prop);
+
+	m->sdmax_rlcx_rb_rptr = saved_rptr;
+	m->sdmax_rlcx_rb_rptr_hi = saved_rptr_hi;
+	m->sdmax_rlcx_rb_wptr = lower_32_bits(user_wptr);
+	m->sdmax_rlcx_rb_wptr_hi = upper_32_bits(user_wptr);
+
+	/*
+	 * init_mqd seeds ib_cntl from the live IB_CNTL register, which reads
+	 * back IB_ENABLE=0 on a stopped queue; the re-mapped engine would then
+	 * drain the ring without executing the IBs. Force IB_ENABLE on.
+	 */
+	m->sdmax_rlcx_ib_cntl |= SDMA0_SDMA_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
+
+	return 0;
+}
+
 static void sdma_v7_1_set_mqd_funcs(struct amdgpu_device *adev)
 {
 	adev->mqds[AMDGPU_HW_IP_DMA].mqd_size = sizeof(struct v12_sdma_mqd);
 	adev->mqds[AMDGPU_HW_IP_DMA].init_mqd = sdma_v7_1_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_DMA].update_mqd = sdma_v7_1_mqd_update;
 }
 
 /**
Signature · 1 line
2.49.0
#7 lore raw

PATCH 8/10 drm/amdgpu/mes_userqueue: route compute MODIFY through update_mqd

In reply to Jesse Zhang

Call the per-IP update_mqd callback instead of init_mqd for a compute MODIFY, so a queue re-enabled after a queue_percentage == 0 disable keeps its ring position instead of wedging into a GPU reset (see the update_mqd callback commit for why). Add mes_userq_read_user_wptr() to read the current user wptr and forward it to the callback.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 28 +++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +27 -1
index 82bb4369451e..f2742fa28dc6 100644
@@ -681,6 +681,25 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 	return r;
 }
 
+/*
+ * Read the queue's current user wptr from its wptr poll BO. Packets queued
+ * while the queue was disabled advanced this value but not the MQD; the per-IP
+ * update_mqd callback forwards it back into the MQD so a re-enabled queue picks
+ * the work up. Returns 0 if the BO is not mapped.
+ */
+static u64 mes_userq_read_user_wptr(struct amdgpu_usermode_queue *queue)
+{
+	u64 user_wptr = 0;
+	void *wc = NULL;
+
+	if (queue->wptr_obj.obj &&
+	    !amdgpu_bo_kmap(queue->wptr_obj.obj, &wc) && wc) {
+		user_wptr = *(volatile u64 *)wc;
+		amdgpu_bo_kunmap(queue->wptr_obj.obj);
+	}
+	return user_wptr;
+}
+
 static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
 					struct drm_amdgpu_userq_in *args_in)
 {
@@ -695,6 +714,11 @@ static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
 		return -EINVAL;
 	}
 
+	if (!mqd_hw_default->update_mqd) {
+		DRM_ERROR("Compute MQD update not supported on this IP\n");
+		return -EOPNOTSUPP;
+	}
+
 	compute_mqd_v11 = memdup_user(u64_to_user_ptr(args_in->mqd), args_in->mqd_size);
 	if (IS_ERR(compute_mqd_v11)) {
 		DRM_ERROR("Failed to read user MQD\n");
@@ -708,7 +732,9 @@ static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
 	userq_props->queue_size = args_in->queue_size;
 	userq_props->hqd_base_gpu_addr = args_in->queue_va;
 
-	retval = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
+	retval = mqd_hw_default->update_mqd(adev, (void *)queue->mqd.cpu_ptr,
+					    userq_props,
+					    mes_userq_read_user_wptr(queue));
 
 free:
 	kfree(compute_mqd_v11);
Signature · 1 line
2.49.0
#8 lore raw

PATCH 9/10 drm/amdgpu/mes_userqueue: add GFX MODIFY support

In reply to Jesse Zhang

Add the GFX case to the mqd_update dispatcher, routing it through the per-IP update_mqd callback like compute. Add a queue_percentage field to drm_amdgpu_userq_mqd_gfx11 and plumb it through create; 0 marks the queue inactive so it is not remapped, aligning KGD GFX user queues with KFD.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 55 ++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  6 +++
 2 files changed, 61 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +55 -0
index f2742fa28dc6..3059224dd9ad 100644
@@ -573,8 +573,16 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 			goto free_mqd;
 		}
 
+		if (mqd_gfx_v11->queue_percentage > AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {
+			DRM_ERROR("Queue percentage must be between 0 to AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE.\n");
+			r = -EINVAL;
+			kfree(mqd_gfx_v11);
+			goto free_mqd;
+		}
+
 		userq_props->shadow_addr = mqd_gfx_v11->shadow_va;
 		userq_props->csa_addr = mqd_gfx_v11->csa_va;
+		userq_props->queue_percentage = mqd_gfx_v11->queue_percentage;
 		userq_props->tmz_queue =
 			mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
 
@@ -700,6 +708,51 @@ static u64 mes_userq_read_user_wptr(struct amdgpu_usermode_queue *queue)
 	return user_wptr;
 }
 
+static int mes_userq_gfx_mqd_update(struct amdgpu_usermode_queue *queue,
+				    struct drm_amdgpu_userq_in *args_in)
+{
+	int retval = 0;
+	struct amdgpu_device *adev = queue->userq_mgr->adev;
+	struct amdgpu_mqd_prop *userq_props = queue->userq_prop;
+	struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue->queue_type];
+	struct drm_amdgpu_userq_mqd_gfx11 *gfx_mqd_v11;
+
+	if (args_in->mqd_size != sizeof(*gfx_mqd_v11)) {
+		DRM_ERROR("Invalid GFX IP MQD size\n");
+		return -EINVAL;
+	}
+
+	if (!mqd_hw_default->update_mqd) {
+		DRM_ERROR("GFX MQD update not supported on this IP\n");
+		return -EOPNOTSUPP;
+	}
+
+	gfx_mqd_v11 = memdup_user(u64_to_user_ptr(args_in->mqd), args_in->mqd_size);
+	if (IS_ERR(gfx_mqd_v11)) {
+		DRM_ERROR("Failed to read user MQD\n");
+		return -ENOMEM;
+	}
+
+	if (gfx_mqd_v11->queue_percentage > AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {
+		DRM_ERROR("Queue percentage must be between 0 to AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE.\n");
+		kfree(gfx_mqd_v11);
+		return -EINVAL;
+	}
+
+	userq_props->shadow_addr = gfx_mqd_v11->shadow_va;
+	userq_props->csa_addr = gfx_mqd_v11->csa_va;
+	userq_props->queue_size = args_in->queue_size;
+	userq_props->hqd_base_gpu_addr = args_in->queue_va;
+	userq_props->queue_percentage = gfx_mqd_v11->queue_percentage;
+
+	retval = mqd_hw_default->update_mqd(adev, (void *)queue->mqd.cpu_ptr,
+					    userq_props,
+					    mes_userq_read_user_wptr(queue));
+
+	kfree(gfx_mqd_v11);
+	return retval;
+}
+
 static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
 					struct drm_amdgpu_userq_in *args_in)
 {
@@ -749,6 +802,8 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_
 	switch (queue->queue_type) {
 	case AMDGPU_HW_IP_COMPUTE:
 		return mes_userq_compute_mqd_update(queue, args_in);
+	case AMDGPU_HW_IP_GFX:
+		return mes_userq_gfx_mqd_update(queue, args_in);
 	default:
 		return -EINVAL;
 	}
include/uapi/drm/amdgpu_drm.h +6 -0
index 2de47ff7c4d0..da2016f42a2e 100644
@@ -449,6 +449,12 @@ struct drm_amdgpu_userq_mqd_gfx11 {
 	 * Use AMDGPU_INFO_IOCTL to find the exact size of the object.
 	 */
 	__u64   csa_va;
+	/**
+	 * @queue_percentage: Queue resource allocation percentage (0-100)
+	 * Defines the percentage of GPU resources allocated to this queue.
+	 * A value of 0 marks the queue inactive and it will not be mapped.
+	 */
+	__u32   queue_percentage;
 };
 
 /* GFX V11 SDMA IP specific MQD parameters */
Signature · 1 line
2.49.0
#9 lore raw

PATCH 10/10 drm/amdgpu/mes_userqueue: add SDMA MODIFY support

In reply to Jesse Zhang

Add the SDMA case to the mqd_update dispatcher, routing it through the per-IP update_mqd callback like compute and GFX. Add a queue_percentage field to drm_amdgpu_userq_mqd_sdma_gfx11 and plumb it through create; 0 marks the queue inactive so it is not remapped, aligning KGD SDMA user queues with KFD (which controls activeness the same way via update_mqd_sdma).

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 54 ++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  6 +++
 2 files changed, 60 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +54 -0
index 3059224dd9ad..d9ddc0085d44 100644
@@ -626,6 +626,13 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 			goto free_mqd;
 		}
 
+		if (mqd_sdma_v11->queue_percentage > AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {
+			DRM_ERROR("Queue percentage must be between 0 to AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE.\n");
+			r = -EINVAL;
+			kfree(mqd_sdma_v11);
+			goto free_mqd;
+		}
+
 		r = amdgpu_bo_reserve(queue->vm->root.bo, false);
 		if (r) {
 			kfree(mqd_sdma_v11);
@@ -641,6 +648,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 		}
 
 		userq_props->csa_addr = mqd_sdma_v11->csa_va;
+		userq_props->queue_percentage = mqd_sdma_v11->queue_percentage;
 		kfree(mqd_sdma_v11);
 	}
 
@@ -708,6 +716,50 @@ static u64 mes_userq_read_user_wptr(struct amdgpu_usermode_queue *queue)
 	return user_wptr;
 }
 
+static int mes_userq_sdma_mqd_update(struct amdgpu_usermode_queue *queue,
+				     struct drm_amdgpu_userq_in *args_in)
+{
+	int retval = 0;
+	struct amdgpu_device *adev = queue->userq_mgr->adev;
+	struct amdgpu_mqd_prop *userq_props = queue->userq_prop;
+	struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue->queue_type];
+	struct drm_amdgpu_userq_mqd_sdma_gfx11 *sdma_mqd_v11;
+
+	if (args_in->mqd_size != sizeof(*sdma_mqd_v11)) {
+		DRM_ERROR("Invalid SDMA IP MQD size\n");
+		return -EINVAL;
+	}
+
+	if (!mqd_hw_default->update_mqd) {
+		DRM_ERROR("SDMA MQD update not supported on this IP\n");
+		return -EOPNOTSUPP;
+	}
+
+	sdma_mqd_v11 = memdup_user(u64_to_user_ptr(args_in->mqd), args_in->mqd_size);
+	if (IS_ERR(sdma_mqd_v11)) {
+		DRM_ERROR("Failed to read user MQD\n");
+		return -ENOMEM;
+	}
+
+	if (sdma_mqd_v11->queue_percentage > AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {
+		DRM_ERROR("Queue percentage must be between 0 to AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE.\n");
+		kfree(sdma_mqd_v11);
+		return -EINVAL;
+	}
+
+	userq_props->csa_addr = sdma_mqd_v11->csa_va;
+	userq_props->queue_size = args_in->queue_size;
+	userq_props->hqd_base_gpu_addr = args_in->queue_va;
+	userq_props->queue_percentage = sdma_mqd_v11->queue_percentage;
+
+	retval = mqd_hw_default->update_mqd(adev, (void *)queue->mqd.cpu_ptr,
+					    userq_props,
+					    mes_userq_read_user_wptr(queue));
+
+	kfree(sdma_mqd_v11);
+	return retval;
+}
+
 static int mes_userq_gfx_mqd_update(struct amdgpu_usermode_queue *queue,
 				    struct drm_amdgpu_userq_in *args_in)
 {
@@ -804,6 +856,8 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_
 		return mes_userq_compute_mqd_update(queue, args_in);
 	case AMDGPU_HW_IP_GFX:
 		return mes_userq_gfx_mqd_update(queue, args_in);
+	case AMDGPU_HW_IP_DMA:
+		return mes_userq_sdma_mqd_update(queue, args_in);
 	default:
 		return -EINVAL;
 	}
include/uapi/drm/amdgpu_drm.h +6 -0
index da2016f42a2e..94497d1217b8 100644
@@ -465,6 +465,12 @@ struct drm_amdgpu_userq_mqd_sdma_gfx11 {
 	 * to get the size.
 	 */
 	__u64   csa_va;
+	/**
+	 * @queue_percentage: Queue resource allocation percentage (0-100)
+	 * Defines the percentage of GPU resources allocated to this queue.
+	 * A value of 0 marks the queue inactive and it will not be mapped.
+	 */
+	__u32   queue_percentage;
 };
 
 /* GFX V11 Compute IP specific MQD parameters */
Signature · 1 line
2.49.0
#10 lore raw
In reply to Jesse Zhang

AMD General

Ping ...

Quoted 75 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, August 21, 2026 5:52 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH 01/10] drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers

Split the inlined compute path out of mes_userq_mqd_update() into mes_userq_compute_mqd_update() and turn the former into a dispatcher that switches on queue_type, giving other IPs an obvious place to hook in.

No functional change.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -1
index ad72ced472dd..82bb4369451e 100644
@@ -681,7 +681,8 @@ static int mes_userq_mqd_create(struct
 amdgpu_usermode_queue *queue,
      return r;
 }
 
-static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct
 drm_amdgpu_userq_in *args_in)
+static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue
 *queue,
+                                     struct drm_amdgpu_userq_in *args_in)
 {
      int retval = 0;
      struct amdgpu_device *adev = queue->userq_mgr->adev; @@ -689,12
+690,6 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue
*queue, struct drm_
      struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue-
Quoted 1 line

queue_type];

      struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd_v11;
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -6
-     if (!queue || !userq_props)
-             return -EINVAL;
-
-     if (queue->queue_type != AMDGPU_HW_IP_COMPUTE)
-             return -EINVAL;
-
      if (args_in->mqd_size != sizeof(*compute_mqd_v11)) {
              DRM_ERROR("Invalid compute IP MQD size\n");
              return -EINVAL;
@@ -720,6 +715,19 @@ static int mes_userq_mqd_update(struct

amdgpu_usermode_queue *queue, struct drm_

      return retval;

}

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +13 -1
+static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue,
+struct drm_amdgpu_userq_in *args_in) {
+     if (!queue || !queue->userq_prop)
+             return -EINVAL;
+
+     switch (queue->queue_type) {
+     case AMDGPU_HW_IP_COMPUTE:
+             return mes_userq_compute_mqd_update(queue, args_in);
+     default:
+             return -EINVAL;
+     }
+}
+
 static void mes_userq_mqd_destroy(struct amdgpu_usermode_queue *queue)  {
 
--

2.49.0