Skip to content

Commit 7283877

Browse files
ZhenGuo Yinalexdeucher
authored andcommitted
drm/amdkfd: Free gang_ctx_bo and wptr_bo in pqm_uninit
[Why] Memory leaks of gang_ctx_bo and wptr_bo. [How] Free gang_ctx_bo and wptr_bo in pqm_uninit. v2: add a common function pqm_clean_queue_resource to free queue's resources. v3: reset pdd->pqd.num_gws when destorying GWS queue. Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: ZhenGuo Yin <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent e040902 commit 7283877

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,43 @@ int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p)
169169
return 0;
170170
}
171171

172+
static void pqm_clean_queue_resource(struct process_queue_manager *pqm,
173+
struct process_queue_node *pqn)
174+
{
175+
struct kfd_node *dev;
176+
struct kfd_process_device *pdd;
177+
178+
dev = pqn->q->device;
179+
180+
pdd = kfd_get_process_device_data(dev, pqm->process);
181+
if (!pdd) {
182+
pr_err("Process device data doesn't exist\n");
183+
return;
184+
}
185+
186+
if (pqn->q->gws) {
187+
if (KFD_GC_VERSION(pqn->q->device) != IP_VERSION(9, 4, 3) &&
188+
!dev->kfd->shared_resources.enable_mes)
189+
amdgpu_amdkfd_remove_gws_from_process(
190+
pqm->process->kgd_process_info, pqn->q->gws);
191+
pdd->qpd.num_gws = 0;
192+
}
193+
194+
if (dev->kfd->shared_resources.enable_mes) {
195+
amdgpu_amdkfd_free_gtt_mem(dev->adev, pqn->q->gang_ctx_bo);
196+
if (pqn->q->wptr_bo)
197+
amdgpu_amdkfd_free_gtt_mem(dev->adev, pqn->q->wptr_bo);
198+
}
199+
}
200+
172201
void pqm_uninit(struct process_queue_manager *pqm)
173202
{
174203
struct process_queue_node *pqn, *next;
175204

176205
list_for_each_entry_safe(pqn, next, &pqm->queues, process_queue_list) {
177-
if (pqn->q && pqn->q->gws &&
178-
KFD_GC_VERSION(pqn->q->device) != IP_VERSION(9, 4, 3) &&
179-
!pqn->q->device->kfd->shared_resources.enable_mes)
180-
amdgpu_amdkfd_remove_gws_from_process(pqm->process->kgd_process_info,
181-
pqn->q->gws);
206+
if (pqn->q)
207+
pqm_clean_queue_resource(pqm, pqn);
208+
182209
kfd_procfs_del_queue(pqn->q);
183210
uninit_queue(pqn->q);
184211
list_del(&pqn->process_queue_list);
@@ -461,22 +488,7 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
461488
goto err_destroy_queue;
462489
}
463490

464-
if (pqn->q->gws) {
465-
if (KFD_GC_VERSION(pqn->q->device) != IP_VERSION(9, 4, 3) &&
466-
!dev->kfd->shared_resources.enable_mes)
467-
amdgpu_amdkfd_remove_gws_from_process(
468-
pqm->process->kgd_process_info,
469-
pqn->q->gws);
470-
pdd->qpd.num_gws = 0;
471-
}
472-
473-
if (dev->kfd->shared_resources.enable_mes) {
474-
amdgpu_amdkfd_free_gtt_mem(dev->adev,
475-
pqn->q->gang_ctx_bo);
476-
if (pqn->q->wptr_bo)
477-
amdgpu_amdkfd_free_gtt_mem(dev->adev, pqn->q->wptr_bo);
478-
479-
}
491+
pqm_clean_queue_resource(pqm, pqn);
480492
uninit_queue(pqn->q);
481493
}
482494

0 commit comments

Comments
 (0)