drm/amdgpu,amdkfd: fix MES queue type handling
Subsystems (3)
cover drm/amdgpu,amdkfd: fix MES queue type handling
Hi,
This series fixes MES queue type handling for KFD queues.
MES ADD_QUEUE programs the firmware using the queue type supplied by the driver, but REMOVE_QUEUE was leaving queue_type zero-initialized. Since zero decodes as GFX in the REMOVE_QUEUE packet, a KFD compute queue could be removed as a GFX queue.
This was observed during a debug-trap suspend/remove sequence: the failing REMOVE_QUEUE packet used queue_type=GFX for doorbell 0x1002, while the matching ADD_QUEUE packet for that doorbell had used queue_type=COMPUTE. MES can then search in the wrong queue class and the REMOVE_QUEUE command may not complete.
The first patch sets queue_type for REMOVE_QUEUE using the same queue information as ADD_QUEUE.
The second patch fixes the type abstraction used by KFD. The MES input interface expects enum amdgpu_ring_type values; conversion to MES_QUEUE_TYPE is handled by the MES backend when building firmware packets. KFD now returns AMDGPU_RING_TYPE_* values from the helper, renames the helper to make that explicit, and uses it consistently for add, remove, and reset paths.
Geoffrey McRae (2):
drm/amdgpu,amdkfd: correct setting MES queue type drm/amdkfd: use amdgpu ring types for MES queue
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 1 + drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 1 + drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 3 +++ .../drm/amd/amdkfd/kfd_device_queue_manager.c | 19 +++++++++++-------- 6 files changed, 20 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 drm/amdgpu,amdkfd: correct setting MES queue type
MES ADD_QUEUE programs the firmware with the queue type from the driver input, but MES REMOVE_QUEUE leaves queue_type at the zero-initialized value. Zero decodes as GFX in the MES REMOVE_QUEUE packet.
That means removing a KFD compute queue can be submitted to MES as a GFX queue. In a debug-trap suspend/remove sequence this can leave MES looking for the doorbell in the wrong queue class and the REMOVE_QUEUE command may never complete. The observed failing packet removed doorbell 0x1002 with queue_type=GFX even though the corresponding ADD_QUEUE for the same doorbell was queue_type=COMPUTE.
Populate REMOVE_QUEUE.queue_type the same way ADD_QUEUE does.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 1 + drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 1 + drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 3 +++ drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 2 ++ 6 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
@@ -274,6 +274,7 @@ struct mes_remove_queue_input {uint32_t xcc_id;uint32_t doorbell_offset;uint64_t gang_context_addr; +uint32_t queue_type;bool remove_queue_after_reset; };
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
@@ -170,6 +170,7 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = queue->doorbell_index; queue_input.gang_context_addr = ctx->gpu_addr; + queue_input.queue_type = queue->queue_type;amdgpu_mes_lock (&adev->mes); r = adev->mes.funcs->remove_hw_queue (&adev->mes, &queue_input);
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 -0
@@ -383,6 +383,8 @@ static int mes_v11_0_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type);if (mes_rev >=0x60 ) mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +2 -0
@@ -371,6 +371,8 @@ static int mes_v12_0_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type);if (mes_rev >=0x5a ) mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +3 -0
@@ -362,6 +362,8 @@ static int mes_v12_1_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type); return mes_v12_1_submit_pkt_and_poll_completion(mes, xcc_id, AMDGPU_MES_SCHED_PIPE,
@@ -2270,6 +2272,7 @@ static int mes_v12_1_test_queue(struct amdgpu_device *adev, int xcc_id, remove_queue.xcc_id = xcc_id; remove_queue.doorbell_offset = doorbell_idx; remove_queue.gang_context_addr = add_queue.gang_context_addr; + remove_queue.queue_type = queue_type; r =mes_v12_1_remove_hw_queue (&adev->mes, &remove_queue); error:
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2 -0
@@ -299,6 +299,7 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, stmemset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); queue_input.remove_queue_after_reset = flush_mes_queue; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;
@@ -467,6 +468,7 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); queue_input.remove_queue_after_reset = false; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;/* pass the known bad queue info to the reset function */
Signature · 1 line
2.43.0
Christian König
maintainerRe: [PATCH 1/2] drm/amdgpu,amdkfd: correct setting MES queue type
Quoted 11 lines · Geoffrey McRae
MES
ADD_QUEUEprograms the firmware with the queue type from the driver input, but MESREMOVE_QUEUEleavesqueue_typeat the zero-initialized value. Zero decodes as GFX in the MESREMOVE_QUEUEpacket.That means removing a KFD compute queue can be submitted to MES as a GFX queue. In a debug-trap suspend/remove sequence this can leave MES looking for the doorbell in the wrong queue class and the
REMOVE_QUEUEcommand may never complete. The observed failing packet removed doorbell0x1002with queue_type=GFX even though the correspondingADD_QUEUEfor the same doorbell was queue_type=COMPUTE.
Quoted 5 lines
Populate REMOVE_QUEUE.queue_type the same way
ADD_QUEUEdoes.Signed-off-by Geoffrey McRae <[email protected]>Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>
Of hand looks correct to me, but Sunil can you take a look as well.
Thanks,
Christian.
Quoted 100 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 1 + drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 1 + drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 3 +++ drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 2 ++ 6 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1
-0@@ -274,6 +274,7 @@ struct mes_remove_queue_input {uint32_t xcc_id;uint32_t doorbell_offset;uint64_t gang_context_addr; +uint32_t queue_type;bool remove_queue_after_reset; };drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-0@@ -170,6 +170,7 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = queue->doorbell_index; queue_input.gang_context_addr = ctx->gpu_addr; + queue_input.queue_type = queue->queue_type;amdgpu_mes_lock (&adev->mes); r = adev->mes.funcs->remove_hw_queue (&adev->mes, &queue_input);drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2
-0@@ -383,6 +383,8 @@ static int mes_v11_0_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type);if (mes_rev >=0x60 ) mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +2
-0@@ -371,6 +371,8 @@ static int mes_v12_0_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type);if (mes_rev >=0x5a ) mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +3
-0@@ -362,6 +362,8 @@ static int mes_v12_1_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type); return mes_v12_1_submit_pkt_and_poll_completion(mes, xcc_id, AMDGPU_MES_SCHED_PIPE,@@ -2270,6 +2272,7 @@ static int mes_v12_1_test_queue(struct amdgpu_device *adev, int xcc_id, remove_queue.xcc_id = xcc_id; remove_queue.doorbell_offset = doorbell_idx; remove_queue.gang_context_addr = add_queue.gang_context_addr; + remove_queue.queue_type = queue_type; r =mes_v12_1_remove_hw_queue (&adev->mes, &remove_queue); error:drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2
-0@@ -299,6 +299,7 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, stmemset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); queue_input.remove_queue_after_reset = flush_mes_queue; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;@@ -467,6 +468,7 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); queue_input.remove_queue_after_reset = false; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;/* pass the known bad queue info to the reset function */
Re: [PATCH 1/2] drm/amdgpu,amdkfd: correct setting MES queue type
Quoted 12 lines · Christian König
Quoted 11 lines · Geoffrey McRae
MES
ADD_QUEUEprograms the firmware with the queue type from the driver input, but MESREMOVE_QUEUEleavesqueue_typeat the zero-initialized value. Zero decodes as GFX in the MESREMOVE_QUEUEpacket.That means removing a KFD compute queue can be submitted to MES as a GFX queue. In a debug-trap suspend/remove sequence this can leave MES looking for the doorbell in the wrong queue class and the
REMOVE_QUEUEcommand may never complete. The observed failing packet removed doorbell0x1002with queue_type=GFX even though the correspondingADD_QUEUEfor the same doorbell was queue_type=COMPUTE.
Quoted 6 lines
Quoted 5 lines
Populate REMOVE_QUEUE.queue_type the same way
ADD_QUEUEdoes.Signed-off-by Geoffrey McRae <[email protected]>Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>Of hand looks correct to me, but Sunil can you take a look as well.
To me it looks that MES firmware does not care during an remove queue pkt to have queue type as it seems to be doing it based on doorbell_offset. But the original MESAPI__REMOVE_QUEUE does have a field and
of queue type which is used for legacy queues but not for userqueues. I think even if it does not use the queue type to remove queue there is nothing wrong in setting up the queue type.
Looks good to me. Just validate well that MES handles this gracefully and there are no surprises from the FW.
Series Reviewed-by: Sunil Khatri <[email protected]>
Regards
Sunil Khatri
Quoted 104 lines
Thanks,
Christian.Quoted 100 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 1 + drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 1 + drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 3 +++ drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 2 ++ 6 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1
-0@@ -274,6 +274,7 @@ struct mes_remove_queue_input {uint32_t xcc_id;uint32_t doorbell_offset;uint64_t gang_context_addr; +uint32_t queue_type;bool remove_queue_after_reset; };drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-0@@ -170,6 +170,7 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = queue->doorbell_index; queue_input.gang_context_addr = ctx->gpu_addr; + queue_input.queue_type = queue->queue_type;amdgpu_mes_lock (&adev->mes); r = adev->mes.funcs->remove_hw_queue (&adev->mes, &queue_input);drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2
-0@@ -383,6 +383,8 @@ static int mes_v11_0_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type);if (mes_rev >=0x60 ) mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +2
-0@@ -371,6 +371,8 @@ static int mes_v12_0_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type);if (mes_rev >=0x5a ) mes_remove_queue_pkt.remove_queue_after_reset = input->remove_queue_after_reset;drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +3
-0@@ -362,6 +362,8 @@ static int mes_v12_1_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type); return mes_v12_1_submit_pkt_and_poll_completion(mes, xcc_id, AMDGPU_MES_SCHED_PIPE,@@ -2270,6 +2272,7 @@ static int mes_v12_1_test_queue(struct amdgpu_device *adev, int xcc_id, remove_queue.xcc_id = xcc_id; remove_queue.doorbell_offset = doorbell_idx; remove_queue.gang_context_addr = add_queue.gang_context_addr; + remove_queue.queue_type = queue_type; r =mes_v12_1_remove_hw_queue (&adev->mes, &remove_queue); error:drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2
-0@@ -299,6 +299,7 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, stmemset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); queue_input.remove_queue_after_reset = flush_mes_queue; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;@@ -467,6 +468,7 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); queue_input.remove_queue_after_reset = false; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;/* pass the known bad queue info to the reset function */
PATCH 2/2 drm/amdkfd: use amdgpu ring types for MES queue
In reply to Geoffrey McRaeThe MES interface takes queue types as enum amdgpu_ring_type values. The MES backend is responsible for converting those values to firmware-facing MES_QUEUE_TYPE values when building MES packets.
The KFD queue manager was converting KFD queue types directly to MES_QUEUE_TYPE values before filling the MES input structures. That is the wrong abstraction level for the generic MES interface.
Change the KFD helper to return AMDGPU_RING_TYPE_* values and rename it to make the expected type explicit. Use the helper for the add, remove, and reset MES paths.
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +11 -10
@@ -37,7 +37,8 @@#include "amdgpu_amdkfd.h" #include "amdgpu_reset.h" #include "amdgpu_sdma.h" -#include "mes_v11_api_def.h" +#include "amdgpu_ring.h" +#include "amdgpu_mes.h" #include "kfd_debug.h" /* Size of the per-pipe EOP queue */
@@ -183,24 +184,24 @@ static void kfd_hws_hang(struct device_queue_manager *dqm)amdgpu_amdkfd_gpu_reset (dqm->dev->adev); } -static int convert_to_mes_queue_type (int queue_type) +static int convert_to_amdgpu_ring_type (int queue_type) { -int mes_queue_type; +int amdgpu_ring_type;switch (queue_type) {case KFD_QUEUE_TYPE_COMPUTE : - mes_queue_type =MES_QUEUE_TYPE_COMPUTE ; + amdgpu_ring_type =AMDGPU_RING_TYPE_COMPUTE ;break ;case KFD_QUEUE_TYPE_SDMA : - mes_queue_type =MES_QUEUE_TYPE_SDMA ; + amdgpu_ring_type =AMDGPU_RING_TYPE_SDMA ;break ;default :WARN (1 ,"Invalid queue type %d" , queue_type); - mes_queue_type = -EINVAL ; + amdgpu_ring_type = -EINVAL ;break ; } -return mes_queue_type; +return amdgpu_ring_type; } static int add_queue_mes(struct device_queue_manager *dqm, struct queue *q,
@@ -250,7 +251,7 @@ static int add_queue_mes(struct device_queue_manager *dqm, struct queue *q, (qpd->pqm->process->debug_trap_enabled ||kfd_dbg_has_ttmps_always_setup (q->device)); - queue_type =convert_to_mes_queue_type (q->properties.type); + queue_type =convert_to_amdgpu_ring_type (q->properties.type);if (queue_type <0 ) {dev_err (adev->dev,"Queue type not supported with MES, queue:%d\n" , q->properties.type);
@@ -299,7 +300,7 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, stmemset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; - queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); + queue_input.queue_type =convert_to_amdgpu_ring_type (q->properties.type); queue_input.remove_queue_after_reset = flush_mes_queue; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;
@@ -468,7 +469,7 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); queue_input.doorbell_offset = q->properties.doorbell_off; queue_input.gang_context_addr = q->gang_ctx_gpu_addr; - queue_input.queue_type =convert_to_mes_queue_type (q->properties.type); + queue_input.queue_type =convert_to_amdgpu_ring_type (q->properties.type); queue_input.remove_queue_after_reset = false; queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;/* pass the known bad queue info to the reset function */
Signature · 1 line
2.43.0