drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers
Subsystems (3)
PATCH v3 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
@@ -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
PATCH v3 2/10 drm/amdgpu: add mqd_prop modify flag for queue MODIFY
Add a modify flag and user_wptr to struct amdgpu_mqd_prop. When set, init_mqd patches the MQD in place: keep the context-saved rptr and use user_wptr as the wptr. KFD already patches the MQD in place for the same disable/re-enable sequence.
v3: use an mqd_prop modify flag consumed by init_mqd instead of a
separate per-IP update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
@@ -494,6 +494,9 @@ struct amdgpu_mqd_prop {uint64_t ctx_save_area_addr;uint32_t ctx_save_area_size;uint32_t ctl_stack_size; +/* queue MODIFY: keep the context-saved rptr, use user_wptr as the wptr */ +bool modify; +u64 user_wptr; };struct amdgpu_mqd {
Signature · 1 line
2.49.0
PATCH v3 3/10 drm/amdgpu/gfx11: honor mqd_prop modify flag in init_mqd
In reply to Jesse ZhangOn a queue MODIFY (prop->modify) the gfx11 GFX and compute init_mqd keep the context-saved rptr and use prop->user_wptr as the wptr, so a re-enabled queue resumes at the first un-consumed packet.
v2: rebuild the HQD via init_mqd and save/restore the rptr, matching the
SDMA update_mqd style, instead of patching individual MQD fields in place. Keeps all update_mqd callbacks consistent.
v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate gfx11 update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +23 -10
@@ -4167,9 +4167,14 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,uint32_t tmp;uint32_t rb_bufsz; -/* set up gfx hqd wptr */ - mqd->cp_gfx_hqd_wptr =0 ; - mqd->cp_gfx_hqd_wptr_hi =0 ; +/* set up gfx hqd wptr - on a MODIFY use the live user wptr */ +if (prop->modify) { + mqd->cp_gfx_hqd_wptr =lower_32_bits (prop->user_wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (prop->user_wptr); + }else { + mqd->cp_gfx_hqd_wptr =0 ; + mqd->cp_gfx_hqd_wptr_hi =0 ; + }/* set the pointer to the MQD */ mqd->cp_mqd_base_addr = prop->mqd_gpu_addr &0xfffffffc ;
@@ -4237,8 +4242,9 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m, DOORBELL_EN, 0); mqd->cp_rb_doorbell_control = tmp; -/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */ - mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT; +/* reset read pointer - on a MODIFY keep the context-saved rptr */ +if (!prop->modify) + mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT;/* active the queue */ mqd->cp_gfx_hqd_active =1 ;
@@ -4379,9 +4385,15 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,/* disable the queue if it's active */ mqd->cp_hqd_dequeue_request =0 ; - mqd->cp_hqd_pq_rptr =0 ; - mqd->cp_hqd_pq_wptr_lo =0 ; - mqd->cp_hqd_pq_wptr_hi =0 ; +/* on a MODIFY keep the context-saved rptr, use the live user wptr */ +if (prop->modify) { + mqd->cp_hqd_pq_wptr_lo =lower_32_bits (prop->user_wptr); + mqd->cp_hqd_pq_wptr_hi =upper_32_bits (prop->user_wptr); + }else { + mqd->cp_hqd_pq_rptr =0 ; + mqd->cp_hqd_pq_wptr_lo =0 ; + mqd->cp_hqd_pq_wptr_hi =0 ; + }/* set the pointer to the MQD */ mqd->cp_mqd_base_addr_lo = prop->mqd_gpu_addr &0xfffffffc ;
@@ -4442,8 +4454,9 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m, mqd->cp_hqd_pq_doorbell_control = tmp; -/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */ - mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT; +/* reset read pointer - but on a MODIFY keep the context-saved rptr */ +if (!prop->modify) + mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT;/* set the vmid for the queue */ mqd->cp_hqd_vmid =0 ;
Signature · 1 line
2.49.0
PATCH v3 4/10 drm/amdgpu/gfx12: honor mqd_prop modify flag in init_mqd
In reply to Jesse ZhangOn a queue MODIFY (prop->modify) the gfx12 GFX and compute init_mqd keep the context-saved rptr and use prop->user_wptr as the wptr, so a re-enabled queue resumes at the first un-consumed packet.
v2: rebuild the HQD via init_mqd and save/restore the rptr, matching the
SDMA update_mqd style, instead of patching individual MQD fields in place. Keeps all update_mqd callbacks consistent.
v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate gfx12 update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 29 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +20 -9
@@ -3006,9 +3006,14 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,uint32_t tmp;uint32_t rb_bufsz; -/* set up gfx hqd wptr */ - mqd->cp_gfx_hqd_wptr =0 ; - mqd->cp_gfx_hqd_wptr_hi =0 ; +/* set up gfx hqd wptr - on a MODIFY use the live user wptr */ +if (prop->modify) { + mqd->cp_gfx_hqd_wptr =lower_32_bits (prop->user_wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (prop->user_wptr); + }else { + mqd->cp_gfx_hqd_wptr =0 ; + mqd->cp_gfx_hqd_wptr_hi =0 ; + }/* set the pointer to the MQD */ mqd->cp_mqd_base_addr = prop->mqd_gpu_addr &0xfffffffc ;
@@ -3079,8 +3084,9 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m, DOORBELL_EN, 0); mqd->cp_rb_doorbell_control = tmp; -/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */ - mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT; +/* reset read pointer - but on a MODIFY keep the context-saved rptr */ +if (!prop->modify) + mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT;/* active the queue */ mqd->cp_gfx_hqd_active =1 ;
@@ -3212,10 +3218,15 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,/* disable the queue if it's active */ mqd->cp_hqd_dequeue_request =0 ; -/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */ - mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT; - mqd->cp_hqd_pq_wptr_lo =0 ; - mqd->cp_hqd_pq_wptr_hi =0 ; +/* reset read/write pointers - on a MODIFY keep rptr, use live user wptr */ +if (prop->modify) { + mqd->cp_hqd_pq_wptr_lo =lower_32_bits (prop->user_wptr); + mqd->cp_hqd_pq_wptr_hi =upper_32_bits (prop->user_wptr); + }else { + mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT; + mqd->cp_hqd_pq_wptr_lo =0 ; + mqd->cp_hqd_pq_wptr_hi =0 ; + }/* set the pointer to the MQD */ mqd->cp_mqd_base_addr_lo = prop->mqd_gpu_addr &0xfffffffc ;
Signature · 1 line
2.49.0
PATCH v3 5/10 drm/amdgpu/sdma6: honor mqd_prop modify flag in init_mqd
In reply to Jesse ZhangOn a queue MODIFY (prop->modify) sdma6 init_mqd keeps the context-saved rptr and uses prop->user_wptr as the wptr, so a re-enabled queue resumes at the first un-consumed packet. It also forces IB_ENABLE back on, since ib_cntl reads back IB_ENABLE=0 on a stopped queue.
v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate sdma6 update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +9 -0
@@ -881,6 +881,15 @@ static int sdma_v6_0_mqd_init(struct amdgpu_device *adev, void *mqd, m->sdmax_rlcx_f32_dbg0 =lower_32_bits (prop->fence_address); m->sdmax_rlcx_f32_dbg1 =upper_32_bits (prop->fence_address); +if (prop->modify) { +/* MODIFY: keep the context-saved rptr, use the live user wptr */ + m->sdmax_rlcx_rb_wptr =lower_32_bits (prop->user_wptr); + m->sdmax_rlcx_rb_wptr_hi =upper_32_bits (prop->user_wptr); + +/* ib_cntl read back IB_ENABLE=0 on the stopped queue; force it on */ + m->sdmax_rlcx_ib_cntl |=SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK ; + } +return 0 ; }
Signature · 1 line
2.49.0
PATCH v3 6/10 drm/amdgpu/sdma7: honor mqd_prop modify flag in init_mqd
In reply to Jesse ZhangOn a queue MODIFY (prop->modify) sdma7 init_mqd keeps the context-saved rptr and uses prop->user_wptr as the wptr, so a re-enabled queue resumes at the first un-consumed packet. It also forces IB_ENABLE back on, since ib_cntl reads back IB_ENABLE=0 on a stopped queue.
v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate sdma7 update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +9 -0
@@ -902,6 +902,15 @@ static int sdma_v7_0_mqd_init(struct amdgpu_device *adev, void *mqd, m->sdmax_rlcx_mcu_dbg0 =lower_32_bits (prop->fence_address); m->sdmax_rlcx_mcu_dbg1 =upper_32_bits (prop->fence_address); +if (prop->modify) { +/* MODIFY: keep the context-saved rptr, use the live user wptr */ + m->sdmax_rlcx_rb_wptr =lower_32_bits (prop->user_wptr); + m->sdmax_rlcx_rb_wptr_hi =upper_32_bits (prop->user_wptr); + +/* ib_cntl read back IB_ENABLE=0 on the stopped queue; force it on */ + m->sdmax_rlcx_ib_cntl |=SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK ; + } +return 0 ; }
Signature · 1 line
2.49.0
PATCH v3 7/10 drm/amdgpu/sdma7_1: honor mqd_prop modify flag in init_mqd
In reply to Jesse ZhangOn a queue MODIFY (prop->modify) sdma7_1 init_mqd keeps the context-saved rptr and uses prop->user_wptr as the wptr, so a re-enabled queue resumes at the first un-consumed packet. It also forces IB_ENABLE back on, since ib_cntl reads back IB_ENABLE=0 on a stopped queue.
v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate sdma7_1 update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c +9 -0
@@ -886,6 +886,15 @@ static int sdma_v7_1_mqd_init(struct amdgpu_device *adev, void *mqd, m->sdmax_rlcx_csa_addr_lo =lower_32_bits (prop->csa_addr); m->sdmax_rlcx_csa_addr_hi =upper_32_bits (prop->csa_addr); +if (prop->modify) { +/* MODIFY: keep the context-saved rptr, use the live user wptr */ + m->sdmax_rlcx_rb_wptr =lower_32_bits (prop->user_wptr); + m->sdmax_rlcx_rb_wptr_hi =upper_32_bits (prop->user_wptr); + +/* ib_cntl read back IB_ENABLE=0 on the stopped queue; force it on */ + m->sdmax_rlcx_ib_cntl |=SDMA0_SDMA_QUEUE0_IB_CNTL__IB_ENABLE_MASK ; + } +return 0 ; }
Signature · 1 line
2.49.0
PATCH v3 8/10 drm/amdgpu/mes_userqueue: route compute MODIFY through init_mqd
In reply to Jesse ZhangSet prop->modify and prop->user_wptr (read from the wptr poll BO) and call init_mqd, so a re-enabled compute queue keeps its context-saved rptr and resumes at the first un-consumed packet.
Also set modify=false on the create and kernel-ring (amdgpu_ring_to_mqd_prop) paths, so every init_mqd caller states its own value rather than relying on the zeroed prop.
v3: set the mqd_prop modify flag and call init_mqd instead of a separate
update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2 -0
@@ -840,6 +840,8 @@ static void amdgpu_ring_to_mqd_prop(struct amdgpu_ring *ring, prop->use_doorbell = ring->use_doorbell; prop->doorbell_index = ring->doorbell_index; prop->kernel_queue = true; +/* kernel rings always build the MQD from scratch, never a MODIFY */ + prop->modify = false;/* map_queues packet doesn't need activate the queue, * so only kiq need set this field.
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +19 -1
@@ -479,6 +479,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, userq_props->use_doorbell = true; userq_props->doorbell_index = queue->doorbell_index; userq_props->fence_address = queue->fence_drv->gpu_addr; + userq_props->modify = false;if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) {struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd;
@@ -681,6 +682,20 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,return r; } +/* Read the queue's live user wptr from its poll BO; 0 if 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) {
@@ -707,8 +722,11 @@ 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; + userq_props->modify = true; + userq_props->user_wptr =mes_userq_read_user_wptr (queue); - retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, userq_props); + retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, + userq_props); free:kfree (compute_mqd_v11);
Signature · 1 line
2.49.0
Re: [PATCH V3 08/10] drm/amdgpu/mes_userqueue: route compute MODIFY through init_mqd
Quoted 51 lines · Jesse Zhang
Set
prop->modifyandprop->user_wptr(read from the wptr poll BO) and callinit_mqd, so a re-enabled compute queue keeps its context-saved rptr and resumes at the first un-consumed packet.Also set modify=false on the create and kernel-ring (
amdgpu_ring_to_mqd_prop) paths, so everyinit_mqdcaller states its own value rather than relying on the zeroed prop.v3: set the
mqd_propmodify flag and callinit_mqdinstead of a separate
update_mqdcallback, per review.Signed-off-by Jesse Zhang <[email protected]>Suggested-by Alexander Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-0@@ -840,6 +840,8 @@ static void amdgpu_ring_to_mqd_prop(struct amdgpu_ring *ring, prop->use_doorbell = ring->use_doorbell; prop->doorbell_index = ring->doorbell_index; prop->kernel_queue = true; +/* kernel rings always build the MQD from scratch, never a MODIFY */ + prop->modify = false;/* map_queues packet doesn't need activate the queue, * so only kiq need set this field. drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +4
-0@@ -479,6 +479,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, userq_props->use_doorbell = true; userq_props->doorbell_index = queue->doorbell_index; userq_props->fence_address = queue->fence_drv->gpu_addr; + userq_props->modify = false;if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) {struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd;@@ -681,6 +682,20 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,return r; } +/* Read the queue's live user wptr from its poll BO; 0 if not mapped. */ +static u64 mes_userq_read_user_wptr (struct amdgpu_usermode_queue *queue) +{
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, · line 697
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +10
-0+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; +}
Can't we just skip this? The firmware should update the MQD and store the current rptr/wptr when we unmap it. So when we modify the queue, all we need to do is skip any changes to the rptr/wrptr when we modify the MQD. No need to save the wptr. Other than that, the patches look good to me.
Alex
Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +5
-2+static int mes_userq_compute_mqd_update (struct amdgpu_usermode_queue *queue,struct drm_amdgpu_userq_in *args_in) {@@ -707,8 +722,11 @@ 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; + userq_props->modify = true; + userq_props->user_wptr =mes_userq_read_user_wptr (queue); - retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, userq_props); + retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, + userq_props); free:kfree (compute_mqd_v11); --2.49.0
RE: [PATCH V3 08/10] drm/amdgpu/mes_userqueue: route compute MODIFY through init_mqd
AMD General
Quoted 73 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, September 4, 2026 2:01 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH V3 08/10] drm/amdgpu/mes_userqueue: route compute MODIFY throughinit_mqddrivers/gpu/drm/amd/amdgpu/amdgpu_ring.c static void amdgpu_ring_to_mqd_prop(struct
Quoted 25 lines · Jesse Zhang
Set
prop->modifyandprop->user_wptr(read from the wptr poll BO) and callinit_mqd, so a re-enabled compute queue keeps its context-saved rptr and resumes at the first un-consumed packet.Also set modify=false on the create and kernel-ring (
amdgpu_ring_to_mqd_prop) paths, so everyinit_mqdcaller states its own value rather than relying on the zeroed prop.v3: set the
mqd_propmodify flag and callinit_mqdinstead of a separate
update_mqdcallback, per review.Signed-off-by Jesse Zhang <[email protected]>Suggested-by Alexander Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -840,6 +840,8 @@ static void amdgpu_ring_to_mqd_prop(struct
amdgpu_ring*ring,drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-0prop->use_doorbell = ring->use_doorbell; prop->doorbell_index = ring->doorbell_index; prop->kernel_queue = true; +/* kernel rings always build the MQD from scratch, never a MODIFY */ + prop->modify = false;/* map_queues packet doesn't need activate the queue, * so only kiq need set this field. drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0
-0@@ -479,6 +479,7 @@ static int mes_userq_mqd_create(struct
amdgpu_usermode_queue*queue,Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-0userq_props->use_doorbell = true; userq_props->doorbell_index = queue->doorbell_index; userq_props->fence_address = queue->fence_drv->gpu_addr; + userq_props->modify = false;if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) {struct drm_amdgpu_userq_mqd_compute_gfx11
*compute_mqd; @@ -681,6 +682,20 @@ static intmes_userq_mqd_create(struct
amdgpu_usermode_queue*queue,Quoted 13 lines
return r;}
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +10
-0+/* Read the queue's live user wptr from its poll BO; 0 if 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);
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, · line 697
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3
-0+ } +return user_wptr; +}Can't we just skip this? The firmware should update the MQD and store the current rptr/wptr when we unmap it. So when we modify the queue, all we need to do is skip any changes to the rptr/wrptr when we modify the MQD. No need to save the wptr. Other than that, the patches look good to me.
Thanks Alex. You're right, will skip this in v4 - init_mqd just keeps the firmware context-saved rptr/wptr, dropping the read_user_wptr helper. Tested all pass.
Jesse
Quoted 25 lines
Alex
Quoted 2 lines
+
static int mes_userq_compute_mqd_update(structamdgpu_usermode_queue*queue,
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
Quoted 10 lines
struct
drm_amdgpu_userq_in*args_in) { @@ -707,8 +722,11 @@ static int mes_userq_compute_mqd_update(structamdgpu_usermode_queue*queue,userq_props->queue_size = args_in->queue_size; userq_props->hqd_base_gpu_addr = args_in->queue_va;drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2
-1+ userq_props->modify = true; + userq_props->user_wptr =mes_userq_read_user_wptr (queue); - retval = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr,
userq_props);Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2
-1+ retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, + userq_props); free:kfree (compute_mqd_v11); --2.49.0
PATCH v3 9/10 drm/amdgpu/mes_userqueue: add GFX MODIFY support
In reply to Jesse ZhangAdd mes_userq_gfx_mqd_update() to update a GFX queue's MQD from a drm_amdgpu_userq_mqd_gfx11 (shadow/csa address, queue size, ring base), re-init it in place via prop->modify + prop->user_wptr, and wire it into the queue_type dispatcher.
v3: re-init the MQD via the mqd_prop modify flag instead of a separate
update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 51 ++++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 6 +++ 2 files changed, 57 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +51 -0
@@ -574,8 +574,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 ;
@@ -696,6 +704,47 @@ 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 ; + } + + 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; + userq_props->modify = true; + userq_props->user_wptr =mes_userq_read_user_wptr (queue); + + retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, + userq_props); + +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) {
@@ -741,6 +790,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
@@ -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
PATCH v3 10/10 drm/amdgpu/mes_userqueue: add SDMA MODIFY support
In reply to Jesse ZhangAdd mes_userq_sdma_mqd_update() to update an SDMA queue's MQD from a drm_amdgpu_userq_mqd_sdma_gfx11 (csa address, queue size, ring base), re-init it in place via prop->modify + prop->user_wptr, and wire it into the queue_type dispatcher. This aligns KGD user queues with KFD's update_mqd_sdma.
v3: re-init the MQD via the mqd_prop modify flag instead of a separate
update_mqd callback, per review.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 50 ++++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 6 +++ 2 files changed, 56 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +50 -0
@@ -627,6 +627,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);
@@ -642,6 +649,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); }
@@ -704,6 +712,46 @@ 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 ; + } + + 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; + userq_props->modify = true; + userq_props->user_wptr =mes_userq_read_user_wptr (queue); + + retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, + userq_props); + +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) {
@@ -792,6 +840,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
@@ -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
AMD General
Ping ...
Quoted 75 lines
-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Monday, August 31, 2026 1:24 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH V3 01/10] drm/amdgpu/mes_userqueue: refactormqd_updateinto per-IP helpersSplit the inlined compute path out of
mes_userq_mqd_update()intomes_userq_compute_mqd_update()and turn the former into a dispatcher that switches onqueue_type, giving other IPs an obvious place to hook in.No functional change.
Signed-off-by Jesse Zhang <[email protected]>--- 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@@ -681,7 +681,8 @@ static int mes_userq_mqd_create(structamdgpu_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, structdrm_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