The gang context and the GART mapping of the write pointer are the parts of a queue that only exist for MES. They are freed in pqm_clean_queue_resource() together with the GWS bookkeeping.
Move them into kfd_queue_free_mes_resources() so that code outside the pqm can free them at the point where MES is known to have let go of the queue. No functional change. Signed-off-by: Armas Spann <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]> --- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + .../amd/amdkfd/kfd_process_queue_manager.c | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 3292e616d..0c276f7eb 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1387,6 +1387,7 @@ int kfd_criu_resume_queues(struct kfd_process *p); /* Queue Context Management */ int init_queue(struct queue **q, const struct queue_properties *properties); void uninit_queue(struct queue *q); +void kfd_queue_free_mes_resources(struct kfd_node *dev, struct queue *q); void print_queue_properties(struct queue_properties *q); void print_queue(struct queue *q); int kfd_queue_buffer_get(struct amdgpu_vm *vm, void __user *addr, struct amdgpu_bo **pbo, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c index b68e884b1..89e95b70e 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -186,6 +186,21 @@ int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p) return 0; } +/* + * Free the storage that only exists so MES can run the queue: the gang + * context and the GART mapping of the write pointer. MES addresses both + * directly, so the queue must be out of MES before this is called. + */ +void kfd_queue_free_mes_resources(struct kfd_node *dev, struct queue *q) +{ + if (!dev->kfd->shared_resources.enable_mes) + return; + + amdgpu_mes_free_gang_ctx_index(&dev->adev->mes, q->gang_ctx_array_index); + amdgpu_amdkfd_free_kernel_mem(dev->adev, &q->gang_ctx_bo); + amdgpu_amdkfd_free_kernel_mem(dev->adev, (void **)&q->wptr_bo_gart); +} + static void pqm_clean_queue_resource(struct process_queue_manager *pqm, struct process_queue_node *pqn) { @@ -210,11 +225,7 @@ static void pqm_clean_queue_resource(struct process_queue_manager *pqm, pdd->qpd.num_gws = 0; } - if (dev->kfd->shared_resources.enable_mes) { - amdgpu_mes_free_gang_ctx_index(&dev->adev->mes, pqn->q->gang_ctx_array_index); - amdgpu_amdkfd_free_kernel_mem(dev->adev, &pqn->q->gang_ctx_bo); - amdgpu_amdkfd_free_kernel_mem(dev->adev, (void **)&pqn->q->wptr_bo_gart); - } + kfd_queue_free_mes_resources(dev, pqn->q); } void pqm_uninit(struct process_queue_manager *pqm) -- 2.47.3
